Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View zahradil's full-sized avatar

Jiri Zahradil zahradil

  • Czech Republic
View GitHub Profile
@zahradil
zahradil / zipfile2_bz2extended.py
Created June 24, 2021 07:05
Modification to original python zipfile (/usr/lib/python2.7/zipfile.py) to support bzip2 type (type=12) compression and decompression in Python 2.7, where originally zipfile support only STORED and DEFLATED(zlib) compression schemes.
# -*- coding: utf-8 -*-
"""
Read and write ZIP files.
"""
import struct, os, time, sys, shutil
import binascii, cStringIO, stat
import io
import re
import string, bz2
@zahradil
zahradil / gist:8800421
Created February 4, 2014 09:15
btrfs: how to use and create snapshotable btrfs volume
sudo apt-get install btrfs-tools
sudo su
mkdir /data
cd /data
# create 500 MB file
dd if=/dev/zero of=/data/datadisk bs=1024 count=500000
# create btrfs
@zahradil
zahradil / ccnumvalidate.py
Last active December 20, 2015 22:59
corrected cc validation code
# original code: http://code.activestate.com/recipes/578202-credit-card-number-check/
cc_patterns = { # '<cc_type>' : { dict of valid lengths : [list of associated prefixes] }
'amex' : { (15) : ('34', '37') },
'carteblanche' : { (14) : ('300', '301', '302', '303', '304', '305', '36', '38') },
'dinersclub' : { (14) : ('300', '301', '302', '303', '304', '305', '36', '38') },
'discover' : { (16) : ('6011') },
'enroute' : { (15) : ('2014', '2149') },
'jcb' : { (15) : ('2131', '1800'), (16) : ('3') },
'mastercard' : { (16) : ('51', '52', '53', '54', '55') },
@zahradil
zahradil / gist:3368186
Created August 16, 2012 07:49
setdault too slow problem
import timeit
def debug(func, var):
print "Timing", func,
stmt = lambda: func(var)
tm = timeit.Timer(stmt=stmt)
res = tm.timeit(10000)
lst = stmt()
print "%1.10f" % (res*1000)
@zahradil
zahradil / gist:2311175
Created April 5, 2012 13:56
Redukce ticha na začátku wav souboru
# -*- coding: utf-8 -*-
import wave, array
wi = wave.open('a.wav', 'rb')
wo = wave.open('a-reduced.wav', 'wb')
wo.setparams(wi.getparams())
def process_start(frms):
delta, threshold = 50, 250