Skip to content

Instantly share code, notes, and snippets.

View mirekfranc's full-sized avatar
🌚
Rien

Miroslav Franc mirekfranc

🌚
Rien
  • Prague, Czech Republic
View GitHub Profile
@mirekfranc
mirekfranc / generators.py
Created May 11, 2015 21:07
python's generator methods...
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
@mirekfranc
mirekfranc / sqlite_dump.py
Created May 11, 2015 22:39
small script to dump sqlite database files to stdin...
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
@mirekfranc
mirekfranc / import_from_above.py
Created May 28, 2015 15:16
importing of ../somemodule.py
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
@mirekfranc
mirekfranc / dispatch.cpp
Created May 30, 2015 03:16
clearing up the terminology...
#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)
{
@mirekfranc
mirekfranc / struct_public_inheritance.cpp
Created June 6, 2015 13:27
struct using public inheritance by default...
#include <iostream>
class uh
{
public:
void f () { std::cout << "uh" << std::endl; }
};
struct shit : uh {}; // public inheritance by default
@mirekfranc
mirekfranc / post-receive.sh
Last active August 29, 2015 14:23
post-receive git hook
#!/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
@mirekfranc
mirekfranc / defined_or.pl
Created June 28, 2015 21:10
defined or operator in perl 5.10
use 5.10.0;
$a = 0;
$a ||= $0;
say $a;
$b = 0;
$b //= $0;
say $b;
@mirekfranc
mirekfranc / state_and_say.pl
Created June 28, 2015 21:18
state and say features from perl 5.10...
use feature qw(state say);
sub counter {
state $a = 0;
return ++$a;
}
say counter; # => 1
say counter; # => 2
say counter; # => 3
@mirekfranc
mirekfranc / factorial.cpp
Created July 3, 2015 02:11
factorial with C++ templates
#include <iostream>
template<unsigned long M>
struct f
{
static const unsigned long value = M * f<M-1>::value;
};
template<>
struct f<0>
@mirekfranc
mirekfranc / hello.java
Last active August 29, 2015 14:24
Global classpath...
class hello {
public static void main(String[] args)
{
System.out.println (System.getProperty("sun.boot.class.path"));
}
}
// javac hello.java
// java hello | tr ':' '\n'