Skip to content

Instantly share code, notes, and snippets.

View cldotdev's full-sized avatar

Chienlung Huang cldotdev

View GitHub Profile
@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 / create_slink.sh
Created July 3, 2013 09:29
Batch create soft links to files in a directory
@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 / 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 / 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):
#!/bin/sh
# Convert ANSI (terminal) colours and attributes to HTML
# Licence: LGPLv2
# Author:
# http://www.pixelbeat.org/docs/terminal_colours/
# Examples:
# ls -l --color=always | ansi2html.sh > ls.html
# git show --color | ansi2html.sh > last_change.html
@cldotdev
cldotdev / comb_amount.c
Last active January 1, 2016 16:08
Algorithm by Donald Knuth
unsigned long long
choose(unsigned long long n, unsigned long long k) {
if (k > n) {
return 0;
}
unsigned long long r = 1;
for (unsigned long long d = 1; d <= k; ++d) {
r *= n--;
r /= d;
}
@cldotdev
cldotdev / grandom.c
Created January 5, 2014 08:03
Generate random number in C
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
srand(time(NULL));
int r = rand();
printf("%d\n", r);
# Rollcode.com
import sys, subprocess, urllib
def getSpeech(phrase):
googleAPIurl = "http://translate.google.com/translate_tts?tl=en&"
param = {'q': phrase}
data = urllib.urlencode(param)
googleAPIurl += data # Append the parameters
return googleAPIurl
@cldotdev
cldotdev / wmv2flv.sh
Last active January 3, 2016 02:49
wmv to flv with ffmpeg
#!/bin/bash
# Usage: ./wmv2flv.sh <intput.wmv> <output.flv>
if [ $# -eq 0 ]; then
echo "Usage: ./wmv2flv.sh <intput.wmv> <output.flv>"
exit 1
fi
ffmpeg -i $1 -acodec libmp3lame -ar 22050 -ab 96000 -deinterlace \
-nr 500 -aspect 4:3 -r 20 -g 500 -me_range 20 -b 270k -deinterlace \