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 / overriding.py
Created October 4, 2017 12:21
Python overriding
class Foo(object):
def fce(self):
print "foo"
class Bar(Foo):
def fce(self):
super(Bar, self).fce() # c'est nécessaire
print "bar"
a = Bar()
eu-readelf --debug-dump=info /usr/lib/debug/usr/bin/emacs-25.2-nox.debug | grep producer
find . -iname \*.cc -o -iname \*.hh | while read -r i ;do wc -L $i;done | awk '{ if ($1 > 110) printf "%50s %3d\n", $2, $1 }' | sort -n -k 2 -r
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/local_time_adjustor.hpp>
#include <iostream>
int main()
{
boost::posix_time::ptime x = boost::posix_time::time_from_string("2017-03-30 14:16:02.713506");
std::cout << x << std::endl;
typedef boost::date_time::local_adjustor<boost::posix_time::ptime, +2, boost::posix_time::no_dst> cest;
if (distance<home, work>::value < km<2>::value)
go_by_foot<work>();
else if (distance<my_car, home>::value
+ distance<free_parking_lot, work>::value
< km<1>::value)
go_by_car<work>();
else
go_by_public_transport<work>();
@mirekfranc
mirekfranc / to-unicode-form-feed.cpp
Created April 19, 2017 21:58
ascii to unicode form feed...
#include <fstream>
#include <iterator>
int main(int argc, char *argv[])
{
std::fstream is, os;
if (argc < 3)
return 1;
@mirekfranc
mirekfranc / old_examples.cpp
Created December 16, 2016 13:22
history is nice ;)
#ifdef HAVE_STD
#include <iostream>
using namespace std;
#else
#include <iostream.h>
#endif
@mirekfranc
mirekfranc / opcodes.txt
Last active October 10, 2016 12:33
access to the last element of an array in python
>>> a = [1, 2, 3]
>>> import dis
>>> def f():
print a[len(a)-1]
... ...
>>> def g():
print a[-1]
... ...
>>> dis.dis(f)
2 0 LOAD_GLOBAL 0 (a)
@mirekfranc
mirekfranc / strip-nl-at-the-end.py
Created September 14, 2016 12:39
remove trailing newline at the end of the file / windows tools generate this crap a one needs to be compatible with them
import sys
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
if len(sys.argv) < 2:
sys.exit(1)
with open(sys.argv[1], 'rb') as f:
@mirekfranc
mirekfranc / read_json_from_zip_archive.py
Created August 24, 2016 13:19
Read JSON from zip archive
from __future__ import print_function
import zipfile
archive = 'something.zip'
with zipfile.ZipFile(archive, 'r') as myzip:
for zi in myzip.infolist():
if zi.filename.endswith('.json'):
with myzip.open(zi, 'rU') as f:
for line in f: