Skip to content

Instantly share code, notes, and snippets.

@zetter
zetter / atom.rb
Last active August 29, 2015 13:56 — forked from floehopper/atom.rb
class Atom
attr_reader :symbol
def initialize(symbol)
@symbol = symbol
end
def ==(other)
self.symbol == other.symbol
end
@zetter
zetter / enrolling.feature
Last active August 29, 2015 14:03
Enrolling in a course Cucumber feature
Feature: Enrolment
Scenario: Enrolling in a course
Given there is a course
And I am logged in as a learner
When I enrol on a course
Then the course should appear in 'my courses'
@zetter
zetter / enrolment_spec.rb
Last active August 29, 2015 14:03
Enrolment rspec feature spec
feature 'Enrolment' do
scenario 'Enrolling in a course' do
course = FactoryGirl.create(:course)
learner = FactoryGirl.create(:learner)
login_as learner
visit course_path(course)
find('.join').click
expect(page).to have_content('Thanks for joining!')
@zetter
zetter / deploy.sh
Created December 6, 2014 20:48
Deploying my personal site using s3cmd
#!/bin/bash
jekyll build
s3cmd sync -r --acl-public public/ s3://chriszetter.com/
class Hash
def hash_map()
result = self.inject({}) do |hash, (k, v)|
hash.merge(yield(k, v))
end
end
end
{:a => 1, :b => 2}.hash_map {|k,v| {k.to_s*2, v*2}} # => {"aa"=>2, "bb"=>4}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
#! /usr/bin/ruby
# Saves two random and contiguous cropped images from a larger image
# Written so an image that is too big can be displayed on a dual screen desktop
IMAGE_NAME = "file_small.png"
IMAGE_WIDTH, IMAGE_HEIGHT = IO.read(IMAGE_NAME)[0x10..0x18].unpack('NN')
# # For non-pngs:
# IMAGE_WIDTH, IMAGE_HEIGHT = [12304, 8605]
# Hacked from http://github.com/dball/zoomifier/blob/master/lib/zoomifier.rb
require 'fileutils'
require 'open-uri'
require 'rubygems'
require 'rmagick'
require 'rexml/document'
class Zoomify
TILESIZE = 256
@zetter
zetter / Bubble Free Click
Created March 26, 2011 20:39
jquery extension to register click events that won't bubble. Call instead of click(func).
jQuery.fn.preventDefaultClick = function(f) {
this.click(function(e){
f.call(this, e);
e.preventDefault();
});
return this;
}
@zetter
zetter / deconstruct.markdown
Created January 31, 2012 21:10
therubygame deconstruct by @czetter

therubygame deconstruct by @czetter

This is a deconstuction of matematikaadit's submission to therubygame challenge 5; 'Roman numerals. What are they good IV?'. The goal of the challenge is to take a string representing a roman numeral as input and return the integer that the numeral represents.

matematikaadit currently has the honour of the shortest (by character count) submission for this challenge. At first glance I didn't understand how it worked so I re-wrote and analyzed it until I did.

Making it readable

matematikaadit's original submission: