If you have used twitter I am sure you have noticed that if you post a long url in your update it gets turned in to a tinyurl for you. This is really cool functionality and I have created a helper in rails to do it for me.
First, let’s talk about how you get a tinyurl. Tinyurl has a really simple api that you can call that will return a tiny url. It is rediculous how simple it is. You just call this url with a GET: http://tinyurl.comapi-create.php?url=http://example.com
The returned page will be a single line with the tinyurl equivalent. It is that simple. Now on to the rails part.
In your application.rb helper you would add this:
require ‘net/http’
require ‘uri’
def tinyfy(newurl)
url = URI.parse(’http://tinyurl.com/’)
res = Net::HTTP.start(url.host, url.port) {|http|
http.get(’/api-create.php?url=’ + newurl)
}
if res.body.empty?
#tinyurl is not responding properly… Return the original url
return newurl
else
return res.body
end
end
Now if you call the tinyfy method in your app, let’s say in your view, with the url you want to tinyurlify as the parameter the return will be the tinyurl. I take this one step further and have the tinyfy method make the url a link by adding the ‘a’ tags in the method like so:
require ‘net/http’
require ‘uri’
def tinyfy(newurl)
url = URI.parse(’http://tinyurl.com/’)
res = Net::HTTP.start(url.host, url.port) {|http|
http.get(’/api-create.php?url=’ + newurl)
}
if res.body.empty?
#tinyurl is not responding properly… Return the original url
return ‘<a href=’ + newurl + ‘>’ + newurl + ‘</a>’
else
return ‘<a href=’ + res.body + ‘>’ + res.body + ‘</a>’
end
end
That will return a nice linked tinyurl in your view. That is all there is to it.
As an operations engineer, I get to touch a lot of systems and a lot of different apps on those systems on a daily basis. This means a lot of log following, debugging, fixing, and more log following. Something that I love but often forget to use is background jobs. Background jobs work like windows on your desktop but for the command line. You need to switch between your text editor (vi), the log tail, and the command prompt. You could open three connections to the machine or you could use the background/foreground functionality built in to linux/bsd. Here is what you do:
You need to follow /var/logs/app.log, you need to edit /etc/app/app.conf, and you need to execute /usr/bin/app -debug to fix your problem.
First you run tail -f /var/logs/app.log and then hit ‘ctrl+z’ to suspend this task and return to the prompt. You should see something like: [1]+ Stopped tail -f /var/logs/app.log
The number at the beginning is the job number. That is how you get back to the process.
Now you run vi /etc/app/app.conf and hit ‘ctrl+z’ This will be assigned job number 2: [2]+ Stopped vi /etc/app/app.conf
Now you can use the ‘fg’ command to ‘foreground’ a job. So if you want to pull the log back up you do ‘fg 1′ and the log job will come back. Use ‘ctrl+z’ to go back to the command line and run ‘fg 2′ to pull up your app.conf. It’s that easy. If you ever forget what jobs are which you can run ‘jobs’ to display all running jobs:
[1]+ Stopped tail -f /var/logs/app.log [2]+ Stopped vi /etc/app/app.conf
Hey everyone, there is a new site on the interwebs today! Gripefest.us
GripeFest is an open forum for posting pretty much anything you want and your name is optional! It really is a Gripe Fest. It just launch about an hour ago and it already has a few gripes from the community. Pretty cool considering that it launched with only one gripe to begin with. So, go to http://gripefest.us and bitch about something, its fun
Over the weekend I was driving around Sunnyvale trying to find a place to live that is close to work when I decided that I needed some things from Wal-Mart. Now, I am not familiar with the area so, I pulled out the blackberry and loaded up Google maps. I have the curve with the GPS so, finding places near me is really simple. I typed “walmart” in the search and quickly got a list of local Wal-Mart stores. The closest looked to be in Moutainview, so I clicked on “directions to here” from my location and got the turn by turn. Here is where the problem comes in… I followed the directions right to the NASA Ames research facility. The directions took me right up to the security checkpoint! There is no Wal-Mart located on the military base. What went wrong here? Well, upon further inspection, I found that the Wal-Mart that I had chosen to go to was listed as Wal-Mart, Mountainview, Ca. Because there was no street address, I guess google wanted me to see where thier new facility on base would be or something. Lisa was with me and she has a military ID so we went on base to see where the map goes… The map led me right to the big NASA hanger (pictured below). Maybe, Google Earth saw a big ass building and assumed it must be a Wal-Mart. Needless to say, I was not happy about it. Perhaps making the app smart enough to at least warn that there is no street would be nice! Lesson Learned though.
Sitting here and working on my computer, I am hit with an idea for a project or plugin for my word press blog… I use growltunes to growl the song info from itunes as the tracks change. I am thinking, why can’t I growl the track info to my blog/website? Is there already an app that does this? If not, I think I am going to make that a weekend project. Doesn’t seem too hard with a pub/sub setup. Just a random thought for my blog.
So I have been playing with Justin.tv ever since I interviewed for the position and I must admit that I am addicted. It sucks that they decided not to hire anyone for the position
But hey, they got another user out of it!
Justin.tv is a live webcasting website that is totally free! Like YouTube for live footage. It is the most awesome up and coming application out right now.
You can check me out two ways… First you can click on the “Live Feed” link above or if you want to chat while I am live you can go directly to my live feed on Justin.tv by clicking here.
So I found this video on YouTube and it is a perfect example of what the job market will be like if we are not fucking careful and mindful of our economy…
I recently ported the toobs project from sourceforge (SVN) to github (git). So in order to do this I had to get git-svn to work. So with my last post I showed how I got the application to run, however, if you try and commit changes back to svn (git-svn dcommit) you will most likely end up with this error:
Password for 'mike': Can't locate Term/ReadKey.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at /usr/bin/git-svn line 2272.
This is because git-svn needs the ReadKey perl module to be able to read the server’s key to encrypt the password before it sends the password to the server. (wouldn’t want to be sending passwords in plain text across the internet would you?). Here is the solution:
Pull up the CPAN teminal: perl -MCPAN -e shell You may need to set it up if you have never used it…. just use defaults if you are not sure
Once at the cpan prompt install the needed module: cpan> install Term::ReadKey
once it is finished go ahead and quit the cpan terminal and you should be able to run git-svn dcommit and everything should be peachy
After a few hours of googling and pull some hair out, I have finally figured out how to make git-svn work on Mac OSX 10.4 Tiger. If you have installed git on your Mac using mac-ports or source, you will find that running git-svn causes an error similar to this:
Can't locate SVN/Core.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl /sw/lib/perl5 /sw/lib/perl5/darwin /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at /usr/bin/git-svn line 24.
This is because when you installed SVN it didn’t put the perl modules in the correct place. Here is a quick way to fix it.
mike@mikes-laptop$ locate SVN/Core.pm
In my case it was located in /usr/local/lib/svn-perl/SVN/Core.pm
Now we need to link that SVN directory in to your perl directory so perl can pick it up and use it. We will put it in /System/Library/Perl/Extras/5.8.6 mike@mikes-laptop$ sudo ln -s /usr/local/lib/svn-perl/SVN /System/Library/Perl/Extras/5.8.6/SVN
Now if you run git-svn you will notice a different error that resembles this:
Can't locate loadable object for module SVN::_Core in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl /sw/lib/perl5 /sw/lib/perl5/darwin /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at /System/Library/Perl/Extras/5.8.6/SVN/Base.pm line 59
BEGIN failed--compilation aborted at /System/Library/Perl/Extras/5.8.6/SVN/Core.pm line 5.
Compilation failed in require at /usr/bin/git-svn line 24.
We just need to link the auto/svn directory as well. Use the prior base path but instead of SVN you use auto/svn. Like so:
So, today, I get presented with the task of setting up a git repository for my office to experiment and test as a replacement for SVN. Imagine my surprise, considering that I came in to this office preaching the benefits of distributed source control and the awesomeness of git, just to get blown off by everyone due to lack of understanding. Now, everyone thinks its a good idea all of a sudden and I think that github.com really drove that one home for me. Thank you Chris and github. Anyway, so now, I get to try and create a repository using git and get Cruise Control to build from it.. never a dull day in Mike’s world at work…