Skip to content

Instantly share code, notes, and snippets.

Avatar

Jiri Zahradil zahradil

  • Czech Republic
View GitHub Profile
@zahradil
zahradil / gist:2311175
Created Apr 5, 2012
Redukce ticha na začátku wav souboru
View gist:2311175
# -*- 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
@zahradil
zahradil / gist:3368186
Created Aug 16, 2012
setdault too slow problem
View gist:3368186
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 / ccnumvalidate.py
Last active Dec 20, 2015
corrected cc validation code
View ccnumvalidate.py
# 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:8800421
Created Feb 4, 2014
btrfs: how to use and create snapshotable btrfs volume
View gist:8800421
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 / zipfile2_bz2extended.py
Created Jun 24, 2021
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.
View zipfile2_bz2extended.py
# -*- 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