Skip to content

Instantly share code, notes, and snippets.

@codeincontext
codeincontext / gist:6665176
Last active January 11, 2016 00:22
Programming Elixir binary chop exercise
defmodule Chop do
def guess(actual, a..b) do
mid = midpoint(a, b)
IO.puts "Is it #{mid}?"
compare actual, a..b, mid
end
defp compare(actual, _.._, current) when current == actual do
IO.puts "Got it! It was #{actual}"
@codeincontext
codeincontext / fizzbuzz.ex
Created September 21, 2013 15:45
My solution to the pragprog fizzbuzz exercise
fizz_or_buzz = fn
(0, 0, _) -> "FizzBuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, x) -> "#{x}"
end
Enum.each 10..16, fn n ->
IO.puts fizz_or_buzz.(rem(n, 3), rem(n, 5), n)
end
@codeincontext
codeincontext / glitchr.rb
Created August 16, 2013 11:02
Glitch art generator
input_file = 'input.jpg'
output_file = 'output.jpg'
def mutate(line)
line[rand(line.length-1)] = "0"
end
File.open(input_file,'r') do |input|
File.open(output_file,'w') do |output|
while line = input.gets
@codeincontext
codeincontext / gist:5559784
Created May 11, 2013 12:04
Genius trick to get an inner drop shadow on a UILabel
label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.55];
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(0.0,-1.0);
@codeincontext
codeincontext / Podfile
Created May 9, 2013 12:25
The CocoaPods I'm using in this current iOS project. Check them out, because they're all super useful
platform :ios, '5.0'
pod 'AFNetworking', '1.1.0'
pod 'AdMob', '6.2.1'
pod 'HockeySDK', '3.0.0'
pod 'Facebook-iOS-SDK', '3.2.1'
pod 'StyledPageControl', '1.0'
pod 'BSKeyboardControls', '2.0'
pod 'GoogleAnalytics-iOS-SDK', '2.0beta4'
pod 'AFHTTPRequestOperationLogger', '0.10.0'
@codeincontext
codeincontext / gist:5404572
Created April 17, 2013 14:06
Output git log as markdown list - for hockeyapp updates
git log --pretty=format:"- %s" --decorate
- (void)onTapped:(UITapGestureRecognizer*)gesture {
self.currentPage = (self.currentPage+1) % self.numberOfPages;
[self setNeedsDisplay];
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
new Crafty.polygon([379,562],[772,560],[785,547],[783,531],[381,531],[379,543]),
new Crafty.polygon([186,526],[293,522],[297,556],[186,561],[175,544]),
new Crafty.polygon([817,362],[805,385],[781,403],[751,418],[712,421],[696,318],[749,307],[777,321],[806,338]),
new Crafty.polygon([219,189],[796,189],[807,197],[809,208],[802,221],[787,230],[218,224],[206,215],[206,205]),
new Crafty.polygon([635,550],[713,457],[781,520],[784,543],[778,556]),
new Crafty.polygon([709,412],[709,479],[731,480],[731,412]),
new Crafty.polygon([620,226],[699,294],[785,218]),
new Crafty.polygon([679,280],[704,347],[749,327],[722,263]),
new Crafty.polygon([91,55],[997,52],[997,14],[95,25]),
new Crafty.polygon([261,688],[935,688],[934,726],[262,718]),
@codeincontext
codeincontext / gist:4732237
Created February 7, 2013 16:40
Running the same JS on client and server
var serverSide = (typeof module !== "undefined");
if (serverSide) {
var Canvas = require('canvas')
, Image = Canvas.Image
, fs = require('fs');
}
function HeroImage() {
var height = 620;
@codeincontext
codeincontext / gist:4731892
Created February 7, 2013 15:59
No segfault
var Canvas = require('canvas')
, Image = Canvas.Image
, canvas = new Canvas(400, 400)
, ctx = canvas.getContext('2d')
, fs = require('fs')
var sprite
var hairSprite