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.

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

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

Things are Crazy

General, PHP, Tech, Web No Comments

The past two weeks have been nuts. I had to work last Saturday and it looks like I will be working this Saturday and Sunday! Damnit!

This release cycle is nothing short of a power cycle death march. We had a few weeks to add functionality  and do yet another redesign on some stuff. It was kind of crazy to begin with but hey, add the fact that the production system has been a little spotty and you have a recipe for watching the release deadline fly right by without fail. So there is that right now. I am struggling to not die.

Also this past couple of weeks, I have been working towards getting better with Java. I have been reading up and experimenting in the Java realm. I want to broaden myself from Systems Admin to Software Developer… I got involved in some java projects and Sean and I have been working on a new application called JAmba. Well, mostly Sean right now but I am learning. If you want to know more about JAmba go to www.jambagroup.org (I built the whole site…I am proud damnit). Sean and I are planning on using JAmba for the production site in this next release, provided we can work the bugs out. We hope to release the source code and the package on the JAmba site by next week for anyone to use and play with.

The next update comes from the little bit of personal life I have managed to sneak in to this crazy release cycle. At Karate,  as of Wednesday, I learned all four Kata I need for the test in May.  All I need to do is practice and polish and hopefully by June Lisa and I will be donning some yellow around our waist. Also, last Wednesday we had to do a birthday workout because our sensai turned 61, so we had to do 61 pushups, 61 sit-ups, 61 leglifts, 61 crunches… you get the idea. I am so sore still, though it was fun. 

Compiling Apache 2.0 with Mod_JK support HOWTO

Tech, Web No Comments

Compiling the mod_jk module in to the apache webserver allows for threading of jk connections and thus increases performance of your Tomcat, Jboss, or other AJP based web application. It will also increase the amount of connections you can serve at once. This is why I suggest compiling the module in.

With that said, I have ran in to what seems like a common problem with the instructions provided on the mod_jk website for compiling the module in. I have found the solution through much reading of the make log.

If you go to the mod_jk site page for how to compile the module in (found here - bottom of page) here is what it says:

Connector source is found in /home/tomcat-connectors-1.2.26-src
apache source is found in /home/httpd-2.0.63
[user@host] ~ $ cd /home/tomcat-connectors-1.2.26-src/native
[user@host] ~ $ ./configure –with-apache=${HTTPD_SRC}
[user@host] ~ $ make
[user@host] ~ $ make install
[user@host] ~ $ cd/home/httpd-2.0.63
[user@host] ~ $ sh buildconf
[user@host] ~ $ configure … –with-mod_jk
[user@host] ~ $ make
[user@host] ~ $ make install

This will result in an error in the first make step. When you configure the connector it goes in to the apache source and tries to grab a file that does not exist. Then when you run make, all of the referenced files generated by the configure script based off of the missing file are not there and it results in an error.

~snip~
mod_jk.c:3105: error: dereferencing pointer to incomplete type
mod_jk.c:3107: warning: assignment makes pointer from integer without a cast
mod_jk.c:3109: error: storage size of 'finfo' isn't known
mod_jk.c:3112: error: dereferencing pointer to incomplete type
mod_jk.c:3115: error: dereferencing pointer to incomplete type
mod_jk.c:3117: error: dereferencing pointer to incomplete type
mod_jk.c:3118: warning: initialization makes pointer from integer without a cast
mod_jk.c:3125: error: dereferencing pointer to incomplete type
mod_jk.c:3138: error: dereferencing pointer to incomplete type
mod_jk.c:3149: error: dereferencing pointer to incomplete type
mod_jk.c: In function `jk_map_to_storage':
mod_jk.c:3162: error: dereferencing pointer to incomplete type
mod_jk.c:3162: error: dereferencing pointer to incomplete type
mod_jk.c:3164: error: dereferencing pointer to incomplete type

~snip~

This is caused because the make command is referencing things in the Makefile.aspx file in the apache 2.0 source directory. The problem is that the file has not been generated yet. The aspx file is a perl file generated when you configure the code. So there is in fact a missing step. You must configure the apache source first then follow the online how to that the tomcat people have posted.

THE SOLUTION!!! FOLLOW THESE STEPS AND YOU ARE GOLDEN!
I installed httpd-2.0.63 and tomcat-connectors-1.2.26

The paths are:
/opt/src/httpd-2.0.63
/opt/src/tomcat-connectors-1.2.26-src

Configure the apache source and generate the missing aspx file
[user@host] ~ $ cd /opt/src/httpd-2.0.63
[user@host] ~ $ ./configure –prefix=/opt/apache2

Configure and install the mod_jk connector
[user@host] ~ $ cd /opt/src/tomcat-connectors-1.2.26-src
[user@host] ~ $ ./configure –with-apache=/opt/src/httpd-2.0.63
[user@host] ~ $ make
[user@host] ~ $ make install

RE-Configure the apache source and make/install it
[user@host] ~ $ cd /opt/src/httpd-2.0.63
[user@host] ~ $ sh buildconf
[user@host] ~ $ ./configure –prefix=/opt/apache2 –with-mod_jk
[user@host] ~ $ make
[user@host] ~ $ make install

You are all set and everything should have gone without an error. Just cruise to /opt/apache2/bin and run ./apachectl start

Technorati Tags: , , , , , ,

Facebook Apps are getting out of hand…

Web 1 Comment

Facebook FF

Today I found an app on facebook called “Friend Fu*k!” WTF?! Are you serious?! Here is what the app’s about page says:

First there were apps that let you smooch your friends. Now you can fu*k your friends. Fu*k yeah!

I think they have officially gone too far in my book because I am sure that my friends don’t want me sending them virtual fu*ks on facebook. I just think its a little creepy, don’t you?

*UPDATE - I realized that its tough to find new apps on face book so here is the link to Friend Fu*k.

Technorati Tags:

Is it Christmas?

General, Web No Comments

I don’t know why but I still think that this site is still the best thing I have ever seen:

http://isitchristmas.com

A site completely dedicated to letting you know if it is Christmas or not… There is even an rss feed that is updated daily for those of us that don’t have the time to go to the website to check. I checked out the source for the page and Google analytics is running on the site. I don’t know about anyone else out there but I sure know that I would love to see the stats and map overlay on the site.

Technorati Tags: , ,