dnite’s ‘old’ Blog

For my new blog, head over to http://blog.dnite.org

  • Moved Out!

    Thanks for stopping by my blog! It's been fun over here at Wordpress.com but I've moved to bigger, better things. My new blog is located here! Hope to see you there!

Moving out…

Posted by dnite on March 8, 2007

WordPress.com has been good to me for some time but it’s my time to move on out on my own. From now on, you’ll find me at http://blog.dnite.org (and probably just plain http://dnite.org as well). I’ll be doing most of my development and rails blogs over there as well as release the plugins I’ve released here over there. See you there!!

Posted in Blogs, Misc., Ruby on Rails, Web development | Leave a Comment »

OpenID testing in rails

Posted by dnite on March 2, 2007

UPDATE: I’ve moved my blog to http://blog.dnite.org and updated this into a real plugin. You can check it (and anything else I have going on) over there.

It’s all the rage lately. OpenID has quickly become huge as of late. With huge companies like digg, microsoft and aol picking up and supporting OpenID, it’s just a matter of time before we’re all basking in OpenID glory and wondering what we ever did without it.

For those of you not in the know, OpenID presents a decentralized universal login. Basically, your URL is your login name. When you visit a site that accepts OpenID logins, you give them your OpenID URL and your forwarded to your OpenID server to log in. Once you log in, your redirected back to where you came from pretty seamlessly. It’s really cool stuff with a lot of potential. It offers a nice speed bump for spammers on a lot of blogs. It also offers a way for people to keep track of the same person across multiple sites. If you have a friend you met on xyz.com, you can rest assured that it is the same person you happened across on abc.com as well.

Less than a week ago, DHH added a plugin to the official Rails subversion repository that wraps around some of the lose ends for accepting OpenID logins in your Rails application. It’s early in development but it works quite well. Pick it up and read through the README for basic instructions on how to get things working.

Recently, I started training myself to do Test Driven Development. I bought the GREAT peepcode screencast on the topic and got started. This means that I’m writing tests for everything and I essentially won’t really look at my site until it’s close to done. So after I implemented OpenID into my new application, I needed a way to write some tests for it. I didn’t want to hammer a OpenID server with constant testing so I wrote up a ‘stub’ that I figured I’d share with others wishing to write tests for their OpenID applications. It’s very basic right now. I’ll probably improve it shortly down the road, but for right now. It’ll do.

Posted in OpenID, Ruby on Rails, Web development | 2 Comments »

Self Referential Two Way Friends Ruby on Rails Plugin

Posted by dnite on January 26, 2007

UPDATE (3/08/2007) :: I’ve moved my blog and this plugin (an updated version at that) over to http://blog.dnite.org. If you want more information and would also like to download it, head over there. That’s where I’ll be residing from now on.

Posted in Ruby on Rails, Web development | 5 Comments »

Acid 2 test results…

Posted by dnite on December 28, 2006

Today, while very bored, I decided to give Firefox 3 a download. To my surprise, a brand new build was released on this very day! Lucky times for me! This got me thinking about the acid 2 test that I had recently read about firefox 3 passing. I knew they had passed the test after they released the last alpha release of firefox 3, but this was a brand new release so I had to test it out. Instead of just sharing the results of firefox 3, I decided to grab the latest 2.0.0.1 release of firefox as well as Opera 9.10. I’m running Ubuntu Linux (6.10, Edgy), so I’ll also be sharing Internet Explorer 7‘s ‘results’ from inside VMware. Click any of the images to view them at their full resolution.

The first browser I opened up and tried was The latest Firefox most of you are probably using right now. Firefox 2.0.0.1 was released shortly ago which is essentially just a few bug fixes and a vulnerability plug. Definately not the best results. You might be able to tell that it’s supposed to be a face, but that’s about it.

Firefox 2.0.0.1 Acid 2 Test

Firefox 3 was next. I was excited about this one because it should have passed the test. But sadly, it did not. It came really, really close. But not quite. My only guess is that the new gecko engine changes didn’t make it into the this newest build? Not sure, but still impressive results.

Firefox 3 Alpha2 Pre Acid 2 Test

Next came Opera. I had read a while back that Opera had passed the acid 2 test, but I never actually tested it. It was true. Opera passed with flying colors. This is what the test is supposed to look like for those of you who’ve never seen the test.

