Skip to content

Instantly share code, notes, and snippets.

View stormbrew's full-sized avatar

stormbrew stormbrew

  • Edmonton, Alberta, Canada
View GitHub Profile
class Y; end
class X
class Y; end
end
class X::Z
puts self, Y # Guess the output.
end
#<ExchangeBitcoins::Trade:0xa7d4 @id=3766 @date=Wed Jul 06 10:09:29 -0700 2011 @amount=0.2124 @price=15.69>,
211 + #<ExchangeBitcoins::Trade:0xa7ec @id=3767 @date=Wed Jul 06 10:09:30 -0700 2011 @amount=0.2612 @price=15.69>,
212 #<ExchangeBitcoins::Trade:0xa7dc @id=3769 @date=Wed Jul 06 10:09:30 -0700 2011 @amount=5.181 @price=15.69>,
213 #<ExchangeBitcoins::Trade:0xa7e4 @id=3768 @date=Wed Jul 06 10:09:30 -0700 2011 @amount=0.3246 @price=15.69>,
214 - #<ExchangeBitcoins::Trade:0xa7ec @id=3767 @date=Wed Jul 06 10:09:30 -0700 2011 @amount=0.2612 @price=15.69>,
215 #<ExchangeBitcoins::Trade:0xa7f4 @id=3770 @date=Wed Jul 06 10:09:57 -0700 2011 @amount=4.629 @price=15.69>,
@stormbrew
stormbrew / gist:1184811
Created August 31, 2011 21:47
my tmux config
set -g prefix C-a
unbind C-b
bind a send-prefix
bind C-a last-window
unbind %
bind | split-window -h
bind - split-window -v
set-window-option -g window-status-current-bg red
@stormbrew
stormbrew / coroutine.c9s
Created September 10, 2011 00:29
Ridiculously contrived coroutine example for Channel9
var ho
var hi = () {
var cont = ho
var count = 0
while (count != 1000) {
"hi " + count.to_string_primitive -> $stdout
// send count + 1 to cont, save its return address in cont
count = (count + 1 -> cont : cont)
}
}
C++ code:
Data * data = m_cur_chunk->alloc(alloc_size);
data->init(size, type, m_cur_pool, false);
Data * alloc(size_t size)
{
Data * ret = (Data*)(m_data + m_used);
m_used += size;
return ret;
}
a = 10
l = ARGV.collect {|x| x.to_i }
c = 0
i = 0
while i < (l.size - 2)
j = i + 1
while j < (l.size - 1)
k = j + 1
while k < (l.size)
#include <stdio.h>
int my_atoi(const char *str)
{
int neg = 1;
int x = 0;
if (*str == '-')
{
neg = -1;
*str++;
@stormbrew
stormbrew / gist:2521852
Created April 28, 2012 20:39
Devil's advocate argument for case based on its term-less form
# Ugly poorly aligned if
if a == b
elsif b == c
elsif z == d
else
end
#include <string>
#include <cstdio>
using namespace std;
class X
{
public:
string str;
X(const string &s) : str(s) { printf("Constructor %s 0x%p\n", str.c_str(), this); }
~X() { printf("Destructor %s 0x%p\n", str.c_str(), this); }
Python object model in a nutshell (with deliberate errors for simplicity):
- A class is a dict
- The dict contains methods (not in python syntax):
cls = { 'a': function(self, blah) {...}, 'b': function(self, blorp) {...} }
- An object is also a dict that contains an __class__ member that points to the class:
obj = { '__class__': cls }
- When you fetch a method from obj:
obj.a
it looks on __class__ for 'a', and finding it wraps it in a functor that adds the self parameter:
function(blah) { obj['__class__']['a'](obj, blah) }