Tuesday, July 26, 2011

Writing the Congressman

I got a little fired up about the debt ceiling nonsense, and decided to e-mail my Congressman, Mike Rogers. I always feel so empowered after writing a politician - which is ridiculous, because it has never made a difference.

Hello Congressman!

I'm writing today to complain about your part in the House majority's role in taking the United States to the brink of default. I cannot take your "Cut, Cap, and Balance" bill seriously. It is exactly in times of economic recession that we need the federal government to run a deficit - lowering taxes, bolstering the social safety net, and absorbing the lost revenue from a diminished tax base. Our short term debt increase is a result of the economic downturn and stimulus spending; it is not a result of "out of control" spending. Our long term debt mostly results from the projected increase in medicare spending. I know you understand this, so I find your press announcements disingenuous.

The debt ceiling should be raised as a matter of course, and not used as a gun to the nation's head to push through the minority agenda. Please do your part to ease the debt-ceiling grid lock. It would be great while your at it if you could help restore funding to the FAA, and contribute to the plans to save the postal service from bankruptcy.

Thanks for your service.

Cheers,
Reuben Pasquini

Sunday, July 24, 2011

Giving GWT a try

When I decided to implement a webapp browser for littleware's node database I began a debate with myself whether to implement the project in javascript or to give GWT a try. I have a little experience with javascript - I've enjoyed working with YUI on several projects, but javascript really sucks - no strict type checking, no module system, weirdo prototype object system ...

On the other hand - I feel like if I'm going to build a browser-based application, then I should develop with web technologies - javascript, HTML, CSS, ... It's great that GWT let's me develop in java, but it's a weird technology - not javascript, not really java - it's its own thing, but GWT is open source, has a community, is used and sponsored by Google (this blogger editor uses GWT), so might as well give it a try.

Anyway, I downloaded GWT and Eclipse, and was quickly running the demo application that the GWT Eclipse plugin creates in a new project. The demo is great for demonstrating GWT's remote service infrastructure and asyncrhonous support, but the simple UI assembly does not take advantage of GWT's new declarative UIBinder infrastructure. I want to use that UIBinder mojo, so I decided a good first task would be to refactor the demo to use UIBinder. I had a few false starts and a few different parts, but one part of the code replaces this html segment:


...
    <table align="center">
      <tr>
        <td colspan="2" style="font-weight:bold;">Please enter your name:</td>        
      </tr>
      <tr>
        <td id="nameFieldContainer"></td>
        <td id="sendButtonContainer"></td>
      </tr>
      <tr>
        <td colspan="2" style="color:red;" id="errorLabelContainer"></td>
      </tr>
    </table>
    ...
, and this java code:
	public void onModuleLoad() {
		final Button sendButton = new Button("Send");
		final TextBox nameField = new TextBox();
		nameField.setText("GWT User");
		final Label errorLabel = new Label();

		// We can add style names to widgets
		sendButton.addStyleName("sendButton");

		// Add the nameField and sendButton to the RootPanel
		// Use RootPanel.get() to get the entire body element
		RootPanel.get("nameFieldContainer").add(nameField);
		RootPanel.get("sendButtonContainer").add(sendButton);
		RootPanel.get("errorLabelContainer").add(errorLabel);
                ...
         }
with this UIBinder XML:
...
	<g:HTMLPanel>
		
    <table align="center">
      <tr>
        <td colspan="2" style="font-weight:bold;">Please enter your name:</td>        
      </tr>
      <tr>
        <td> <g:TextBox ui:field="nameField" /></td>
        <td> <g:Button ui:field="sendButton" /></td>
      </tr>
      <tr>
        <td colspan="2" style="color:red;"> <g:Label ui:field="errorLabel" /></td>
      </tr>
    </table>
		
	</g:HTMLPanel>
   ...
that pairs with this code:
public class DemoPanelView extends Composite {
	private static DemoPanelViewUiBinder uiBinder = GWT
			.create(DemoPanelViewUiBinder.class);

	interface DemoPanelViewUiBinder extends UiBinder<Widget, DemoPanelView> {
	}

	@UiField
	public Label errorLabel;
	@UiField
	public Button sendButton;	
	@UiField
	public TextBox  nameField;
...
Anyway I'm having fun with GWT, so I'll try to implement the database browser in GWT until I run into something that stops me ...

Sunday, July 03, 2011

Powershell Tabexpansion

There must be a better way to do this, but one of the funny things I do is setup variables in Powershell for paths that I frequently navigate to. So my profile.ps1 file has lines like this:
$GLOBAL:g1 = "C:\whatever\some\path"
$GLOBAL:l1 = "C:\whatever\some\other\path"
, and I issue a lot of commands like cd $g1
ls $l1
cp $l1/bla $g1
... that kind of thing.

One thing that drives me crazy is that I often want to do something with a sub-directory or file under a path referenced by one of my jump variables, but Powershell tabexpansion won't expand the variable for me ... until now! I finally decided to look into how to customize Powershell's tab expansion, and sure enough there's a TabExpansion function that I can override. This bLog post has the details.
Anyway, I defined my own TabExpansion function in profile.ps1 with a patch that just adds one line to the default function. The default has this regex-switch case that expands variable names:

            foreach ($_v in Get-ChildItem ($_varName + '*') | sort Name)
            { 
                $_nameFound = $_v.name
                $(if ($_nameFound.IndexOfAny($_varsRequiringQuotes) -eq -1) {'{0}{1}{2}'}
                else {'{0}{{{1}{2}}}'}) -f $_prefix, $_provider, $_nameFound
            }
, and my patch just adds a line to the end of the loop that also returns the value of the expanded variable:
            foreach ($_v in Get-ChildItem ($_varName + '*') | sort Name)
            { 
                $_nameFound = $_v.name
                $(if ($_nameFound.IndexOfAny($_varsRequiringQuotes) -eq -1) {'{0}{1}{2}'}
                else {'{0}{{{1}{2}}}'}) -f $_prefix, $_provider, $_nameFound
                $_v.value
            }
Now when I enter 'ls $g', then for each tab Powershell scrolls through a series of possible expansions: $g1, value of $g1, $gr, value of $gr, then back to $g1. If I want to list some sub-directory of $g1, then when the value of $g1 shows up, I just enter a '/' and start tabbing again to find the sub-directory. Hopefully that makes sense. Let me know if there's a better approach!