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
function getAstro(m, d) {
return "魔羯水瓶双鱼牡羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m*2-(d<"102123444543".charAt(m-1)- -19)*2,2);
}
@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)?/, ''))
}
@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 / 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 / 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 / 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 / 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 / header_size.c
Created August 17, 2013 16:58
Calculate header size(requested memory) of a item stored in memcached.
#include <stdio.h>
#include <stdint.h>
/** Time relative to server start. Smaller than time_t on 64-bit systems. */
typedef unsigned int rel_time_t;
typedef struct _stritem {
struct _stritem *next;
struct _stritem *prev;
struct _stritem *h_next; /* hash chain next */
@codeb2cc
codeb2cc / gist:6280031
Created August 20, 2013 10:58
Nginx log format and GoAccess configuration.
# Nginx log format
log_format main '$remote_addr\t$remote_user\t$time_local\t$request_time\t$request\t'
'$status\t$body_bytes_sent\t$http_referer\t'
'$http_user_agent\t$http_x_forwarded_for';
# GoAccess configuration
# IMPORTANT: Replace all `\t` below with real tabs
date_format %d/%b/%Y:%T
log_format %h\t%^\t%d %^\t%T\t%r\t%s\t%b\t%R\t%u\t%^
@codeb2cc
codeb2cc / .gitconfig
Created September 30, 2013 07:49
Git config file
[user]
name = Codeb Fan
email = [email protected]
[push]
default = simple
[core]
editor = vim
[diff]
tool = vimdiff
ignoreSubmodules = dirty