This file contains hidden or 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
-- See http://stackoverflow.com/questions/9967790/instance-in-haskell | |
instance (Enum x, Enum y) => Enum (x, y) where | |
fromEnum (x,y) = | |
k^2 + 2*j + if permuted then 1 else 0 | |
where | |
k = max (fromEnum x) (fromEnum y) | |
j = min (fromEnum x) (fromEnum y) | |
permuted = (fromEnum y) > (fromEnum x) | |
toEnum n = |
This file contains hidden or 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
import os, time | |
def list_modules(path): | |
for name in os.listdir(path): | |
base, ext = os.path.splitext(name) | |
if '.' in base or base.startswith('__'): | |
continue | |
if ext == '.py': | |
yield base | |
elif not ext: | |
if not os.path.exists(os.path.join(base, '__init__.py')): |
This file contains hidden or 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
/* Copyright 2012 Dietrich Epp <[email protected]> */ | |
#if defined(__GNUC__) && \ | |
((__GNUC__ == 4 && __GNUC_MINOR >= 6) || __GNUC__ > 4) | |
#define HAVE_DPUSH 1 | |
#endif | |
#include "keycode/keycode.h" | |
#include "keycode/keytable.h" | |
#include "sg/audio_system.h" | |
#include "sg/clock.h" |
This file contains hidden or 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
fn main() { | |
let mut x = "hello".chars(); | |
while (true) { | |
match x.next() { | |
Some('o') => return, | |
Some(c) => println!("Char: {}", c), | |
None => return | |
} | |
} | |
} |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#undef CUSTOM_BUFFER | |
#if defined CUSTOM_BUFFER | |
static const int BUFFER_SIZE = 1024 * 16; | |
#endif | |
int main() |
This file contains hidden or 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 A(object): | |
def __init__(self): | |
print('A') | |
class B(A): | |
def __init__(self): | |
print('B') | |
super(self.__class__, self).__init__() | |
class C(B): |
This file contains hidden or 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
run: test.o main.o | |
cc -o $@ $^ | |
test.o: test.c | |
cc -Wall -Wextra -O3 -c $< -o $@ | |
main.o: main.c | |
cc -Wall -Wextra -O2 -c $< -o $@ |
This file contains hidden or 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
As you can see, only extern_func() is accessible from other translation units. | |
$ c++ -std=c++11 -c test.cpp | |
$ nm -g test.o | c++filt | |
0000000000000000 T extern_func() | |
$ nm test.o | c++filt | |
0000000000000000 T extern_func() | |
0000000000000006 t static_func() | |
000000000000000c t (anonymous namespace)::anonymous_namespace_func() |
This file contains hidden or 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
This is what happens when I run the program. Note that 2 and 4 appear twice, but 0 and 1 never appear. The output is non-deterministic, because there is a race condition, the output could be almost anything. | |
Arg = 2 | |
Arg = 4 | |
Arg = 3 | |
Arg = 5 | |
Arg = 6 | |
Arg = 2 | |
Arg = 7 | |
Arg = 8 |
This file contains hidden or 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
Notice how each number appears only once. | |
The order is still scrambled, but we don't care about the order. | |
Arg = 1 | |
Arg = 4 | |
Arg = 2 | |
Arg = 6 | |
Arg = 3 | |
Arg = 7 |
OlderNewer