Skip to content

Instantly share code, notes, and snippets.

@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
@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: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 / 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 / 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 / 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 / gist:6708684
Created September 26, 2013 01:35
Look how easy it is to build a deck of cards in Elixir! Example shamelessly taken from "Programming Elixir", which you should definitely buy
import Enum
# build a deck of cards
deck = lc rank inlist '23456789TJQKA', suit inlist 'CDHS', do: [suit, rank]
# -> ['C2', 'D2', 'H2', 'S2', 'C3', 'D3', ... ]
# take 5 random cards from the deck
hand = deck |> shuffle |> take(5)
# -> ['D8', 'CQ', 'H2', 'H3', 'HK']
@codeincontext
codeincontext / gist:6710863
Last active December 23, 2015 23:38
The one-electron theory
I think the one-electron theory is my favourite physics theory. It's something I was taught that's come around on Hacker News recently https://en.wikipedia.org/wiki/One-electron_universe
**It involves a thought experiment.**
Imagine making jelly *(jello, if you're in the states)* with a load of string looped around, bundled, and set in it like a big suspended knot. Taking a cross-section of the jello will show a load of identical dots. They're seemingly un-connected, but _we know there's just one string they came from_.
Now extrapolate this out and imagine that the jelly is space-time, and any slice is our 3D world at a given time. Because we're bound by time we can only see one slice at a time. It seems to us that there are always a lot of identical dots - and we naturally assume each is a separate thing.
The one-electron theory asks whether this could be how we're perceiving electrons. Could there be one electron whizzing about space and time. At any given time, it would appear to us in multiple places
@codeincontext
codeincontext / christmas.js
Last active December 31, 2015 17:39
MERRY CHRISTMAS!
w=console.log.bind(console),t=13,l=0,s=function(b,c){return new Array(b).join(c)};
f=function(){clear();l=!l;w('\u001B[2J\u001B[0;0f');w(s(t-1,' ')+(l?'\\ /':''));w(s(t-3,' ')+(l?'-->*<--':' .'));
for(i=1;i<t;i++){w(s(t-i,' ')+'/'+s(i,'_'+(i%2?'/':'\\'))+'_\\')}w(s(t-2,' ')+'[___]');setTimeout(f,600)};f()
@codeincontext
codeincontext / gist:15784828067029c27038
Last active August 29, 2015 14:24
Quick and dirty translation helper
currentLocale = 'en';
locales = {
en: {
'common.between': 'less than __ but more than __'
}
};
t = function(key, ...insertions) {
let translatedString = locales[currentLocale][key];
return translatedString.replace(/__/g, () => insertions.shift());