Skip to content

Instantly share code, notes, and snippets.

Chris Zetter zetter

Block or report user

Report or block zetter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View atom.rb
class Atom
attr_reader :symbol
def initialize(symbol)
@symbol = symbol
end
def ==(other)
self.symbol == other.symbol
end
@zetter
zetter / enrolment_spec.rb
Last active Aug 29, 2015
Enrolment rspec feature spec
View enrolment_spec.rb
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 / enrolling.feature
Last active Aug 29, 2015
Enrolling in a course Cucumber feature
View enrolling.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 / deploy.sh
Created Dec 6, 2014
Deploying my personal site using s3cmd
View deploy.sh
#!/bin/bash
jekyll build
s3cmd sync -r --acl-public public/ s3://chriszetter.com/
View gist:295978
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}
View Cycle through colours using jquery
<!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">
View random slicer
#! /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]
View Unzoomify
# 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 Mar 26, 2011
jquery extension to register click events that won't bubble. Call instead of click(func).
View Bubble Free Click
jQuery.fn.preventDefaultClick = function(f) {
this.click(function(e){
f.call(this, e);
e.preventDefault();
});
return this;
}
@zetter
zetter / deconstruct.markdown
Created Jan 31, 2012
therubygame deconstruct by @czetter
View deconstruct.markdown

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:

You can’t perform that action at this time.