Skip to content

Instantly share code, notes, and snippets.

View cldotdev's full-sized avatar

Chienlung Huang cldotdev

View GitHub Profile
@cldotdev
cldotdev / check_exit_status.sh
Created February 18, 2014 03:04
Check exit status
#!/bin/bash
$@ &>/dev/null
echo "Exit status:" $?
@cldotdev
cldotdev / .xprofile
Created February 15, 2014 07:27
Support Chinese input method (hime) in Emacs
#
# ~/.xprofile
#
# sourced by /etc/lxdm/Xsession
#
if which dbus-launch >/dev/null && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
eval "$(dbus-launch --sh-syntax --exit-with-session)"
fi
#!/bin/bash
#
# Usage:
# 1. Change the values in Config
# 2. $ sudo chmod 700 backup-mysql
# 3. $ sudo mv backup-mysql /etc/cron.daily/
## Config
MYSQL=/usr/bin/mysql
#!/bin/sh
if [ $# -lt 1 ]; then
echo "No destination defined. Usage: $0 destination" >&2
exit 1
elif [ $# -gt 1 ]; then
echo "Too many arguments. Usage: $0 destination" >&2
exit 1
elif [ ! -d "$1" ]; then
echo "Invalid path: $1" >&2
@cldotdev
cldotdev / dumpdb
Created January 22, 2014 08:46
regularly backup data
#!/bin/bash
# Add the path of this file to /etc/crontab
# e.g.
# $ chmod 700 dumpdb; mv dumpdb /etc/cron.daily/
today=$(date +%Y%m%d)
basedir=/var/backups
mysql_password=
if [[ -x /usr/bin/mysqldump ]]; then
@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 \
# 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 / 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);
@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;
}
#!/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