Opera 9.10 Acid 2 Test

The next was just for my own entertainment. Internet Explorer 7. I went out of my way to load up my virtual machine to test this one but, my lord, I didn’t think it was going to be this bad. Can anyone tell me what this is? Or maybe how Microsoft feels they are more standards compliant than they were before Internet Explorer 7? I didn’t want to go through the trouble of getting a version of IE6 running, so I just hunted down a picture of what it’s test looked like, it’s not much better. I even gave them the benefit of the doubt and noticed the souce for the test doesn’t contain a strict doctype, so I changed it and still got the same results. The only difference that strict made was the scroll bars didn’t appear.

Internet Explorer 7 Acid 2 Results

There we have it. The few popular browsers I was able to test pretty quickly. The only browser I would have liked to include but couldn’t, was Safari. I need to get me a mac. Who wants to send me a macbook pro so I can post the results of the acid 2 test?? Donations welcome! x=)

Posted in Blogs, Linux, Tech News, Web development | 2 Comments »

Airport Hustler?! Are you kidding me!?

Posted by dnite on December 8, 2006

Just wow. I found this article on digg and I had to comment. it’s from, yet another, prude fucking American about the new airport x-ray scanners they are using in Phoenix. I REALLY don’t understand what the big deal is.

The TSA is about the baddest, bawdiest bureaucracy ever to curse a country, but geez, even they must have needed help on this one. I figure they went to Larry Flynt at Hustler Magazine for advice. Only a pornographer of his unsavory talents could have dreamed up such wickedness: tell Americans that merely groping us is no longer enough protection from the terrorists thronging our airports. Now we must pose for dirty pictures, too.

Hustler!? Are you out of your mind!? The only reason these scanners haven’t come out sooner, is because of how obsessed America is with sex and nudity. We don’t have a problem showing dead bodies and talking about killings all over the news without censors, but the minute we think about a breast, stop the country. lock your doors. something bad is going to happen. GROW THE FUCK UP, AMERICA! The only reason we haven’t been using these scanners for YEARS now is because of how prude this country is. They needed to devise a way to ‘censor’ our naughty bits. What is the big deal?! Your junk is being censored to a degree! You can’t see your face! No one is going to see this but someone who’s seen so many of these pictures, he doesn’t even care any more! Trust me, your not that attractive. I’m sure of it. Because, if you were. You probably wouldn’t care either. No one cares about seeing you naked. I’m very sorry that I have a penis. I’m really sorry that you have a vagina. Terribly sorry that you have breasts. It’s part of nature! IT’S NOT THAT BAD! Why don’t we, as American’s, stop worrying so much about sex and start worrying about the fact that all we ever see on the news and TV and movies are people dieing! Why is something as beautiful as sex, so looked down upon (only, really, in America, too) as such a dirty thing? Why are things that are much more harmful, like violence and all the terrible news that we as a society have become addicted over years and years become so common place that we don’t even care that we just saw a REAL PERSON fall off of that building on network TV. Stop looking for a reason to be angry, just because your bored and you think you SHOULD be angry. I’ll strip naked to ensure my safety any day. These scanners make that process a whole lot more private, so I’m all for it. Just because you couldn’t think for yourself when they spoon fed you this garbage as a child that sex is a such a bad bad thing. Just lighten up. blech. I’m done. </incoherant_rant>

Posted in Airport Security, America, Blogs, Gaming, Misc., Sex | 1 Comment »

Ruby on Rails :: Restful friends with has_many :through

Posted by dnite on November 25, 2006

