Skip to content

Instantly share code, notes, and snippets.

@nickboyce
nickboyce / gist:1814754
Created February 13, 2012 07:50
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
@nickboyce
nickboyce / youtube_style_ids.rb
Created February 15, 2012 11:36
Youtube-style IDs in Ruby
# courtesy of juliocapote (http://news.ycombinator.com/item?id=485423)
def generate_code(len = 5)
(1..len).map { (("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a)[rand(62)] }.join
end
describe "as_json method" do
subject { artwork.to_json }
# test the root object structure
it { should have_json_type(String).at_path("artist_id") }
it { should have_json_type(Array).at_path("available_sizes") }
# test a nested object
it { should have_json_type(Object).at_path("artist") }
it { should have_json_type(String).at_path("artist/id") }
Which is totally awesome.
describe "as_json method" do
subject { artwork.to_json }
# test the root object structure
it { should have_json_type(String).at_path("artist_id") }
it { should have_json_type(Array).at_path("available_sizes") }
# test a nested object
it { should have_json_type(Object).at_path("artist") }
it { should have_json_type(String).at_path("artist/id") }
it { should have_json_type(String).at_path("artist/slug") }
end
context "#index (GET /artworks.json)" do
# create 30 Artwork documents using FactoryGirl, and do a HTTP GET request on "/artworks.json"
before(:each) do
30.times { FactoryGirl.create(:artwork) }
get "/artworks.json"
end
describe "should list all artworks" do
# the request returns a variable called "response", which we can then make sure comes back as expected
it { response.should be_ok }
it { JSON.parse(response.body)["results"].should be_a_kind_of(Array) }
it "each artwork should have the correct structure" do
JSON.parse(response.body)["results"].each do |artwork|
artwork.keys.sort.should eq JSON.parse(FactoryGirl.create(:artwork).to_json).keys.sort
end
end
$("a").each(function(k,v) {
$(v).click(function() {
// do something here to load the content in dynamically
history.pushState(null, null, $(this).prop("href"));
return false;
});
});
$(window).bind('popstate', function(event) {
var filename = location.pathname.substr(location.pathname.lastIndexOf("/"));
if (filename.indexOf("page1") > 0) {
// go back to the page1 context
} else {
// go to the page2 context
}
});
s3cmd sync --exclude '.DS_Store' --exclude '.git/*' --exclude-from '.gitgnore' --add-header=Expires:max-age=604800 --acl-public ./ s3://the_bucket_name