Skip to content

Instantly share code, notes, and snippets.

View cldotdev's full-sized avatar

Chienlung Huang cldotdev

View GitHub Profile
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
@cldotdev
cldotdev / xor.rb
Created October 8, 2014 08:47
XOR operation in Ruby
class Array
def ^(that)
self + that - (self & that)
end
end
@cldotdev
cldotdev / struct_increment.c
Created June 23, 2014 13:45
遞升運算子及結構指標運算子
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int i;
} student;
int main()
{
student *s = malloc(sizeof(student));
>>> a = range(10000)
>>> def b():
... return len(set(a)) == 1
...
>>> def c():
... return all(x == a[0] for x in a)
...
>>> timeit.timeit(b, number=1000)
0.4336268901824951
>>> timeit.timeit(c, number=1000)
@cldotdev
cldotdev / new.py
Created May 7, 2014 05:22
Keyboard Interrupts with python's multiprocessing Pool (http://pastebin.com/5giYaMAx)
from multiprocessing import Pool
from time import sleep
from sys import exit
def slowly_square(i):
sleep(1)
return i*i
def go():
pool = Pool(8)
@cldotdev
cldotdev / fix_multiprocessing_keyboardinterrupt.py
Created April 18, 2014 06:52
Python 2.7 Multiprocessing and KeyboardInterrupts
#!/usr/bin/env python
# http://jtushman.github.io/blog/2014/01/14/python-%7C-multiprocessing-and-interrupts/
from multiprocessing import Process
from multiprocessing.managers import SyncManager
import time
import signal
def mgr_init():
signal.signal(signal.SIGINT, signal.SIG_IGN)
@cldotdev
cldotdev / ntpdate
Created April 6, 2014 11:44
Put it to /etc/cron.daily/. chmod 755 ntpdate
ntpdate time.stdtime.gov.tw
@cldotdev
cldotdev / terminalrc
Created March 11, 2014 17:32
Zenburn colours scheme for Xfce Terminal http://slinky.imukuppi.org/zenburnpage/
# Zenburn colours scheme for Xfce Terminal. Copy and paste the following in ${HOME}/.config/Terminal/terminalrc:
ColorBackground=#404040
ColorForeground=#F6F3E8
ColorPalette1=#3f3f3f3f3f3f
ColorPalette2=#e8e893939393
ColorPalette3=#9e9ecece9e9e
ColorPalette4=#f0f0dfdfafaf
ColorPalette5=#8c8cd0d0d3d3
ColorPalette6=#c0c0bebed1d1
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
xhost +local:root > /dev/null 2>&1
@cldotdev
cldotdev / README
Created March 5, 2014 11:50
Package installation list
Preferred package installation list for CentOS:
Usage:
$ sudo yum install -y $(curl https://gist.githubusercontent.com/jlhg/9365775/raw/yum-pkg)