Thursday, April 16, 2009

GIT Rebase

I've recently become a die-hard git convert. I used to use subversion but branches in subversion and always having to be connected gave way to an interest in git. Branches in git are ridiculously easy and I like the fact that I don't have to be connected to save changes. Then I started using git and discovered rebase.

My typical workflow is to work and commit locally and then push up my changes when I have major chunks of work done. I also like to try and keep groups of commits small and related.

Typically though I'll do lots of commits and rebase lets me group related commits. You typically don't want to do rewrite the history (what rebase lets you do) to commits you've already pushed to the server but if you are the only one working on it or are sure it won't screw anyone up, you can --force a push to get your newly rewritten history up.

Now, how do I use it? If I have local changes I'm not ready to commit yet, I first use the 'git stash' command. This creates a temporary branch and stores your changes there. You could create another branch if you want and then switch back to rewrite history, but I find the stash command handy.

Now we do the rebase, in this example, we'll go back 5 commits. 'git rebase --interactive HEAD~5' Of course change 5 to whatever number you want to go back. (A quick git log should give you a good idea of how far to go back.)

From here, you'll get a list of commits, each with the work 'pick', the commit's short sha and the commit message. What I primarily use is pick and squash. Just move the line you want to merge into something else under the commit you want to merge into. Change pick to squash. Now save.

It will then open up your editor and ask you for a new commit message. It will show you both and let you change it. Saving this will rewrite your history. Now you can push up your newly rewritten history. Now to get back the changes you stashed away, simply type: 'git stash apply'

Git is really fast at what it does, even when pushing changes to the server. The only time I've noticed it taking a while was transferring an entire bare repository over a slow ssh connection. (Not really gits fault) Once I get very comfortable with it, I'll create a workflow chart that documents how I use it in hopes that it helps others.

Sunday, March 22, 2009

Bias in the media

It really bothers me to see blatant bias and ignorance in the news. I just read this short article from reuters:

OAKLAND, California (Reuters) - An Oakland, California man killed three police officers and wounded two others on Saturday in two separate shootings that began with a traffic stop and ended with a gun battle, police said.

Lovelle Mixon, 26, was pulled over during a traffic stop in the early afternoon. Mixon, who was wanted for violating parole on a charge of assault with a deadly weapon, opened fire on two officers, one of whom later died, and fled.

Officers found the suspect later that afternoon in an apartment.

When a Special Weapons and Tactics team forced their way in, he opened fire with an assault rifle, hitting three officers, including two who died from the wounds, according to a statement by police in the San Francisco Bay area city.

Mixon was killed in the gun fight, and the officer wounded in the traffic stop is in critical condition.

(Reporting by Peter Henderson, Editing by Sandra Maler)

Ok, now some may read this and think the best thing to do would be more gun control. While it's not stated, there are many phrases that clue you into this. "Gun battle," "opened fire," "assault with a deadly weapon," "assault rifle." Now if after reading this you think there should be tighter gun laws, let's think again.

First the criminal was "violating parole on charges of assault with a deadly weapon." I don't care what state you are from, it's illegal for him to posses a gun. He shot at two police officers, do you still think at this point he cares about breaking yet another law? Do you really think he got his gun legally?

But let's not forget that he opened fire with a rifle at the Special Weapons and Tactics team. I abhor the term assault rifle because really, if you are shooting at someone, any rifle is an assault rifle. The assault weapons ban was based on meaningless components and really seemed to focus on appearance rather than some sort of increased capacity for violence. And while we're on the subject of words and phrases, let's also look at "assault with a deadly weapon." Ummm... aren't all weapons deadly? I mean I think that's part of the definition of weapon. But it sounds so much more horrific than just assault with a weapon.

So how are more gun laws going to affect people like this man from getting guns? There not, just look at prohibition and the war on drugs. People still get drugs despite them being completely illegal. If something has value to someone, they will find a way to get it. In the case of guns, I really think the best defense is to arm as many "good guys" as possible. Then maybe the bad guys will think twice before using a gun for evil.

Thursday, February 05, 2009

Current economic situation

Things have been busy for me lately which is why there has been an absence of posts. I just want to talk for a minute about our current economic situation. There's a lot of talk about why we are in the mess we are in and what to do about it. Being the geeky type, I like to try and use the scientific method to solve problems rather than just go for a feel good measure. So first we must form a question.

I feel the question should be twofold, first what got us into this mess in the first place because as we all know, "those who cannot remember the past, are condemned to repeat it." Plus if we know what causes the problem, we should be able to prevent it from happening again right?

The second question I'm sure you are thinking is how should we fix it? I feel that is too vague, fix what? Let's first define the problem and then we can try to figure out how to fix it.

The way I see the current problem is that unemployment it up, value of the dollar is down and people aren't spending as much money as they used to giving us a low Gross Domestic Product (GDP). So what caused this?

It's hard to say exactly what caused this as there are a lot of variables to consider but I think there are a few things that stand out. Unemployment is tricky so we'll come back to it after we consider the second point, the value of the dollar.

This is an easy one, why is the value of the dollar so low? Because the government keeps printing money. What you say, the government can't just create money out of thin air? Sure they can, what they do is they set a target interest rate. To make the market converge to this rate, the Federal Reserve buys and sells Treasury Securities. By buying up Treasury Bills, the Federal Reserve puts money back into the system, where does Uncle Sam get the money to buy these? They have 2 options, first Tax us to take it from us, not a very popular option because people can only be taxed so far before they've had enough. Secondly, they can just print money on their printing presses. (Both methods are of course illegal for us to do)

Since we are off the Gold standard, the value of the dollar is based on whatever the markets say it is. If there is a surplus of dollars, the value of them goes down. When we were on the gold standard, it basically meant that the US had gold in it's vaults to back up the money it was printing. (The printed money was basically an IOU for gold or silver because let's face it... it's a lot easier to carry around paper than gold)

Ok, so now the dollar doesn't buy you as much as it used to but unless you are in the government, your salary probably hasn't gone up. So what does that cause you to do? We aren't the Federal Reserve so we can't print money, we aren't the IRS so we can't steal it, that means we have to either find a higher paying job or cut back your spending. By not spending as much the GDP goes down.

Also by not spending as much, businesses do not make as much money because people aren't spending as much. Some businesses do better than others but ultimately as people buy less, business can't afford as many employees and have to lay people off. This makes the unemployment rate increase.

Now the above are the first two steps of the Scientific method, state the question and then doing some background research to find a way to create a hypothesis. If anyone got this far, do you think that the hypothesis they would come up with would be print more money by lowering interest rates or taxing the people? Some people feel (because the media and the Government told them so) that the reason for this mess is because of deregulation. So they call for more regulation, more government spending, a newer new deal of sorts. Some felt the new deal was a great success, others (myself included), felt that all the new deal did was prolong the depression and that it was WWII that created the jobs to get us out of the depression. Who should you trust? No one, do some research for yourself. Just remember, some of the legacy programs from the new deal are FDIC, FHA, TVA, Social Security (nothing but a Ponzi scheme), SEC and Fannie Mae.

And for those of you who say this was unexpected, no one could have predicted what happened... take a look at the Austrian School of Economics. Specifically, take a look at one Congressman who has it right. In fact to make it easy for you, one blogger made a nice collection of his works available for you: If you want more info on this, visit

And it doesn't matter if you are a republican or a democrat or an independent, this is an issue that affects us all. In fact I seem to remember Obama, McCain and Bush all saying the same things about the banking and auto bailouts that most Americans were against. If you disagree with me then fine, everyone is entitled to an opinion, just don't say no one told you.

Friday, August 01, 2008

iPhone ringtones

Have a cool audio file you want to use as a ringtone on your new iPhone but can't figure out how to get it to work? Don't want to spend $0.99 on a ringtone from apple for a song you already have and want to use your fair use rights? You can do it, I can help.

