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 <iostream> | |
#include <vector> | |
#undef CUSTOM_BUFFER | |
#if defined CUSTOM_BUFFER | |
static const int BUFFER_SIZE = 1024 * 16; | |
#endif | |
int main() |
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 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 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 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 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
~ $ cc -fPIC -pie -fsanitize=thread -pthread test3.c -Wall -Wextra -g | |
~ $ ./a.out 5 | |
i am thread 1 .created a new thread(132118272) in the itaration 0 | |
i am thread 1 .created a new thread(123725568) in the itaration 1 | |
================== | |
WARNING: ThreadSanitizer: data race (pid=20232) | |
Read of size 4 at 0x7ffcdeefaadc by thread T1: | |
#0 thread /home/depp/test3.c:10 (a.out+0x000000000c14) | |
#1 <null> <null> (libtsan.so.0+0x000000023519) |
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
-- 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 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 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 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 <depp@zdome.net> */ | |
#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 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: https://stackoverflow.com/a/48812277/82294 | |
template <int N> | |
void add(unsigned long long *dest, unsigned long long *src) { | |
__asm__( | |
"movq (%1), %%rax" | |
"\n\taddq %%rax, (%0)" | |
"\n.local add_offset" | |
"\n.set add_offset,0" | |
"\n.rept %P2" |
OlderNewer