February 27, 2009
I recently revisited the problem of detecting browser time zone because I wanted to try the new time zone functionality in Rails 2.1. I found this post from Dave Johnson. To my disappointment this was the same solution Spongecell used in the personal calendar 3 years ago.
I wanted a simpler solution: one that doesn’t require a js cookie library, nor around filters, nor a UI with a combo box with 100s of time zone choices.
The solution presented is to send browser info using jquery and then storing the time zone in the session for use in all subsequent requests.
in the view (this is haml), this can be in your layout on all pages:
- unless @time_zone
= javascript_tag "$.get('/controller/time_zone',
'offset_minutes':(-1 * (new Date()).getTimezoneOffset())})"
in the controller:
before_filter :init_time_zone
#sets the time zone for this request if a session time zone exists
#if it doesn't the default is UTC
def init_time_zone
@time_zone = ActiveSupport::TimeZone[session[:time_zone_name]] if session[:time_zone_name]
Time.zone = @time_zone.name if @time_zone
end
#this receives browser info from a jquery request and stores
#time zone info in the session
def time_zone
offset_seconds = params[:offset_minutes].to_i * 60
@time_zone = ActiveSupport::TimeZone[offset_seconds]
@time_zone = ActiveSupport::TimeZone["UTC"] unless @time_zone
session[:time_zone_name] = @time_zone.name if @time_zone
render :text => "success"
end
in the formatter:
def format_time(t)
return "" unless t
return t.in_time_zone.strftime('%Y-%m-%d %H:%M:%S %Z')
end
Look how simple that is! I choose to default the time zone to UTC if one cannot be determined on the first attempt. Now the formatter will output all the UTC times you have in your db or anywhere in the user’s browser’s time zone.
If there is a better solution in Rails please let me know. We ‘ll see if this solution works for daylight saving time.
3 Comments |
Uncategorized |
Permalink
Posted by Chris Hobbs
January 30, 2009

Obama Day was caching day!
Obama day was sort of intense! Not only did Aretha Franklin have a sweet hat, but all the internet traffic on CNN Live put the hurt on old skool Spongecell Promote. Chris saved the day by quickly page caching the content that was in high demand. So basically some files were copied and everyone was happy (except maybe Texas?)
This trick is super obvi, but hella useful, yo. But, <tear>, its not a permanent fix. Alas, not every day can be Obama Day ! So I set out to fix this permanently. We need to page cache for one customer who always sends the same request, expire the page when the data changes, and action cache for everyone else who is not logged in.
So I wrote a tiny little conditional page cache plugin to let you choose your caching type at runtime. You want to page cache giraffe 1, action cache giraffe 2 when they are green and serve everything else straight up.
class PictureController
conditionally_cache :giraffe
def page_cache?; @giraffe == 1; end
def action_cache?; @giraffe = 2 && @giraffe_color = 'blue'; end
def giraffe
@giraffe = blah_blah
end
end
To clarify the temporary caching trick:
Suppose you have: http://snowgiraffe.com/pictures/giraffe/1.html
Then you simply move the file to:
#{RAILS_ROOT}/public/pictures/giraffe/1.html
1 Comment |
Technology, performance |
Permalink
Posted by blythedunham
November 19, 2008

from CyberCrime and Doing Time
“The website sergej-grienko.com is in Russia and doesn’t run Apache or IIS or any other common webserver. Its running a webserver called “nginx” (Pronounced Engine-X). That’s a huge negative right there. Many webservers that host malware are using this webserver type.”
Spongecell and Engine Yard use NGINX but I think it’s a huge positive! We use it for analytics reporting in addition to normal mongrel load balancing. We’ve load tested nginx on a single slice being able to handle close to 10,000 requests per second. Perhaps we like it for the same reasons the criminals do: it performs.
Leave a Comment » |
Uncategorized |
Permalink
Posted by Chris Hobbs
November 17, 2008
I tried out Facebook Connect with Rails recently. The result is Zack N Miri.
Figuring out all the details wasn’t super straightforward. Essentially I took the jogging php example from Facebook and combined it with the Facebooker Rails plugin. You can check out the code at Github.
Who wants to get some milk with Zack?
17 Comments |
Uncategorized |
Permalink
Posted by Chris Hobbs
October 28, 2008

How annoying, Apple has disabled the power tools in Screen Sharing that are mentioned in this great article. This comes in a recent update to security or system or something. I got around the problem by downgrading my Screen Sharing to 1.0 which I found on an old computer in the office. The app is dated 10/2007.
I use Screen Sharing to connect to my mini at home when I am at the office or on the road and need to access media. I’ve never had to connect to my work computer because I keep that synced with imap, idisk, svn and git.
Leave a Comment » |
Uncategorized |
Permalink
Posted by Chris Hobbs
October 1, 2008
I did some research to see exactly how strong encryption is if you use Apple’s FileVault. (Windows has BitLocker).
1. If your laptop is stolen while powered on, if someone has the right hardware they can read your ram and steal all vault passwords. This is unlikely but possible.
2. If your laptop is off they can brute force your password. For a simple 6 character password this would take ~1000 EC2 computing days and cost ~$5,000. A 7 character password would cost $40,000 to break and 8 character $2.5 million. Use lowercase, uppercase, numbers and symbols for the best password protection. You must also use secure virtual memory or passwords will be written to disk.
If you don’t use FileVault nor BitLocker and your laptop is stolen then your bank accounts, your email, your passwords and you are compromised.
Leave a Comment » |
Uncategorized |
Permalink
Posted by Chris Hobbs
September 4, 2008

I’m in Berlin right now getting ready to give a presentation on E-Commerce. I’ll be comparing a few credit card payment solutions for rails. Europe has stricter banking rules than in the U.S but I’m hoping I can help some people out.
I created an example site, Rails Vendor, to demonstrate payment options and show some code. You can also see an example of one of our new Rich Media Ads picturing DHH himself.

Leave a Comment » |
Uncategorized |
Permalink
Posted by Chris Hobbs
August 27, 2008
I tested content delivery to a server we have at Engine Yard in Sacramento.

We are testing CDN’s for our flash delivery so I tested with a 160kb swf file. Media Temple doesn’t claim to be a CDN but I tested it anyways on it’s budget grid server. Panther and Edgecast are CDNs. I did all testing using apache bench from a slice in Engine Yard cluster EY01. The Intranet test was with content from a slice in their cluster EY02. This was a baseline since the servers are probably only meters from each other. S3’s latency is a big reason we’re looking for a good CDN.
.mac was the surprise contender and they only cost $100 a year. Perhaps we were just geographically lucky. They limit to 100gb a month and we hope to be serving more flash than that so .mac is not a realistic solution. Their consumer agreement is not sufficient as well but in reality neither is S3’s.
I tested 10,000 requests with a concurrency of 10. I repeated the ~4 minute test to make sure numbers were settled. The huge bias was location and perhaps time of day. Tests were done at noon on 8/27/08.
Conclusion: the two CDNs performed better than the non-CDN delivery. This data isn’t fair nor significant enough to rule one CDN better than the other.
3 Comments |
Technology, performance |
Permalink
Posted by Chris Hobbs
June 7, 2008
I was trolling github to see what kind of calendar projects were out there and found calendar_helper. It looks decent. I would probably use it if I needed to display a simple calendar.

For displaying a rich calendar in html the best solution is of course to use Spongecell’s Monthly Online Calendar:

These calendars can easily be created at Spongecell by creating some events and then getting code for your site. For a dynamic calendar built into your web application these calendars can be modified and created using the Spongecell API. A good open source example of this can be found at Spongewolf.
Github is my new favorite social network. My friends are defined by people watching my projects and the projects I am watching. There’s a lot less trashiness and nudity than on other social networks I try to avoid such as MySpace and LinkedIn.
Leave a Comment » |
Technology |
Permalink
Posted by Chris Hobbs
April 29, 2008
Here is more or less what I did to install git on OS X and on Media Temple. Newer versions of the below files will exist by the time you are reading this i.e. now.
I got the below mostly from http://dysinger.net/2007/12/30/installing-git-on-mac-os-x-105-leopard/
# GPG (if you didn’t have it already)
curl ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-1.4.7.tar.bz2 | tar xj
cd gnupg-1.4.7
./configure
make
sudo make install
cd ..
# GetText
curl http://mirrors.usc.edu/pub/gnu/gettext/gettext-0.17.tar.gz | tar xz
cd gettext-0.17
./configure
make
sudo make install
cd ..
# GIT
curl http://kernel.org/pub/software/scm/git/git-1.5.4.4.tar.bz2 | tar xj
cd git-1.5.4.4
./configure
make
sudo make install
cd ..
curl http://www.kernel.org/pub/software/scm/git/git-manpages-1.5.4.4.tar.bz2 |
sudo tar xj -C /usr/local/share/man
# Setup GIT
git config –global user.name ‘My Name’
git config –global user.email me@mydomain.net
#can you see two dashes before “global”?
5 Comments |
Uncategorized |
Permalink
Posted by Chris Hobbs