Ok, as I say to my daughter, the easy way or the hard way? I'll start with the hard way first so you have a basic understanding or don't have garage band... if you do and are impatient, just skip ahead.

First you need an audio clip. Anything will do, we will be converting it to AAC format so if you have one of those, great. (not sure about the copy protected ones though... you have to be able to edit the file) If you do have an AAC file, cut it to 30 seconds or less and you can ignore this next bit.

Of you don't have an AAC file, you'll need to make one. Open your favorite audio editor, I've been using Audacity because it's free but you can use pretty much any audio editor, we don't need any fancy features so I'm sure you can find a free one on just about any platform that will do.

Now, load up your file and find the 30 second (or less) sound clip that you want to use. Got it? Ok, save those 30 seconds as either an AAC format or, if like me your editor doesn't support that, choose an uncompressed audio format. Then to convert to AAC format, load the uncompressed audio file into iTunes and right click and select convert to AAC. If you don't see this option, you probably changed it in your Preferences section of iTunes under Advanced->importing and then change the "Import Using" option to AAC. Now you'll need to right click and choose show in finder to find the aac file and copy it somewhere temporary. (I use the desktop) Now delete the new files it created from iTunes. (but not from the desktop)

Ok, now you have an AAC file on your desktop and not in iTunes. Rename the file from YourFilename.m4a to YourFilename.m4r. Load this file into iTunes and it should go into your ringtone list. Sync your phone and you should now have your custom ringtone on your iPhone.

Have GarageBand? Ok, this is really easy. Choose the loop button next to the FFW button on the main controls. Now, you should notice a small section appear below the timeline, use your mouse to select the 30 second clip you want, then choose Share->Send Ringtone to iTunes. Sync phone.

Apple could have made this a lot easier, especially for users that don't have garageband. I mean, why not just let us use mp3s as ringtones? This is one area where I think apple really dropped the ball. Fortunately I have garageband so it's not a terrible process, I just think $0.99 per ringtone is a bit ridiculous especially because you can buy the whole song for that.

Wednesday, July 23, 2008

iPhone review

Well my script actually worked and did score me an iPhone. Ran it and noticed the Short Hills mall had all three versions in stock and my wife went over. Turns out I had to be there to because I was the primary on the previous account so I left work a little early.

