Skip to content

Instantly share code, notes, and snippets.

@zed
zed / test_chrono.cpp
Created August 8, 2012 17:01
demonstrate that unlike clock() the chrono::steady_clock doesn't ignore sleep(), children time :c++11:chrono:clock:
// $ sudo apt-get install libboost-{system,chrono}1.48-dev
// $ g++ *.cpp -lboost_{system,chrono} && time ./a.out
#include <boost/chrono.hpp> // <chrono> in C++11
#include <iostream>
#include <string>
#include <stdint.h> // uintmax_t
#include <stdlib.h> // system()
#include <unistd.h> // sleep()
@zed
zed / .gitignore
Created August 25, 2012 22:42
call Python callback from a non-python thread in a C extension module
/c_extension_module*.so
/build/*
/.do_built*
/log
/all.did
@zed
zed / .gitignore
Created August 30, 2012 10:45
b2a_bin in Cython (a-la binascii.hexlify but for binary ("01") strings)
/b2a_bin.c
/b2a_bin.html
/b2a_bin*.so
/build/*
@zed
zed / test_utc_to_dst.py
Created October 5, 2012 08:55
can't get correct time during DST using dateutil (pytz works)
# based on https://launchpadlibrarian.net/94884626/testUtcToDst.patch
# from https://bugs.launchpad.net/dateutil/+bug/944123
import unittest
from datetime import datetime, timedelta
import dateutil.tz
import dateutil.zoneinfo
import pytz
tzname = "America/Toronto"
@zed
zed / .gitignore
Created November 8, 2012 21:37
Download comments from projecteuler.net for given problem range, user.
/.cachedir/
/comments-*.json
@zed
zed / progressbar-nothreads.py
Created November 13, 2012 18:47
start/stop tkinter progressbar on start/end of a subprocess without using threads
import sys
from subprocess import Popen
from Tkinter import Tk, StringVar
import ttk
START, STOP = "start", "stop"
# just some arbitrary command for demonstration
cmd = [sys.executable, '-c', """import sys, time
print("!")
@zed
zed / .gitignore
Created November 13, 2012 23:13
test whether socket ignores signals
/.tox/
/*.egg-info/
/tox-*.egg/
@zed
zed / test_arrow_timezone.py
Last active April 5, 2018 20:56
Notes on `arrow` library.
#!/usr/bin/env python3
"""Notes on `arrow` library.
* inconsitent (fixed)
>>> a = arrow.get(datetime(2012, 4, 7, 0, 30, 00), 'America/New_York')
>>> a.datetime.tzname() == a.tzinfo.tzname(a.datetime) # fixed
True
@zed
zed / local_timezones.py
Last active August 4, 2022 13:16
find local timezones as pytz.timezone objects
#!/usr/bin/env python
import os
import time
from datetime import timedelta
from hashlib import sha512
import pytz # pip install pytz
def filehash(path):
with open(path, 'rb') as file:
@zed
zed / count-words-performance.py
Created December 1, 2012 03:21
Python: measure time performance of counting words in corpus/gutenberg
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
http://stackoverflow.com/q/13655169
"""
import doctest
import inspect
import os
import sys
import timeit