Skip to content

Instantly share code, notes, and snippets.

@swguru
swguru / gzcat.py
Last active December 16, 2015 13:09
Read a 'gz or bzip2 file', extract a given number of lines in the file, and save them to a file. this script acts like 'gzcat' with partial extraction.
import sys
import codecs
"""
gzcat-like utility
usage: %prog num_of_lines input_file output_file
"""
if len(sys.argv) < 3:
print 'usage: num_of_lines input_file output_file'
@swguru
swguru / divide_with_bit_operation.py
Created March 22, 2013 07:33
implement divide operation without using built-in divide operator
import sys
# implement divide operation without using built-in divide operator
def divAndMod_slow(y,x, debug=0):
r = 0
while y >= x:
r += 1
y -= x
return r,y