Skip to content

Instantly share code, notes, and snippets.

View codeb2cc's full-sized avatar
🎯
Focusing

Codeb Fan codeb2cc

🎯
Focusing
  • Eastworld AI
  • Singapore
View GitHub Profile
@codeb2cc
codeb2cc / memcached_demo.py
Last active December 21, 2015 05:29
Demonstrate some funny stuffs of memcached.
# -*- coding:utf-8 -*-
import sys
import time
import math
import re
import telnetlib
import random
from collections import namedtuple, defaultdict
@codeb2cc
codeb2cc / mongod.service
Created July 1, 2013 10:04
MongoDB systemctl unit file
[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target network.target
[Service]
Type=forking
User=mongod
PIDFile=/var/run/mongod/mongod.pid
EnvironmentFile=/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod -f /etc/mongod.conf run
@codeb2cc
codeb2cc / segregator.py
Last active December 19, 2015 04:48
Iterable segregator
from itertools import chain, tee, izip
# A
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
@codeb2cc
codeb2cc / dateParser.py
Created June 3, 2013 02:43
Convert Excel Date type
def convert(ordinal):
"""Convert Excel Date type"""
sd = datetime.date(1899, 12, 31) - datetime.timedelta(days=1)
return datetime.datetime.fromordinal(int(ordinal) + sd.toordinal())
@codeb2cc
codeb2cc / gist:5682575
Created May 31, 2013 02:10
Python pip upgrade all command
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
@codeb2cc
codeb2cc / stripVersion.js
Created March 18, 2013 05:21
Strip version/min filename in grunt-contrib-copy task.
// In task configuration, use `expand: true` and `rename: stripVersion`
var stripVersion = function (dest, src) {
var path = require('path');
return path.join(dest, src.replace(/-\d+\.\d+\.\d+(\.min)?/, ''))
}
function getAstro(m, d) {
return "魔羯水瓶双鱼牡羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m*2-(d<"102123444543".charAt(m-1)- -19)*2,2);
}
@codeb2cc
codeb2cc / gist:4994086
Created February 20, 2013 08:56
Remove control characters
import unicodedata
import re
chars = (unichr(i) for i in xrange(0x110000))
cc = ''.join(c for c in chars if unicodedata.category(c) == 'Cc')
# or equivalently and much more efficiently
cc = ''.join(map(unichr, range(0,32) + range(127,160)))
cc_re = re.compile('[%s]' % re.escape(cc))
@codeb2cc
codeb2cc / iptables
Created January 3, 2013 15:44 — forked from anonymous/iptables
Linode PPTP VPN iptables configuration
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*nat
:PREROUTING ACCEPT [10:532]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# PPTP
-A POSTROUTING -s 10.18.1.0/24 -o eth0 -j MASQUERADE
@codeb2cc
codeb2cc / monitor.sh
Last active October 13, 2015 09:37
Memeory usage monitor
#!/bin/sh
MEM=$(cat /proc/meminfo | ack 'MemFree: +(\d+)' --output "\$1" | bc)
CAC=$(cat /proc/meminfo | ack '^Cached: +(\d+)' --output "\$1" | bc)
FREE=$(echo "$MEM + $CAC" | bc)
THRESHOLD=1048576
echo "Free Memory: $MEM kb"