Skip to content

Instantly share code, notes, and snippets.

@oxling
oxling / bowie_career.json
Last active March 28, 2017 19:21
David Bowie Career
{
"timeline": [
["1962–1967", "Early career to debut album", "Davy", "Britain", "https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/David_Bowie_%281967%29.png/340px-David_Bowie_%281967%29.png"],
["1968–1971", "Space Oddity to Hunky Dory", "David Bowie", "Britain/America", "http://www.cheekymonkeysarnia.ca/wp-content/uploads/2016/06/BOWIE-1969.jpg"],
["1972–1974", "Ziggy Stardust Period", "Ziggy Stardust", "Britain/America", "https://upload.wikimedia.org/wikipedia/commons/1/1e/David-Bowie_Early.jpg"]
]
}
@oxling
oxling / memory.js
Created August 18, 2012 15:34
Closure memory management in JavaScript
/* largeString will be included with the returned function,
making the closure large. */
function makeLargeClosure() {
var largeString = new Array(1000).join('0123456789');
return function() {
console.log(largeString);
}
}
/* largeString isn't used in the closure, even though it's in scope.
@oxling
oxling / iotest.erl
Created August 14, 2012 15:28
Using io:fread with new process
-module(iotest).
-compile(export_all).
% io:fread works as expected.
works() ->
io:format("Reading from console...\n"),
{ok, [Name]} = io:fread("What is your name?> ", "~s"),
io:format("Hello, ~s!\n", [Name]).
% Attempting io:fread on a new process has no effect.
@oxling
oxling / list.prolog
Created August 11, 2012 21:30
Finding the minimum in a list in Prolog
% This version doesn't work.
min_wrong([Item], Item).
min_wrong([Item | List], Item) :-
min_wrong(List, List_Answer),
Item =< List_Answer.
min_wrong([_Item | List], Answer) :-
min_wrong(List, Answer).
% Output:
%
@oxling
oxling / map_reduce.erl
Created July 28, 2012 20:00
An implementation of Map/Reduce in Erlang (with examples)
-module(map_reduce).
-compile(export_all).
% Buckets = tuple that will be sent to the map function
% Map_Func = map function.
% Format: fun(Bucket, Reduce_PID), messages Reduce_PID with array of results.
% Reduce_Func = reduce function
% Format: fun(Num_Buckets, Acc, [Results], Main_PID)
% Receives message from Reduce_PID.
% Responsible for messaging Main_PID with results.
@oxling
oxling / gist:3025575
Created June 30, 2012 21:26
Machine code to Assembly
...
C0 06 D0 03 4C 88 C2 C0 07 D0 03 4C 6E C2 98 48 20 24 CB D0 0A AD FB 04 29 28 D0 03 4C A4 C1 68 A8 A9 C1 48 B9 EA CF 48
60 A4 24 A5 25 48 20 24 FC 20 F4 C2 A0 00 68 69 00 C5 23 90 F0 20 22 FC 4C EB C2 A5 22 85 25 A0 00 84 24 F0 E0 A5 22 48
20 24 FC A5 28 85 2A A5 29 85 2B A4 21 88 68 69 01 C5 23 B0 0D 48 20 24 FC B1 28 91 2A 88 10 F9 30 E1 A0 00 20 F4 C2 20
22 FC 4C EB C2 A4 24 A9 A0 91 28 C8 C4 21 90 F9 B0 17 A9 28 85 21 A9 18 85 23 A9 17 85 25 20 22 FC 4C EB C2 A4 1F 20 F4
C2 4C EB C2 68 A8 AD FB 04 29 FE 8D FB 04 68 8D 78 04 68 48 4A 4A 4A AD 78 04 48 B0 08 AD FB 04 09 01 8D FB 04 A5 25 8D
FB 05 4C FF C1 20 A4 CC 4C EB C2 20 48 CD 4C EB C2 A4 1F 20 4E CD 4C EB C2 20 23 CD 4C EB C2 4C 19 C2 4C 34 C2 20 42 CD
AD 7B 05 85 24 8D 7B 04 AD FB 05 85 25 10 2F 20 51 CB A5 24 2C 1F C0 10 05 CD 7B 04 F0 03 8D 7B 05 A9 C1 48 B9 F3 CF
....