After hearing all about Brightkite from Brandice and Colin, I decided to take the plunge and try out the service a few weeks ago. In the time since, I’ve become addicted to the service, and I’m constantly amazed at how well thought out the site is. One thing that really bugged me, though, is that Brightkite doesn’t work with Verizon text messages. After being initially disheartened, I found getting around the issue to be pretty easy: instead of text messages, I used PIX messages.
If you take a look at Brightkite’s SMS Guide when logged into the service, you’ll notice a email under “Post a photo to a place.” This is the email you’ll be sending your updates to. To use any of the mobile commands (PDF) with Verizon, just send a PIX message to the email address without a photo attached. Put your command in the “text” field, send the message, and you should be good to go.
A word of caution: if you don’t have unlimited picture messaging, this method may end up being very costly. I’m not sure if Verizon still charges their PIX rate for messages without pictures, but if they do, make sure you’re not going over your allotted number of messages.
Hopefully, Verizon will fix whatever issue is breaking the Brightkite integration soon, so we don’t have to continue to hack around the problem. In the meantime, however, this method should continue to work; I haven’t had any issues with it thus far.
I never thought I’d actually get to this point, but, today, I am releasing a complete ground-up reworking of my site. With Ruby on Rails as a starting point, I was able to develop my very own content management system, and it is now powering everything here (with the help of a few plugins). I’m also excited to have a brand new design up, and it’s one I really have grown to enjoy. Read on for more details on the specifics of the new site.
Ever since I started using Twitter, I always used a stunning picture of the Crab Nebula as my background. When I started redesigning my site, I used the photo as a placeholder, but after a while it stopped being a placeholder and started driving the rest of the design, so I decided to keep it. The colors in the layout were directly influenced by the image: nearly every color comes directly from the Crab Nebula photo.
One thing I attempted with this was to not hold myself to the notion that there has to be a sidebar on every page. If you take a look at my About and Work pages, you can see where I switched things up. Personally, I think this helps to make it feel a little less like a blog, something I was definitely aiming for.
Even though I’m launching the new design today, there’s still quite a bit of refining for me to do. For one, the notebook page is pretty cluttered, so I really need to go through and organize that a lot better. In addition, several people I’ve shown the site to have mentioned that the header is a bit awkward; having the navigation attached and the title detached throws them off. I’m definitely going to need to find a better way to have that set up.
Developing the site is something I really enjoyed, and it allowed me to try a bunch of things I’ve been thinking of for a while. The site is built using Ruby on Rails, several plugins, and a whole lot of my own code.
One thing I’m proud of on the site is that every single page is cached. This way, things stay speedy, and the load on the server is lessened. Adding caching in Rails is really easy, and if you’re looking to do it yourself, you’ll probably want to check out this Rails Envy tutorial as well some Railscasts episodes.
For the server setup, I originally was planning to use Dreamhost and Phusion Passenger, but after using it for a bit, I felt like I needed a little more freedom, so I ended up buying a VPS from Slicehost. So far, I’ve been thrilled with Slicehost’s service and performance, and I’m definitely considering moving more projects over to them. As far as the technical side of things, I’m still using Passenger to run the site, though I might test out using Mongrel to see if that’s any faster.
I’m really excited about the new site, but I’m not done yet. Like I mentioned before, I still have some design tweaking to do, but I also have a lot I want to implement under the hood. There are bound to be issues that come up, and I’ll be hopefully fixing them as fast as possible, but if you run into something, please let me know.
I would love to hear any feedback (negative or positive) you have about the new site, so please leave a comment below!
def markdown(str) RDiscount.new(str).to_html end
(Note: I’m using the RDiscount library instead of BlueCloth, for reasons discussed here)
However, what if I wanted to add a “Read more” link at the end of the entry excerpt? I’d have to do something like this:
<%= markdown entry.excerpt + link_to("Read more", entry_path(entry)) %>
This way didn’t really appeal to me. What I really wanted to do was just pass a Ruby block, like this:
<% markdown do %> <%= entry.excerpt %> <%= link_to "Read more", entry_path(entry) %> <% end %>
In order to do this, I just had to modify my
markdown helper a bit:
def markdown(str='', &block) str = capture(&block) if block_given? result = RDiscount.new(str).to_html block_given? ? concat(result, block.binding) : result end
And, just like that, I can now pass blocks to my Markdown helper.
I put together a quick video showing where I’m at with the new design and backend for KyleSlattery.com. Take a look, and let me know what you think!
While building the Viddler Facebook application, I needed to create a pagination tool that worked just like Facebook’s. After looking at their HTML and their logic of what pages to display, I came up with one, which I’m releasing for anyone to use. The function takes 5 arguments, in the following order:
- $base_path: The base path for pagination. For instance, if /videos/4/ was page 4, $base_path would be “/videos”
- $cur_page: The current page number
- $total_items: The total number of items on the page
- $per_page: The number of items that are displayed on each page
- $footer_bar: If set to “true” this does not include the “Displaying items 1-5 of 10” text, and styles it as a footer paginator, instead of a header paginator.
- $name: What you’re paginating. This shows up as “Displaying $items 5-10 of 40”
Here’s an example:
<?php echo paginator('/videos', 2, 44, 5, false, 'items'); ?>
And here’s what it would look like:
You can download the source here. Hopefully this helps someone!
Sometimes, I wonder how I ever get anything productive done up here.
Nested resources are awesome. If you want to have a blog with entries that have comments, the resources are dead simple:
map.resources :entries do |entry| entry.resources :comments end
Awesome, now you have set up paths like
entries/3/comments/ using an EntriesController and a CommentsController. What if, however, you want to have a base comments resource (
/comments/) to show all comments? You already have a CommentsController, and it doesn’t do what you want. To solve this, I do something like this:
map.resources :entries do |entry| entry.resources :comments, :controller => 'entries/comments' end map.resources :comments
Now, you have all your routes set up, and you can have separate controllers, Entries::CommentsController (which lives in controllers/entries/comments_controller.rb) and CommentsController. Just remember when generating the nested controller to use the proper name, like so:
ruby script/generate controller entries/comments
Problem: Firefox 3 (which was released today) does not work with Firebug. Firebug’s website is down.
Solution: I found a developer build of Firebug here that seems to work pretty well. Hopefully the actual developers of Firebug can get their site up soon, but in the meantime, this seems to be working pretty well.
So far, I’m liking Firefox 3, and in the next couple of days, I’ll be posting an entry with my observations and thoughts.
After my friend Paul asked me to text him updates from a Euro 2008 game while he was at work, I came up with the idea to set up a twitter bot that posted updates from Soccernet’s gamecasts. After a couple hours of work, using Hpricot and the Twitter gem, I was able to build a Ruby script that worked pretty well. I’m planning on posting a complete post on how I did it, but first I want to work some of the kinks out. There are three twitter accounts you can follow if you’re interested:
- @euro2008cup - All updates from the gamecast (about one post per minute in the game). Tweets are shortened with a link to the full update.
- @euro2008scores - Only updates from the gamecast that are marked as “alerts” (goals, for the most part). Like @euro2008cup, updates are shortened.
- @euro2008sms - This has the same updates as @euro2008scores, but updates longer than 140 characters span across multiple tweets. This is best if you want to follow on your phone, as you’ll get the full update instead of having to click on a link.
Hopefully these will help someone out. Like, I said, I’ll be posting a how to on making your own twitter bot and screen scraper, so keep an eye out for that.
A couple weeks ago, I received my copy of Advanced Rails Recipes by Mike Clark (and others), and so far, I’ve really been enjoying it. The first book by Chad Fowler was easily my favorite Rails book at the time, and the new edition has definitely continued the trend. I’ve always learned best from examples, and the recipes in the book are all top-notch, real world scenarios that can be quickly and easily applied to your application. Already, I’ve used many of them while working on my site, and below are a few of my favorites.
- Respond To Custom Formats
- Freshen Up Your Models with Scope
- Handle Multiple Models in One Form
- Upload Images with Thumbnails
- Send E-mail via Gmail
- Preserve Files Between Deployments
- Give Users Their Own Subdomain
I definitely recommend the book to any Rails developer, new or old, because the book truly has something for everyone.
Deploying Ruby on Rails has always been a pain, even with tools like Mongrel and Capistrano. On shared hosting, it’s nearly impossible. A little while ago, I noticed a project called Phusion Passenger (aka mod_rails), which sought to make deploying as easy as uploading your application to your webhost. A few days ago, Dreamhost (my host) announced on their blog that Phusion Passenger was available on their servers. Naturally, I took some time to play around with it, and so far I’ve been extremely impressed. I threw together a quick app using Viddler.rb and deployed it to Dreamhost (you can see it here). Here’s a quick guide on how to deploy to Dreamhost yourself using mod_rails.
Getting set up
The first thing to do is to set up your domain or subdomain to use Passenger. Just go to the Manage Domains page on the DH web panel, and either create a new domain or edit an existing one. Check the “Ruby on Rails Passenger (mod_rails)?” checkbox and set the web directory to where the public directory of your app will be. Below is a screenshot of my settings for viddler.fidgeting.net.
Next, you need to create your database, so just go into the Manage MySQL section of the panel. Create your database, which should be named as a production database. In my case, it was viddler_production. Then, make sure to change your database.yml to reflect the database you just created.
Uploading and running your application
Before uploading, make sure the first line of your public/dispatch.fcgi has the correct path to ruby on Dreamhost (which is /usr/bin/ruby). Then all you need to do is upload the files to Dreamhost and go to the domain. That’s it—your app is now completely functional. Amazing, huh?
If you need to first run migrations, you can do that from SSH with this command:
RAILS_ENV=production rake db:migrate
If you need to restart your application (anytime you change any files), just run the following command via SSH:
Getting Gems to work on Dreamhost
Since Dreamhost is a shared host, you can’t directly install gems on the server. Dreamhost’s wiki has a lot of information on different ways to get gems working, but they are all fairly involved, and I couldn’t get any of them to work. The way I did it was by unpacking the gems into vendor/gems by using the “gem unpack” command:
gem unpack <GEM NAME>
I’m sure there are better ways to do it, but this method worked perfectly for me.
Like I said at the beginning, I’m very impressed with Passenger, and so far I haven’t noticed any issues. The total time for me to deploy was about 20 minutes: way faster than with Mongrel or FastCGI. It’s definitely awesome to see a host as large as Dreamhost using this, and hopefully soon more will follow suit.
This semester, I took a class called “Computational Physics,” where we simulated various physical properties. For my final project, I wrote a simulation of the Solar System, and in the process, I wrote a “Vector” class for Java. It allows you to do 3 dimensional vector math operations pretty easily, like in the examples below:
// Create vector <1,2,3> Vector v1 = new Vector(1,2,3); // Unit Vector <0.27, 0.53, 0.80> Vector unit = v1.getUnitVector(); // Magnitude (3.74) double mag = v1.getMagnitude(); // Get each value double x = v1.getX(); // 1 double y = v1.getY(); // 2 double z = v1.getZ(); // 3 // Multiply v1 by scalar (<5,10,15>) Vector scalarM = v1.scalarMult(5); // Create vector <-4,-5,-6> Vector v2 = new Vector(-4,-5,6); // Add v1 and v2 (<-3,-3,-3>) Vector add = v1.add(v2); // Subtract v2 from v1 (<5, 7, 9>) Vector sub = v1.minus(v2); // Dot v1 and v2 (-32) Double dot = v1.dot(v2); // Cross v1 and v2 (<3,-6,3>) Vector cross = v1.cross(v2);
I’ve never really used Java before, so my code might not be the best, but it gets the job done. If you want to download the Vector class, here’s the link. If this comes in handy to anyone, I’d really appreciate it if you left a comment!