This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Y; end | |
class X | |
class Y; end | |
end | |
class X::Z | |
puts self, Y # Guess the output. | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#<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>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int my_atoi(const char *str) | |
{ | |
int neg = 1; | |
int x = 0; | |
if (*str == '-') | |
{ | |
neg = -1; | |
*str++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ugly poorly aligned if | |
if a == b | |
elsif b == c | |
elsif z == d | |
else | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |