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
from random import shuffle | |
class Generators(object): | |
def __init__(self, n): | |
self.a = range(n) | |
def __iter__(self): | |
for e in self.a: | |
yield e |
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 sqlite3 | |
import sys | |
for f in sys.argv[1:]: | |
print "== FILE: " + f + " ==" | |
with sqlite3.connect(f) as con: | |
for (table,) in con.cursor().execute("SELECT name FROM sqlite_master WHERE type='table';"): | |
print "=== TABLE: " + table + " ===" | |
for row in con.cursor().execute("SELECT * FROM " + table + ";"): | |
print row |
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, inspect, sys | |
# without inspect | |
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) | |
# or | |
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(inspect.getsourcefile (sys.modules[__name__]))), '..')) | |
import somemodule |
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> | |
using namespace std; | |
struct A { virtual void f () { cout << "A" << endl; }}; | |
struct B: A { void f () { cout << "B" << endl; }}; | |
/* multiple static dispatch */ | |
void overload (int, A *a, B *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
#include <iostream> | |
class uh | |
{ | |
public: | |
void f () { std::cout << "uh" << std::endl; } | |
}; | |
struct shit : uh {}; // public inheritance by default |
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
#!/usr/bin/bash | |
# rename to hooks/post-receive | |
# chmod u+x hooks/post-receive | |
read -r branch | |
if [[ $branch == *master ]] | |
then | |
# do something if somebody pushed something into master | |
fi |
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
use 5.10.0; | |
$a = 0; | |
$a ||= $0; | |
say $a; | |
$b = 0; | |
$b //= $0; | |
say $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
use feature qw(state say); | |
sub counter { | |
state $a = 0; | |
return ++$a; | |
} | |
say counter; # => 1 | |
say counter; # => 2 | |
say counter; # => 3 |
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> | |
template<unsigned long M> | |
struct f | |
{ | |
static const unsigned long value = M * f<M-1>::value; | |
}; | |
template<> | |
struct f<0> |
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 hello { | |
public static void main(String[] args) | |
{ | |
System.out.println (System.getProperty("sun.boot.class.path")); | |
} | |
} | |
// javac hello.java | |
// java hello | tr ':' '\n' |