Tuesday, June 23, 2009

Gitcasts- Scott Chacon

http://github.com/schacon/
Mother Futon. The source is strong with this one. But he also has a great video series on git.

http://gitcasts.com/episodes
These videos are great. They're almost good enough to be used as reference, but they're not. Why? They're videos, and 5, 10, 30 minutes is way too long to find a command that you were looking for. At the same time though, a reference of common commands (beyond the REALLY common 4 or 5) is not really anywhere that I've seen. So I'm just going to list off the less than super common commands that I learned in these videos.

For those less frequent times that you need to use git, I present the other half of the porcelain here.

Ruby Kaigi

The lineup:
http://rubykaigi.org/2009/en/talks/

So I'm headed to rubykaigi in a few weeks, and I'm looking forward to meeting some of the people in the Japan ruby community, and of course, some of the more adventurous westerners. It's sure to be an interesting time, with heavy-hitters on both sides of the Pacific. Not to put down the western presenters, but it looks like the Japanese presentations will be a bit more technical, or at least low level (Yehuda Katz excepted). The most challenging talks will undoubtedly be complicated by my Japanese level.

That said, what the hell do I wear? It's a three day conference in Tokyo. It's going to be hot. Do I go with cool-biz? Are Japanese developers as sloppy as most western ones? Probably not possible. But the ruby crowd is fairly metro compared to some other communities... But the ruby crowd is fairly metro compared to some other communities, so what's it going to be? A suit? Cut off jean shorts? What to do...

Ah, phew. Three guys dressed fairly casually, this helps:
http://redhanded.hobix.com/cult/chairmanTakahashiInTaiwan.html

Monday, June 22, 2009

Weird path issues from upgrading rails

This issue came up when a request to the update action was giving this error:
ActionController::MethodNotAllowed? (Only get and post requests are allowed.)

Okay. At first I thought it was an issue with the form itself or the params being passed, but then I looked at the route method in the view and saw this:
:url => members_path(current_member)

Looks okay, but it's not. At some point between Rails 2.1.0 and 2.3.2, pluralized calls changed their meaning. To debug this, I went to irb. "IRB?!?" you say? Yep. You can get to these methods by using the "app" variable.

> script/console
>> app.members_path(Member.last)
=> "/members.%23%3Cmember:0x3d8838c%3E"

There's a dot in the path? That's weird. What if I try:

>> app.member_path(Member.last)
=> "/members/721714"

Sweet, back to a normal slash, and it's smart enough to grab the id, instead of the object.

For more about tricks with the irb, see the irb mix tape post from err the blog.

Sunday, June 21, 2009

Deploying a rails app to a sub uri with passenger and nginx

This seems simple, but it could be a little tricky if you haven't done it before.

The documentation is a little unclear. The first thing to keep in mind is that you should not have both of the server blocks that are listed. Just add the extra lines:

passenger_enabled on;
passenger_base_uri /rails;


Here are my parenthetical comments for doc code:

server {
listen 80;
(port number, nothing new here)
server_name www.phusion.nl; 

(server name. Nothing new here either)
root /websites/phusion;

(this is describing the root of the main site, not the app on the suburi)
passenger_enabled on;

(self-explanatory)
passenger_base_uri /rails;
}

(The suburi that will be tagged on at the end of the path)


And for the symlink
ln -s /webapps/mycook/public /websites/phusion/rails

This links the public directory of the webapp that you are deploying on the suburi to appear in the folder of the main site.

Other things to keep in mind:

If you're using a rails app from version 2.2.2 on, you will have to make an additional adjustment. This blog recommends opening up the ActionController and ActionView base classes for an "automatic fix" that doesn't "hardcode" the uri. This is clever, but for now I don't need that level of dynamism. Adding this line works fine for me:
config.action_controller.relative_url_root = '/myapp'


Besides this, one thing to look out for is any places in your application where you've hardcoded routes in params for url_for(link_to, etc) methods. These will not add the requisite '/myapp', causing potential breakage.

I'm sure you didn't do that though, because you know better. However, maybe you from 6 months ago didn't...

Thursday, June 18, 2009

Unintuitive error

Error:

>ruby script/server
config.gem: Unpacked gem mislav-will_paginate-2.3.2 in vendor/gems has no specification file. Run 'rake gems:refresh_specs' to fix this.
config.gem: Unpacked gem ruby-hmac-0.3.2 in vendor/gems has no specification file. Run 'rake gems:refresh_specs' to fix this.
no such file to load -- hmac-sha1
...
(trace)
...
no such file to load -- unicode
...
(trace)

>rake gems:refresh_specs
(same as above)

Actual issue:

There is no spec for these gems because there was an attempt to rm, git rm, or svn rm them at some point which worked locally, but didn't end up working after going through the version control. A symptom of this is a version mismatch between what is in environment.rb, gem list, and /vendor/gems. Also, the gems in gem list will say that they're frozen, but they aren't. They just have hobbled directories.

Solution:
1. Try to install the gems.
2. Delete the offending gem folders in /vendor/gems
3. rake gems:install

Wednesday, June 17, 2009

Slicehost Setup- Part 2

This article is pretty good for getting set up, but an important thing to note is this innocent seeming sentence:
"We are going to do this work as the git user so that we don't have to fiddle with permissions when we are done."

Later, when you don't have a shell as the git user, you don't have that option. So if you create a git repo later as any other user, this is the "fiddling" you need to do:

sudo chown -R git project


Here's the error:
~/projects/project (master) $ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 208 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
error: unable to create temporary sha1 filename ./objects/a7: Permission denied

fatal: failed to write object
error: unpack failed: unpacker exited with error code
To ssh://git@IP/home/git/project/.git
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'ssh://git@IP/home/git/project/.git'

Tuesday, June 16, 2009

Screwing up git

Egads. I just deleted my branch without pushing the changes. At first I thought that I might have lost a couple of days of work. But then I found this article. The first comment is particularly helpful. The docs about git log are also helpful.

Basically, what I did from this point was do a "git log -g", which allowed me to look through all of refs, whether they had associated branches or not. Next, I merged these back in one by one by their sha hashes using "git cherry-pick . Ideally, I might have done this in a new branch instead of master, but I didn't think ahead. Also, there may have been a better way to do it than going cherry-pick by cherry-pick, but there were only 10 or so, and merging smaller pieces worked out well.

Anyways, if I lose my changes like that again, my workflow will be something like this:

git log -g
git checkout -b new_branch_to_apply_cherry-pick_to
git cherry-pick (until done, merging/committing stuff as necessary)
git push wherever
git checkout master
git pull wherever
git branch -D new_branch_to_apply_cherry-pick_to (after making damn sure things are in order)

Monday, June 15, 2009

Slicehost Setup- Part 1

I'm not going to pretend that I figured out anything on my own. Here are the tutorials I used:

For setting up most things

For setting up git

Setting up Passenger/nginx


The only snag I hit was in running the git commands (remote add, clone, etc). Apparently, if you use the default port (22), you can do this:

git remote add origin git@YOUR-SLICE-IP:project

If you specified a different port, you would need to do this instead:

git remote add origin ssh://git@YOUR-SLICE-IP:PORT_NUMBER/absolute/path/to/git/project

Sunday, June 14, 2009

Ones And Heroes

The new blog. If you're looking for the old stuff, it's here.

In this post, I'm going to be profiling the github user who goes by semanticart, Jeffrey Chupp. He has a couple of really cool projects, and I would say is a little underrated based on his follower count. Lets go project by project:

Rack-roll. This is what led me to his profile in the first place. I was searching for rack projects and this came up. Basically, it uses rack to randomly redirect a visitor to your page to the now infamous video. This itself might be somewhat worthless, but it does show a simple rack app in action.

In contrast with that is is_paranoid. This does mass appeal as evidenced by the 176 watchers. This is similar to acts_as_paranoid, but with a few differences. That said, his Readme is a lot more informative than acts_as_paranoid's is. Another difference highlighted in the readme is "destroying is always undo-able, but deleting is not." It's pretty interesting that this package didn't get a message in this recent article.

