Skip to content

Instantly share code, notes, and snippets.

View joelturnbull's full-sized avatar

Joel Turnbull joelturnbull

View GitHub Profile
@joelturnbull
joelturnbull / gist:930327
Created April 20, 2011 04:13
double insert:into:
quantityOfIngredient: theIngredient
"return the accumulated quantity of an ingredient across all recipes"
^ recipes inject: 0 into: [ :totalQuantity :aRecipe |
aRecipe ingredients inject: totalQuantity into: [ :theTotalQuantity :anIngredient |
( theIngredient = anIngredient )
ifTrue: [ theTotalQuantity + anIngredient quantity ]
ifFalse: [ theTotalQuantity ]
]
^ (integer \\ 15 = 0) ifTrue: [ 'FizzBuzz' ] ifFalse: [
(integer \\ 3 = 0) ifTrue: [ 'Fizz' ] ifFalse: [
(integer \\ 5 = 0) ifTrue: [ 'Buzz' ] ifFalse: [ integer ]
@joelturnbull
joelturnbull / gist:1024824
Created June 14, 2011 12:49
East-Facing StarMap Rendering
StarMap>>renderContentOn: canvas
self generateStarCollection renderStarsOn: canvas.
StarCollection>>renderStarsOn: canvas
stars do: [ :aStar | aStar renderHtmlOn: canvas ].
Star>>renderHtmlOn: canvas
@joelturnbull
joelturnbull / gist:1026321
Created June 15, 2011 01:37
East-Facing StarMap Rendering
StarMap>>renderContentOn: html
self generateStarCollection renderStarsOn: html.
StarCollection>>renderStarsOn: html
stars do: [ :aStar | aStar renderHtmlOn: html ].
Star>>renderHtmlOn: html
@joelturnbull
joelturnbull / gist:1032674
Created June 18, 2011 00:51
Triangle Ruby Koan Solution
# The sum of the lengths of any two sides of a triangle always exceeds the length of the third side
raise TriangleError if ( vertices.inject(0) { |sum,vertex| sum += vertex } - vertices.max <= vertices.max )
return :equilateral if ( vertices.uniq.size == 1 )
return :isosceles if ( vertices.uniq.size == 2 )
return :scalene
@joelturnbull
joelturnbull / gist:1587101
Created January 10, 2012 05:07
clojure no-no
(#(#(if (pos? %2) (recur (pop %1) (dec %2)) (first %1)) (flatten %1) %2) '(4 5 6 7) 2 ))
@joelturnbull
joelturnbull / jquerytest.cljs
Created January 17, 2012 02:20 — forked from ryancrum/jquerytest.cljs
How to use jQuery from ClojureScript
(ns jquerytest.core)
(def jquery (js* "$"))
(jquery
(fn []
(-> (jquery "div.meat")
(.html "This is a test.")
(.append "<div>Look here!</div>"))))
@joelturnbull
joelturnbull / generate_email_button_html.rb
Created July 9, 2012 03:54
Adding a Share by Email Button to Your Tumblr Posts
require 'open-uri'
def main
image_url = "https://s3.amazonaws.com/gaslight-blog/email_button.png"
subject = "{Title}"
body = <<-eos
Check out this article...
{Title} <{ShortURL}>
eos
@joelturnbull
joelturnbull / 1.feature
Created September 11, 2012 13:44
snippets for cucumber regex article
When I click "Edit"
@joelturnbull
joelturnbull / gist:4634948
Last active December 11, 2015 17:29
Implementation of Party initializers deferring to a Designated Initializer
// Implementation of Party initializers deferring to a Designated Initializer
#import "Party.h"
@implementation Party
-(Party*)initWithLocation:(NSString*)location {
return [self initWithLocation: location date:[self defaultDate] attendees:[self defaultAttendees]];
};