Skip to content

Instantly share code, notes, and snippets.

@jch
jch / jquery.setCurrentClassOnEvent.js
Created August 11, 2010 18:36
jquery.setCurrentClassOnEvent.js
// For a group of elements, sets 'className' on an element when 'evt'
// is triggered, and removes 'className' from all it's
// siblings. Useful for highlighting a selection within a list of
// choices.
//
// $('ul#my_list li').setCurrentClassOnEvent('click', 'current');
// <ul id="my_list">
// <li class="current">Chocolate</li> <!-- click adds 'current' class -->
// <li>Vanilla<li>
// <li>Strawberry</li>
@jch
jch / tail.rb
Created October 11, 2010 18:39
nspipe example
framework 'cocoa'
outpipe = NSPipe.pipe
task = NSTask.alloc.init
task.setLaunchPath '/usr/bin/tail'
task.setArguments %w(-f -n10 /Users/jch/projects/pharmmd/log/wendy.log)
task.setStandardOutput outpipe
file = outpipe.fileHandleForReading
@jch
jch / html5-navigations.html
Created December 14, 2010 05:00
sample navigations created with pure html5
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="reset-min.css" type="text/css" media="screen" title="no title" charset="utf-8">
<style type='text/css'>
html {
background-color: #cacaca;
}
.box {
@jch
jch / README.md
Created May 19, 2011 21:02
Rails Backup

Rails Backup

Add backup support to a Rails project with the 'backup' gem

Gemfile

gem 'backup', '3.0.15'
gem 'fog', '0.7.0'  # used by backup for s3 uploads, but not a dependency

Generate and Edit Config

Rubies to Prevent DevOps Mayhem

<iframe width="640" height="390" src="http://www.youtube.com/embed/vtP-S9OS0o0" frameborder="0" allowfullscreen></iframe>

You've just written a masterpiece of a web app. It's fun, it's viral, and it's useful. It's clearly going to be "Sliced Bread 2.0". But what comes next is a series of unforeseen headaches. You'll outgrow your shared hosting and need to get on cloud services. A late night hack session will leave you sleep deprived, and you'll accidentally drop your production database instead of your staging database. Once you serve up a handful of error pages, your

2006 500 sel
title - clean
#num owners
side airbags?
why selling - company car. maintained through the company.
last mechanic - front windshield. oil change. air filter.
get back at 5pm.
@jch
jch / chargify_mess.rb
Created June 20, 2011 17:37
chargify_mess.rb
def add_to_chargify(user, credit_card_attributes)
credit_card_attributes.symbolize_keys!
customer = Chargify::Customer.create({
:first_name => credit_card_attributes[:first_name],
:last_name => credit_card_attributes[:last_name],
:email => user.email,
:reference => self.id # one payer per account, so Account is customer_reference, not User
})
# TODO: major error handling needed here...
puts customer.errors.full_messages
@jch
jch / route_constraints.rb
Created October 22, 2011 18:26
testing route constraints
# I was upgrading an old rails 2 app to rails 3 and noticed that
# http://rails.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html
# was deprecated. I was using this in the controllers to verify that an action had to be triggered
# by an xhr request
# I am unable to test it from a functional test b/c it doesn't look like functional tests
# go through routes. However, it works fine in the app. I could put this in an integration test,
# but I'm wonder if it makes more sense to have some way of testing the route constraint in
# a local way.
/* **She grows old and feeble** */
//...But she would always have to return back to her dull world of chores and grown-ups.
return function() {
// And her latest story would be filled with wonder
latestStory = adventures[adventures.length - 1];
// But time is a bitch...
setInterval(function() {
// and our dear princess can't help but forget her adventures,
@jch
jch / skip3.rb
Created October 26, 2011 19:04
skip every 3 numbers in a list
(1..18).step(3) {|i| puts (i..i+2).to_a.inspect if i.even?}
# Breaking it down:
# #step(3) yields every 3rd element in the range, so you start with 1, 4, 7, 10...
# in the block, we want to print lists of 3's, so we do (i..i+2).to_a. Giving us: [1,2,3], [4,5,6], [7,8,9]...
# now we want to skip every other list of 3, so we only print if i is even.