The last project is "a simple wiki powered by sinatra" called "Hoboken." I've been really interested in microframeworks lately, but besides not knowing much about data-mapper or haml, it only has 9 watchers, compared to is_paranoid's high count. I might just wait this one out till either it gets a bit more traction or I get to know haml and dm a little better.

With this profile, we have project with a ton of watchers, and two that while not so popular, show examples of Sinatra and Rack. You can tell that he has a sense of humor and cares about what's hot, as well as what's useful.

Also, he had an awesome idea for how to design vanity page.

Thanks Japan

I was in Japan for a year. Reverse culture shock has come and gone. I'm no longer horrified by the slovenly, overweight, rude, self-centered denizens of the home of the free and the brave. Although the MBTA trains are still mind-bogglingly shitty compared to even the back-woodsy* Hokuriku line which passed through Namerikawa, the town where I stayed. There was no inexplicable blue sparking from the third rail, no trash on the seats and floor, no delays due to signal problems or disabled trains, no overshooting the platform and having to back up to let out passengers, and there were no crashes due to the drivers texting. Another thing that I'm not quite over is the terrible rice here. Minute rice, Uncle Bens, and especially Rice-A-Roni are about the worst food products I can think of. Barring homelessness, I plan on having a rice cooker for the rest of my life. Scratch that, homeless or not, I want one.

Anyways, A year in Japan was long enough for me to pick up a few habits which, despite my best efforts, I cannot seem to be able to shake, even after almost a year. The first one is staring. I stare at nearly everyone I see. Because for a year my life worked like this: I know every person who isn't Asian. I know a lot of Asian people too, and I might have to work to recognize them because I meet so many new people all the time. So I'll stare at people of any race. Incidentally, if there's anyone in the greater Boston area who is bothered by a guy who is 5'11" with a shaved head (and more often than not unshaved face) staring at you, here's what I have to say: 1) That's me. 2) I'm sorry. 3) I'm working on it.

Habit two is paying for things by putting my money on the counter instead of handing it to the cashier directly. This still weirds me out. In Japan, there are always little trays that you put the money into, and take the change out of. Here, everyone just hands each other money?! With their hands?! It's so barbaric.

Habit three is slurping my food, especially noodles. In Japan, udon is meant to be slurped, as are ramen, and soba. Spaghetti is gray territory. That said, I've seen Japanese people slurp pizza and sushi also. Maybe it's just a cultural difference between tongue and slurp to get food that didn't quite make it in. Napkin is probably more polite in both cases, but as far as regular eating, here are some tough situations:
Spaghetti with whiteys- This one is obviously a bite, let fall sometimes, use napkin, and maybe a little tongue when needed situation. Doesn't always happen. Sometimes I just gotta get my slurp on, which is wrong. No slurping.
Udon with whiteys, Japanese restaurant in America- Everyone else is slurping, so I guess it's ok here, but all my friends will think I'm weird. No slurping.
Udon with Japanese, Japanese restaurant in America- This one's complicated. I guess it depends on their Americanization level.

Habit four is bowing. I can't help it. Especially when I pay for something or say goodbye to someone. It's slight, but not small enough to be a normal American head-nod.

Habit five started innocently enough. Japanese people at a certain point in their history decided to adopt the handwave, but at handshake distance. Me and my friends in Japan thought it was really funny. So we'd all do that when saying goodbye. And now, well, it's just like what your mother said about your face staying that way if you make a face too much. I wave to people from three feet away, and I look like a complete asshole.

Anyways, thanks Japan for making me cripplingly awkward for God knows how long.


*Japan's backwoodsy areas have no trains, and barely any people. Somewhere in Japanese law there seems to be a rule that nobody can live anywhere close to areas that have an abundance of trees. They're reserved for camp-grounds and tourist attractions. The Hokuriku region is "back-woodsy" in the sense that it's full of small towns, and brimming with parochialism. The fact that it is on the opposite coast of Tokyo is keenly felt, and despite the abundance of concrete, and lack of any natural surroundings to speak of, it is impossible to forget that you are in "uranihon" (裏に本), the "back side" of Japan.