Getting TinyUrl’s in Rails

Rails, Tech No Comments

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.

CTRL-Z and fg: my new(old) best friend

Tech No Comments

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

It’s that freaking easy. Enjoy…

GripeFest - Let the bitching commence

Web No Comments

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 :)

Google Maps - Fail!

For Sale, Tech, Web No Comments

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.

Technorati Tags: , ,

SlumpBuster

Music No Comments

I have been in a music slump for like 2 years now. Nothing I would write would ever be good enough to keep or even playback. I had no ideas, no feels, nothing… I had serious writer’s block! But last week I wrote and tracked the best song I have ever done! It is a really ruff cut but I hear more potential in the riffs and feels than i have heard in any indie band I have ever scouted as an A&R guy. The song is industrial with some metal and ambient origins. I just need to arrange and further produce it out now. The best part is that I have busted my slump! I have so many other ideas coming to me everyday now! I finally see the end of the tunnel for my first solo album! It’s pretty far away, but I see a faint glow!

New Project Idea…

Tech No Comments

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.

Yahoo!

General No Comments

I am now a Yahoo! That’s right, for some of you that actually read this and don’t know, I got laid off at the end of April and in the same day got an interview for Yahoo. I mulled over my offer and interviewed at quite a few other places until I decided to take the Yahoo job. The catch is that it is in Sunnyvale :( and I can commute at 2 hours each way or move. So, I am obviously moving :) 

So, now that I have a job and a cube, I need things for my cube to make it nerdy-awesome. I have been putting things on my “gift list” (link above ^ ) so that:

A) I don’t forget and have a reference to all the things that I have found, thought was cool, and wanted.

and

B) So that if any of my beloved readers/fans wants to get me something… there is a list :)

So check it out, you may find something that you want too :)

Justin.tv!

General, Videography, Web No Comments

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.

JTV

Karate Photos are on Flickr

Martial Arts No Comments

Thanks to Lisa’s photography work, I have some cool pictures from yesterday’s Karate Promotional.

Check them out here - http://www.flickr.com/photos/parabuzzle/sets/72157605120323408/

Thrust Kick

Level up!

Martial Arts No Comments

Today was my first Karate test and I passed! Yay! Now I am donning the yellow around my waist and next week I start sparring. I’d love to talk more about it but I am off to a party right now. Pictures coming soon.

« Previous Entries