Skip to content

Instantly share code, notes, and snippets.

@fakechris
fakechris / gist:5678882
Created May 30, 2013 15:43
gitlab 5.2 has ldap auth bug
- return false unless user.valid_password?(password)
+ if not user.valid_password?(password)
+ # Second chance - try LDAP authentication
+ return false unless Gitlab.config.ldap.enabled
+ ldap_auth(login,password)
+ return false unless !user.nil?
+ end
+ #return false unless user.valid_password?(password)
import csv,sys
def fn_sort_by(key, header_index):
return lambda x,y:cmp(x[header_index[key]], y[header_index[key]])
if __name__ == "__main__":
csvfilename = sys.argv[1]
sort_fileds = sys.argv[2]
f = open(csvfilename)
header = f.readline().split(',')
@fakechris
fakechris / killsql_by_meilishuo.sh
Created October 26, 2012 02:23
shared by meilishuo ppt in photo, type it by me
#!/bin/bash
port=$3
if [ $port'z' == 'z' ]
then
port=3306
fi
mysql -h${1} -P${port} -e "select * from information_sechema.processlist where info is not null and time>${2} and user like '%dbreader%' and info like '%select%'\G">.sql.${1}.tmp
pids=`mysql -h${1} -P${port} -e "select id from information_sechema.processlist where info is not null and time>${2} and user like '%dbreader%' and info like '%select%'"|awk -F\| '{print $1"\n"}'`
@fakechris
fakechris / crawl_baidu_music.py
Created October 19, 2012 08:14
crawl baidu music by top500/new100/artist/songid
#!/usr/bin/env python
# coding: utf-8
import gflags
import logging
import os
import sys
from pygaga.helpers.logger import log_init
from pygaga.helpers.utils import make_dirs_for_file
@fakechris
fakechris / ratelimit.js
Created September 5, 2012 20:12
ratelimit decorator for node.js callback
#!/usr/bin/env node
// interval -- min interval between callback, in ms
// fn_callback -- callback function
// max_queue_len -- drop callback when exceed max queue length
function ratelimit(interval, fn_callback) {
var last = 0,
max_queue_len = 100,
schedule_later = function(context, args, timeout) {
setTimeout(function() {
#!/bin/sh
SRC_PATH=$0
DST_PATH=$1
for d in `ls $SRC_PATH`; do
echo "copying $SRC_PATH/$d -> $DST_PATH/$d"
rsync -aplx --link-dest=$SRC_PATH/$d $SRC_PATH/$d $DST_PATH/$d
echo "removing $SRC_PATH/$d"
rm -rf $SRC_PATH/$d
done
@fakechris
fakechris / g2b.js
Created March 31, 2012 07:44
Javascript bookmartlet that swith between google&baidu
javascript:window.location.href=window.location.href.match(/google/)?'http://www.baidu.com/s?ie=utf-8&wd='+window.location.href.split('&q=')[1].split('&')[0]:'http://www.google.com/search?ie=UTF-8&q='+window.location.href.split('&wd=')[1].split('&')[0];
@fakechris
fakechris / airplay.js
Created December 27, 2011 14:07
ipad airplay bookmarklet
javascript:%5B%5D.forEach.call(document.querySelectorAll('embed,video'),function(e)%7Be.setAttribute('x-webkit-airplay','allow');e.setAttribute('airplay','allow')%7D);
@fakechris
fakechris / hadoop_du.sh
Created December 7, 2011 03:30
user friendly hadoop du
#!/bin/sh
hadoop fs -du $1 | awk '{print $1/1000.0/1000.0/1000.0, $2, $3}'
@fakechris
fakechris / mac_set_dns.sh
Created December 7, 2011 03:28
Set dns on mac
#!/bin/sh
networksetup -setdnsservers Wi-Fi Empty # 8.8.8.8
sudo killall -9 mDNSResponder