Deleting cached javascripts and stylesheets with Capistrano

In order to speed up my rails application I added caching to both my javascript includes and stylesheet includes. It does the speed the webpage up, but rails does not regenerate these files on a subsequent deploy which makes it hard to add new functionality!!

To get around this problem I updated my cap deploy files to delete the cached files on deploy by attaching the following snippet at the bottom of my config/deploy.rb file:

namespace :deploy do
  desc "Deletes all.js and all.css"
  task :delete_cached_files, :roles => :web do
    all_js = File.join(current_path,'public','javascripts', 'all.js')
    all_css = File.join(current_path,'public','stylesheets', 'all.css')
    run "rm #{all_js} #{all_css}"
  end
end

after "deploy", "deploy:delete_cached_files"

Finding your method in Ruby

The dynamic nature of ruby can sometimes make it difficult to track down the location of a method in your code, but it’s quite simple with the console. Just call method on the object in question passing in the method you are trying to locate as a symbol.

For instance, if you want to find the implementation of the method days in the Fixnum class just execute the following

30.method(:days)

And it will return

#<Method: Fixnum(ActiveSupport::CoreExtensions::Numeric::Time)#days>

You can see that our method can be found in ActiveSupport::CoreExtensions::Numeric::Time.

And on a side note, if you want to find out your inheritance hierarchy just send the ancestors method to your class like so

Array.ancestors

Magit and Emacs

Magit was not working properly with my carbonized version of emacs. After poking around a bit, I found out that emacs was unable to locate git in my path. I fixed this by adding the following lines to my emacs start up file

(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin")) 
(setq exec-path (append exec-path '("/usr/local/bin")))

On a side note, if you are using the excellent emacs starter kit you should place all of your custom start up code in ~/.emacs.d/username.el

Getting git to ignore emacs auto save files

I have recently made the switch from TextMate back to my old friend emacs. There are things that I really love about emacs (rinari and flymake come to mind) and there are some minor annoyances like auto save files.

And with my switch to git its made it even more irritating!! But thankfully, it’s fairly easy to have git ignore these files.

First, you need to create a global .gitignore file that contains the following:

auto-save-list
custom.el
url/
.org-id-locations
\#*
org-mode-config.el
*~
.#*
\#*\#
*.log
.DS_Store
org-clock-save.el
emacs-config.el

And the final step is to make git aware of your global ignore file like so

git config --global core.excludesfile ~/.gitignore

Note: my .gitignore file is in my home directory, but you can place it anywhere.

And that’s all there is to it!

Update:I had excluded the config and that doesn’t work too well with rails. I removed it from the list of exclude files.

Update:Check out github’s collection of .gitignore files https://github.com/github/gitignore

Sherlock Holmes And The Case of Slow Broadband

For the past couple of my months my Internet connection has gotten progressively S-L-O-W-E-R. In the process of hunting down the issue I learned a couple new tricks that I wanted to share.

  • SPEEDTEST.NET is great, but make sure you verify the slowness with your ISP’s speed testing tools. They aren’t going to believe it’s an issue unless you use the ISPs reference site.
  • M-Labs has some great tools to help you diagnose Internet connection issues.
  • Part of your issue might be due to your ISP’s poor perfoming DNS servers. You should investigate alternative DNS servers. (Look for a future post about this, but in the meantime take a look at this to wet your appetite.)
  • Most cable modems contain an embedded web server that can provide you with some good information. It’s usually on http://192.168.100.1. Refer to this post to verify your signal/modem are within spec.
  • Your ISP might surprise you! After calling Time Warner’s 1-800 number I was able to quickly speak to a rep who worked with me to determine the issue without the use of a script. Upon determining it was an onsite issue, he quickly dispatched a tech to investigate the issue.

In the end my issue turned out to be my modem. He swapped out my Ambit modem for an Arris one which I was told does a much better job of holding onto signal. My Internet speeds have jumped from 0.3 Mb/s to 30 Mb/s!!

Mail.app and Gmail IMAP

I have never thought Gmail’s IMAP interface worked quite the way I thought it should, so I spent some time today trying to get some answers.

My first issue was with unread messages. I typically use the gmail web interface during the day while I am at work and use Apple mail whenever I am using my mac. Unfortunately, ¬†when I get home at the day Apple Mail never picks up the fact that I have been reading my emails during the day. After poking around a bit I found this post, which says the issue is caused by Gmail’s lack of support for sending the optional untagged FETCH responses to connected clients.

One work around is to uncheck the “Use IDLE command if the server supports it” under Preferences -> Accounts -> Advanced. Note, that by unchecking this box, you will no longer have push email.

The second issue was with the behavior of the delete button. By default, Gmail IMAP will archive messages when you delete them. I usually find myself wanting to delete rather than archive. One of the comment’s in this post details how to fix the issue. Basically you want to

  • Select the [Gmail]->Trash folder
  • From the menu select Mailbox -> Use this mailbox for -> Trash.

You can also do the same thing for the junk, sent, and draft folder.

Getting script/console to log to STDOUT

I just started working on a personal rails project and was shocked to find out that rails doesn’t log messages to STDOUT. Digging through a project at work I noticed that some one added the following to the end of config/environment/development.rb. It’s really a great convenience!

config.logger = Logger.new(STDOUT)
config.logger.level = Logger::INFO

Your Netflix keys have been hacked!

I just fired up my Samsung DB-P2550 bluray player and I was greeted with a message saying “Your Netflix keys have been hacked”. Doh!

After speaking with both a Netflix rep and a Samsung rep, I ended up resetting my player by holding down on FF for 10 seconds after I pressed power. At which point it ended up asking me my preferred language. All I had to do after that was reactivate my Samsung player and I was good to go!

Metered Broadband in San Antonio

Time warner just announced that their metered broadband experiment in Beaumont, TX was a success and they are planning to roll it out in Rochester, NY; and Greensboro, NC; Austin, TX; and San Antonio, TX!!! To make things worse AT&T is matching Time Warner’s metered broadband rollout market for market.

As you can guess, there is a huge outrage about this in San Antonio. We will be paying more money for the same service we receive today. Time Warner says they need to do this to upgrade their infrastructure and to redistribute their costs according to usage. But, I am guessing this is an attempt to get a piece of revenue back from streaming video sites like Hulu and Netflix as well as VOIP providers.

This move seems pretty typical of corporate America. Instead of focus on keeping customers through innovative new products and services, they are focusing on finding new ways to charge us even more for the same service we receive to day.

President Obama is a big supporter of Net Neutrality and says that he is going to appoint FCC commissioners that support open Internet principles. Hopefully, metered broadband will fall under this category as well!

In the meantime, I am looking at getting a Asus WL500G Premium and installing Tomato. It has some really cool looking bandwidth monitoring!

Here is a good blog posting about it.
This is Time Warners official response.