First impressions are that it's awesome. The main reason I got it was for the integration between it and the mac. So far everything has been seamless. I first went into the mail app on the phone at the mall so I hadn't synced up yet. First, you select Gmail, put in my gmail username and password and that was it. I saw no apparent way to add other mail accounts and was a little bummed at first. My fears were for naught as when I later synced with my mac, it pulled in my other mail account. Right now I can just pull but there are services to push (MobileMe being mac's solution) but I'm not that concerned about it yet.

Calendar integration is seamless as well. Syncing with my mac synced all my schedules to the iPhone. Haven't had it that long to tell if there are issues, none have popped up yet so we'll see. Same with my contacts from the Address Book. The only downside was I hadn't updated address book in a while so some of my numbers weren't in there. Definately not the phone's fault though.

There are a lot of apps available on Apple's AppStore, some are free, some are reasonable and some are outrageously priced. I'll start with the free ones first.

Pandora - This is the online radio station pandora. It's free but amazing. Experienced a couple hickups on the way to work this morning where only part of a song played and then skipped. (I'm guessing didn't fully download or something) But for the most part worked well for my commute. I highly recommend this app.

MobileNews - This is basically just a news source for Associated Press news. I've avoided the NYT app because people seem to be complaining that it's slow. MobileNews has been pretty good. My area is not supported for the "Local News" feature and the interface could use some polishing but it's not bad. They also have a web based version which is optimized for the iPhone.

AIM - AOL instant messenger for your iPhone. This was actually the first app I installed to let my coworker know I got an iPhone. Not spectacular but not terrible. Basic instant messaging.

Tomatoes - This is the Rotten Tomatoes website's app. Starts with a text box for you to type in a movie. Typing in a movie then searched for that movie in their database. Gives you a basic summary of the movie and their rating. Summary is only one iTunes screen high. Clicking on the movie name at the top brings you to the web page for said movie but in doing so, exits the Tomatoes app and brings you to the Rotten Tomates page for that movie. Probably wouldn't be terrible if the page it takes you to was optimized for the iPhone but it's not. Will probably use as a quick reference for movies I'm not familiar with. Could be better.

PhoneSaber - Ok, no point to this, it's a lightsaber, you can pick your color beam and swing your iPhone around to make lightsaber sounds. Pointless and a waste of space but I still have it on my iPhone to uhhh... show people how useless it is, yeah, that's it.

Now for the paid apps, these are ones I've actually spent money on. To be fair, I have a credit card that gives me reward points in iTunes cards so I haven't really paid for it, but in a way I have.

Crash Bandikoot Nitro Kart 3d - Graphics are very good and you tilt the phone to turn. Very addictive. Nice use of the controls.

Monkey Ball - Another pretty cool game that uses the motion features of the iPhone to tilt the platform. This moves a monkey in a ball and you go around picking up bananas. A little tricky to get used to but fun.

Well that's it for the Apps I'm going to review today. I have a few more apps on my phone but haven't used them enough to tell if I like them or not yet. So stay tuned. Overall the iPhone has not disappointed.

Monday, July 21, 2008

iPhone availability

UPDATE: Looks like apple changed the link to a PHP page. Not sure of all the details, maybe they are actually checking the time on the server end instead of just relying on some javascript. Oh well, I got mine. :-p

So my contract is finally up with Sprint so I can now leave them without paying any penalties. Avoid sprint like the plague. Nextel was decent until they merged with Sprint, but that's a much longer rant than the cool info you'll find below.

So I've decided to ditch Sprint in favor of AT&T, primarily so I can get an iPhone. Apple has an iPhone stock bit on their web page. Go there after 9pm and you can see if a store is expected to have an iPhone in stock the next day. I do not always get on my computer after 9 for whatever reason so I thought I would script something to just scrape the page and see if the store will have it available. I found something even better.

Go ahead, find a store near you and look at the source, I'll wait. See it? Yes, that bit of javascript where it calls:

That file appears to not only have if there will be an iPhone available, it also has which models it expects to have available. The only other thing I could wish for would be the quantity, but now I'm expecting too much.

So what do we do with it? I'll show you what I did. First, we'll use python because it's cool and makes stuff like this easy. Second, since it's a json formatted file, good choice apple, we'll use simplejson. Got all that? Good, let's script this sucker.

import simplejson, urllib
url = u''
availability = simplejson.load(urllib.urlopen(url))

Ok, that basically downloads the json file and parses it into a nice little python data structure which we called availability. Now, I'm really only interested in certain stores in NJ. So, I do a loop like the following:

for store in availability['locations']['NJ']:
print store['city']

There seems to be available: url, city, storeid, available. Available then lists each type of iPhone (white16, black8, black16) and a true/false if it is available or not. So go forth and script to your heart's content. To be nice, here my final script:

import simplejson, urllib
import smtplib


url = u''
availability = simplejson.load(urllib.urlopen(url))

interested_stores = [u'Rockaway', u'Short Hills', u'Bridgewater']

msg = "From: %s\r\nTo: %s\r\nSubject: iPhone availability\r\n\r\n" % (EMAIL_FROM, EMAIL_TO)
has_iphone = False

for store in availability['locations']['NJ']:
if store['city'] in interested_stores:
if store['available']['black16']:
msg += u'%s has black 16Gb iPhones available\n' % (store['city'])
has_iphone = True

if has_iphone:
server = smtplib.SMTP('', 587)
server.sendmail(EMAIL_FROM, EMAIL_TO, msg)

Tuesday, July 15, 2008

Using git

Things I like about git over subversion.

1. Branches are easy... no, really easy, just do a branch for every feature. Go ahead, you know you want to. 'git checkout -b coolfeature' It's just that easy.

2. Only check in part of a changed file. 'git add -p' It then prompts you line by line if you want those changes added or not.

3. It's fast!