Skip to content

Instantly share code, notes, and snippets.

@caingougou
caingougou / .bash_profile
Last active December 13, 2015 16:59
bash arrow key autocomplete command in history
# works on osx
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
@caingougou
caingougou / v2ex_user_fetcher.rb
Created February 7, 2013 08:28
fetch url in v2ex member profiles
#!/usr/bin/env ruby
require "httpclient"
require "nokogiri"
require "pp"
hc = HTTPClient.new(:agent_name => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Firefox/1.5.0.4")
(1..2000).each { |i|
puts i.to_s + ":"
res = hc.get('http://www.v2ex.com/uid/' + i.to_s, :follow_redirect => true)
@caingougou
caingougou / rollback_svn.sh
Created January 25, 2013 08:12
rollback the svn commit
svn merge -c -[revision number] http://[svn address]/[file path on svn] [local file]
@caingougou
caingougou / generate_ipk.sh
Created January 22, 2013 02:31
Generate dummy ipk file
NAME=me
palm-generate -p "{'id':'com.$NAME.hello$1', 'version':'1.0.0', 'vendor':'$NAME', 'title':'Hello world'}" HelloWorld$1
palm-package HelloWorld$1
rm -r HelloWorld$1
@caingougou
caingougou / generate_apk.sh
Created January 22, 2013 02:30
Generate dummy apk file
#!/bin/sh
ANDROID_TOOLS_DIR=[android tools dir]
NAME=Me
mkdir $NAME$1
$ANDROID_TOOLS_DIR/android -s create project --target 18 --name $NAME$1 --path $NAME$1 --activity $NAME$1 --package com.$NAME.android$1
cd $NAME$1
sed -i 's/android:versionName="1\.0"/android:versionName="1\.0\.0"/g' AndroidManifest.xml # force the version name three parts
sed -i '6i\\t\<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" android:maxSdkVersion="15" />' AndroidManifest.xml # add sdk versions
sed -i '7i\\t\<compatible-screens>\n\t\t\<screen android:screenSize="small" android:screenDensity="ldpi" />\n\t\t\<screen android:screenSize="small" android:screenDensity="mdpi\" />\n\t\t\<screen android:screenSize="small" android:screenDensity="hdpi" />\n\t\t\<screen android:screenSize="small" android:screenDensity="xhdpi" />\n\t\t\<screen android:screenSize="normal" android:screenDensity="ldpi" />\n\t\t\<screen android:screenSize="normal" android:screenDensity="mdpi" />\n\t\t\<screen android:screenSize="normal" android:s
@caingougou
caingougou / filemonitor.rb
Created January 22, 2013 02:25
Monitor file or folder changes
#!/usr/bin/env ruby
require 'inotify'
require 'find'
require 'pp'
i = Inotify.new
t = Thread.new do
i.each_event do |ev|
@caingougou
caingougou / filemonitor.py
Created January 22, 2013 02:23
Monitor file or folder changes
#!/usr/bin/env python
import pyinotify
import sys
class MyEventHandler(pyinotify.ProcessEvent):
def process_IN_ACCESS(self, event):
print "ACCESS event:", event.pathname
def process_IN_ATTRIB(self, event):
diff file file2 > ~/$(date '%F').diff
@caingougou
caingougou / check php.sh
Created January 8, 2013 03:52
check php process is still alive
ps aux|grep "/usr/bin/php"|wc -l|awk '{print $1-1}'
@caingougou
caingougou / get largest file.sh
Created January 8, 2013 03:51
Get the largest file in the folder
find . -type f | xargs ls -s | sort -rn | head