EDIT (2007-03-07) :: I’ve updated this as a plugin and released it at my new blog (http://blog.dnite.org). I’ll keep this information up here, but everything is a lot cleaner and works a lot better with the new plugin. So go check out my new blog!

EDIT (2007-01-23) :: I’m depreciating this entry/tutorial!! If you have problems getting this working, just be patient, I’m going to be releasing a plugin in the very near future that will work a lot better and be a lot easier to impliment than this! Just give me a few days…I’ve been working on a project of mine and while I learn Rails. One thing that surprised me was that as many tutorials there are on how to create a blog, there are very few about creating a friends system. So I’ll try and go through the system I put together today after many headaches (that I’ll explain later).

We’re going to keep it RESTful here (or as RESTful as we can). I’ve found that the easiest way to approach anything RESTfully is to understand the path first. So let’s start there. These are the path’s we’ll need to accomplish our friends methods.

# List a user's friends (index action, GET method)
/users/1/friends

# Confirm that a user wants said friend. (confirm action, GET method)
/users/1/friends/2;confirm

# Add a friend (add action, POST method)
/users/1/friends/2;add

# Remove a friend (destroy action, DELETE method)
/users/1/friends/2

# Show a friend
/users/1/friends/2 (show action, GET method)

We’ll need a couple of models, a couple of controllers, and a couple of routes. I’m assuming you know how to make a new Rails project, so let’s get started by creating the models. We’ll need a User model and a Friendship model. I’ll keep them simple here.

First, here’s the tables I created.

create_table :users do |t|
t.column :name, :string
t.column :created_at, :datetime
end

create_table :friendships, :id => false do |t|
t.column :user_id, :integer, :null => false
t.column :friend_id, :integer, :null => false
t.column :status, :integer, :null => false, :default => 0
t.column :created_at, :datetime
end

The models look like this.

class User < ActiveRecord::Base
has_many :friendships
has_many :friends, :through => :friendships
end
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => 'User', :foreign_key => 'friend_id'
end

Now, here’s where I was pulling my hair out. Because, in theory, that association looks ok to me. But if I try and do something like…

User.find(1).friends

I get a nice and very strange SQL error.

Mysql::Error: Column 'friend_id' cannot be null: INSERT INTO friendships (`status`, `user_id`, `created_at`, `friend_id`) VALUES(0, 2, '2006-11-25 01:06:46', NULL)

The strange part isn’t the error. It’s that, one, there is no friend_id (and I still have no idea why) and two, it’s putting what SHOULD be the friend_id into the user_id column in the table. I still have yet to figure out why this happened, so I just went ahead and made my own little work around which works just fine and in all technicality, will probably work better down the road when I have more attributes in the friendships model. But if anyone has any ideas on what could be wrong, I’d love to hear about it.

Anyways.. Back on topic. Now we have the relationships, we need to interact with them. Being RESTful says that we need to do something like /users/1/friends/2 with the correct method. So I created a friends controller that looks like this.

class FriendsController < ApplicationController
def confirm
@friend = User.find_by_id(params[:id])
@current_user = current_user
end
def add
if !friends_already?(params[:user_id], params[:id])
add_friend(params[:user_id], params[:id])
end
redirect_to users_path
end

def destroy
if friends_already?(params[:user_id], params[:id])
remove_friend(params[:user_id], params[:id])
end
redirect_to users_path
end

protected
def friends_already?(user_id, friend_id)
user = User.find(user_id)
friend = User.find(friend_id)
return true if user.friends.include?(friend) && friend.friends.include?(user)
false
end

def add_friend(user_id, friend_id)
Friendship.create({:user_id => user_id, :friend_id => friend_id})
Friendship.create({:user_id => friend_id, :friend_id => user_id})
end

def remove_friend(user_id, friend_id)
Friendship.delete_all "user_id = #{user_id} and friend_id = #{friend_id}"
Friendship.delete_all "user_id = #{friend_id} and friend_id = #{user_id}"
end
end

The confirm action (/users/1/friends/2;confirm) shows a dialog w/ a button that lets the user confirm that he wants to be friends with this person. The button posts to /users/1/friends/2;add. From here it’s pretty self explanitory. It looks really nice when you can call /users/1/friends to list all of someone’s friends. Any extra attributes needed can be added in the add_friend action. Now all you need to do is add the new cool restful routes to config/routes.rb

map.resources :users do |user|
user.resources :friends, :member => { :confirm => :get, :add => :post }
end

That should do ya. Sorry this isn’t a full out tutorial, but you should definately have a good idea on how to impliment a friends system pretty quickly now. Make changes. Do what you want. Let me know if I screwed anything up. I’m still learning this stuff, so what I have here could be completely stupid. Let me know what you think.

Posted in Ruby on Rails, Web development | 9 Comments »

What happened to the PS3 recall story!?

Posted by dnite on November 21, 2006

Really late last night, a story appeared on digg about a “fatal flaw in the gpu” of the playstation 3, which would result in a recall of 650,000 units. I dugg it. This morning. That story is completely gone. Google turns up very little. Searching Google Blogs gives me the link to the old digg story, but digg says the story doesn’t exist. Is this the kind of thing sony wants under the radar so they’re putting the corporate muscle to work? Or was it completely false so they’re shutting down anyone mentioning it? I would think a story like this would spread like wildfire. So what happened?? Comment with answers!

EDIT :: Ok.. If you read any of the comments, you will realize that I was retarded. But in my defense. I wasn’t the only one. I didn’t bother reading the actual acticle, otherwise I’m pretty certain it would have dawned on me that it was fake. I guess the Nintendo fan-boy in me just really wanted it to be true. My appologies for being dumb.

Posted in Misc. | 4 Comments »

Why Wii Sports was a brilliant move…

Posted by dnite on November 20, 2006

Nintendo’s brand new Wii came out yesterday so I figured it was only fitting to blog about it. For the first time since the Super Nintendo, you get a game packaged in with the new Wii. Wii Sports is a very very simple game. There isn’t a lot of depth to it. It’s just fun. Wii Sports is getting mixed reviews, but I can already tell why Nintendo packed it in with the system. Because it’s going to sell systems AND games. Let me explain…

Nintendo wants the non-gamer market. This means that all those people who have never played a game in their lives need to see a game that they can instantly pick up and play without a problem and have a blast with. Wii Sports is perfect for the non gamer because of it’s simplicity. There are no complicated controls. You don’t have to worry about making sure your fielder runs to catch the ball, all you have to do is pitch. You don’t have to worry about setting power and curves and angles and what not on little meters when you go to bowl, you just bowl. This is going to sell systems to the non gamers.

These non gamers obviously had to find out about Wii Sports somehow. You can ask any hardcore gamer if they dislike ‘recruiting’ gamers and none of them will say they do. So Wii Sports gets to be the game that the hard core early adopters show off to their non gamer friends to get them to buy a system. But there is another reason Wii Sports is a great pack in. Because all those hard core gamers will play it. These games are teasers for those of us who want depth in a sports game. When we play Wii Bowling and love how great it feels to bowl, it makes us wish there was a better looking bowling game. Maybe some better pin physics. So when Mario Bowling (or any more full featured bowling game, for that matter) comes out, we’re definately going to look twice at it. When we swing the Wii-mote like a bat, it just wets our appitite for MVP Baseball ’07 or ’08. When we swing the racket, we can’t wait to have more control when playing a new full featured tennis game. The few punches you can throw (and the pretty good workout you can get) from boxing just makes us want to be able to have that many more options in our fight.

Every one of the Wii Sports is intentionally simple. The graphics are all pretty clean, but they’re far from gorgeous. The games are all pretty polished, but they leave so much more room for more. This is why I think that packing Wii Sports in with the Wii was the best move of this generation as far as selling systems. No one’s left out. Keep it going Nintendo!

Posted in Gaming, Video Games | Leave a Comment »

Transmission on Ubuntu Edgy

Posted by dnite on November 16, 2006

I miss my uTorrent. I could (and have) run uTorrent in wine while running Linux, but that just sucks. So I went looking for a better client. I don’t like BitTornado, or the included bittorrent client that comes with Edgy. They’re ugly and I don’t feel like they work very well. So I found Transmission. Transmission is very light weight. Very simple. It just works. I have recently read that some private trackers have banned Transmission, because it does (or maybe used to?) update the tracker more often than it’s suppose to, but unless I see any big problems (which I will report here) I am going to use it because I like it. For those of you who want to use Transmission with Ubuntu Edgy and are ripping your hair out because you can’t find a good repo. Here it is. Took me a while to find it, but I like using the repo, because it gets updated pretty often.

deb http://acorbeaux.free.fr/ubuntu edgy transmission

Add this repo to your /etc/apt/sources.list and then run the following.

sudo apt-get install transmission

There you have it. A up to date version of Transmission. Run it with the following and your all set. The first time you try and open a torrent in firefox after installing Transmission, click the dropdown, select Other and enter the command below with /usr/bin/ before it and it should stick.

transmission-gtk

Happy bittorrent.. ing..

Posted in Linux, Ubuntu | 5 Comments »

More Ruby on Rails with Ubuntu… (rails.vim)

Posted by dnite on November 10, 2006

UPDATE: I have updated this entry on my new blog at blog.dnite.org. That link is a direct link to the updated article.

I wrote an article not too long ago about installing Ruby on Rails on Ubuntu (Edgy) quickly and easily. The one section I left pretty ‘in the air’ was definitely the IDE. I feel that Linux has the biggest choice when it comes to editor options.

If your using Windows, you’ll probably use RadRails. It’s feature rich. It does everything you need. And windows Java machine just seems to work more efficiently, in my experience, than the ones for linux. If anyone wants to give me some hints to improve my java machines performance, go right ahead. On the mac. You have TextMate. Mac’s also have a lot of options, but from what I’ve heard and seen. Very seldom do you develop Rails applications on a mac without using textmate.

Now, for Linux, you have a variety of things to choose from and I’ve dipped my hands in a few of them. First, I tried RadRails. RadRails is what I used in windows and it was familiar to me. Since it runs on all 3 platforms, I figured I’d give it a shot in Linux. The problem was, that it just seemed a lot slower than it ran in Windows. I’m not exactly sure why this is, but speed and reliability were the reasons I went looking for a better alternative. I did some research and found that some people used jEdit. But getting jEdit to work in Edgy was a chore, do I didn’t even try. gEdit was also another option. It highlights syntax. It can take plugins. It’s a pretty light weight editor. I tried this for a couple of days, but it just didn’t feel right.

Over in the #rubyonrails IRC channel on irc.freenode.net, I heard about vim and a plugin called rails.vim. I’d given vi a try a long time ago. But never a substantial try. It was always really confusing to get into right away. It’s just not like most other editors. But I figured I’d give it a shot anyways. After a week or so of working with Vim and rails.vim, I’m pretty sold. I’m not 100% comfortable with it just yet, but I can definitely see the potential. I find myself hitting ESC and starting to type :wq when quickly editing something in gEdit or something. Rails.vim takes vim a step further and adds a ton of nice Rails features. Here’s what I did to get into and start enjoying using vim in a couple of days.

First and foremost. Make sure you have Vim installed. Pretty simple. The vimtutor command is optional but VERY VERY recommended if you’ve never used vim. Take the half hour to complete the tutor and you will understand vim a lot better.


sudo apt-get install vim-common vim-runtime vim-gnome
vimtutor

Now that you have vim installed, let’s install the vim ruby gem that gives you all the nice syntax highlighting and other cool ruby features. When you run vim-ruby-install.rb, it gives you the option to install to your home folder. I picked this option, so make sure you don’t run this with sudo.


sudo gem install vim-ruby --remote
vim-ruby-install.rb
(select option 1 when it asks where you want to install. /home/username/.vim)

Now you should have Vim installed with some nice ruby stuff. Let’s go ahead and make a startup file to get rid of a few vim annoyances. Create a new file called .vimrc in your home directory (~/.vimrc) and add the following.


set nocompatible
syntax on
filetype plugin indent on
set mouse=a

runtime! macros/matchit.vim

augroup myfiletypes
autocmd!
autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
augroup END

Now, all we have to do is download rails.vim. Head over to rails.vim and download the latest version. There should be a plugin directory and a doc directory in this archive. Extract it to your .vim folder and your all set. The last thing you have to do is enable the rails documentation.


vim
:helptags ~/.vim/doc

With rails.vim installed, you can launch vim from your project directory and have a lot of new functions. If you try :Rmodel user (which tab completes very nicely), it opens up app/models/user.rb. :Rcontroller blog will open up app/controllers/blog_controller.rb. Everything works just like you would expect it to. You can tab complete the commands and the filenames. If you don’t know what file your looking for, leave the filename off and start hitting tab. You’ll just cycle through all the models or controllers or views. :Rextract will take a currently highlighted section of your code, and automatically create a new partial file while replacing the current selection with the render :partial call. Also, if you move the cursor over another controller name or model name or anything similar and press gf, you will open up that file. It takes a little getting used to but it really works. For a completely list of everything that rails.vim can do, type :help rails. There’s a lot you can do.

Hope that helped out some people! Enjoy!

Posted in Linux, Ruby on Rails, Ubuntu, Web development | 10 Comments »

 
Follow

Get every new post delivered to your Inbox.