Skip to content

Instantly share code, notes, and snippets.

View cldotdev's full-sized avatar

Chienlung Huang cldotdev

View GitHub Profile
@cldotdev
cldotdev / match_delimiters.py
Created October 12, 2013 09:46
Code Fragment 6.4: Function for matching delimiters in an arithmetic expression.
#!/usr/bin/env python
class Empty(Exception):
pass
class ArrayStack:
def __init__(self):
@cldotdev
cldotdev / cws2fws.pl
Created August 29, 2013 11:50
SWF decompressing
#!/usr/bin/perl -w
=begin
cws2fws v 0.0.1 - Flash format 6+ decompressor
Jose Melo de Assis Fonseca / JMAF
http://zefonseca.com/
2008-04-26
Usage: cws2fws <COMPRESSED_SWF_FILE.swf>
@cldotdev
cldotdev / besthit.sh
Created July 10, 2013 02:43
Command for selecting the best hit in the blast results
# input.txt: blastlist format
# https://github.com/jlhg/bdorpy/blob/master/docs/format/blastlist.txt
awk -F'\t' '$1 ~ /^[0-9]/ { print $0 }' input.txt |sort -t$'\t' -k4d,4 -k18g,18 -k22gr,22 -k19gr,19 -k26gr,26 -k6gr |sort -t$'\t' -k4,4 -u >output.txt
@cldotdev
cldotdev / create_slink.sh
Created July 3, 2013 09:29
Batch create soft links to files in a directory
@cldotdev
cldotdev / htmlentities.py
Created July 2, 2013 11:33
Convert string to HTML/XML entities
# http://notfaq.wordpress.com/2008/10/18/python-convert-string-to-htmlxml-entities/
def htmlentities(text):
return ''.join(['&#%d;' % ord(ch) for ch in text])
@cldotdev
cldotdev / set_vs_list
Created June 12, 2013 01:27
Performance of Sets and Lists
# http://stackoverflow.com/questions/2831212/python-sets-vs-lists
>>> import timeit
>>> a = set(range(1000000))
>>> b = range(1000000)
>>> def test_a():
... '9999' in a
...
>>> def test_b():
... '9999' in b
@cldotdev
cldotdev / python-function.lang
Last active June 7, 2017 22:04
source-highlight configuration
vardef FUNCTION = '[[:blank:]]([[:alpha:]]|_)[[:word:]]*(?=[[:blank:]]*\()'
function = $FUNCTION
keyword = "and|assert|break|class|continue|def|del|elif|else|except|exec",
"finally|for|global|if|in|is|lambda|not|or|pass",
"print|raise|return|try|while|self"
@cldotdev
cldotdev / config
Last active February 27, 2019 05:44
bpython configuration
# This is a standard python config file
# Valid values can be True, False, integer numbers, strings
# By default bpython will look for ~/.config/bpython/config or you
# can specify a file with the --config option on the command line
# General section tag
[general]
# Display the autocomplete list as you type (default: True).
# When this is off, you can hit tab to see the suggestions.
@cldotdev
cldotdev / convert_camelcase.py
Created May 24, 2013 03:27
Convert CamelCase to camel_case
# http://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-camel-case
def convert(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
@cldotdev
cldotdev / sandbox.py
Last active December 17, 2015 12:58
Preventing Python code from importing certain modules
#!/usr/bin/env python
# http://marlonyao.iteye.com/blog/905313
# Usage: $ python sandbox.py <untrusted.py>
_builtins = dict(__builtins__.__dict__)
def _hook_import(name, *args, **kwargs):
restricted_modules = [
'os',