Skip to content

Instantly share code, notes, and snippets.

@alexzhan
alexzhan / textdiff.py
Created May 5, 2012 09:11
Find the differences between two pieces of TEXT.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
textdiff.py
Original is (C) Ian Bicking <ianb@colorstudy.com>
With changes from Richard Cyganiak <richard@cyganiak.de> and Richard Cyganiak <richard@cyganiak.de>
Modified from https://github.com/cygri/htmldiff/blob/master/htmldiff
Finds the differences between two pieces of TEXT.
@alexzhan
alexzhan / IE_Placeholder
Created February 17, 2012 11:23
add the compatibility to IE for showing the placeholder content
in HTML:
<textarea id="pubtextarea" placeholder="你在想什么?"></textarea>
in Javascript:
$(document).ready(function() {
var ie = document.all ? 1 : 0
if(ie){
$("#pubtextarea").val("你在想什么?");
$("#pubtextarea").css("color","#A9A9A9");
}
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@alexzhan
alexzhan / grep many keywords
Created November 4, 2011 08:40
grep搜索同时包含多个关键字的文件
grep -nirl ‘xxx’ ./ | xargs grep -Hnir “yyy”
命令的前半截先列举出包含’xxx’关键字的文件路径和文件名。后半句在这些文件中搜索’yyy’关键字并列出。
curl -o ~/.vim/colors/molokai.vim http://www.vim.org/scripts/download_script.php?src_id=9750
http://superuser.com/questions/301044/how-to-wget-a-file-with-correct-name-when-redirected
@alexzhan
alexzhan / pdfcrop.py
Created October 7, 2011 12:53 — forked from laogao/pdfcrop.py
Use pyPdf to crop a pdf file according to user inputs
#!/usr/bin/env python
import sys
if __name__ == '__main__' and len(sys.argv) > 5 and sys.argv[1][-3:].upper() == 'PDF':
original = sys.argv[1]
target = original[:-4] + '.cropped.pdf'
left = int(sys.argv[2])
top = int(sys.argv[3])
right = int(sys.argv[4])
@alexzhan
alexzhan / grep
Created September 6, 2011 06:40
grep contents
find . -type f -name "*.php" | xargs grep "DEF_BASE_LOG_PATH"
linux下查找某目录下所有文件包含某字符串的命令:
从文件内容查找匹配指定字符串的行:
$ grep "被查找的字符串" 文件名
从文件内容查找与正则表达式匹配的行:
$ grep –e “正则表达式” 文件名
查找时不区分大小写:
$ grep –i "被查找的字符串" 文件名
查找匹配的行数:
@alexzhan
alexzhan / mapreduce.js
Created June 2, 2011 08:12 — forked from adomado/mapreduce.js
Simple MapReduce with Javascript
var Job = {
data : [
"We are glad to see you here. This site is dedicated to",
"poetry and to the people who make poetry possible",
"poets and their readers. FamousPoetsAndPoems.com is",
"a free poetry site. On our site you can find a large",
"collection of poems and quotes from over 631 poets",
"Read and Enjoy Poetry",
"I, too, sing America",
@alexzhan
alexzhan / mysql update table where something not null
Created January 21, 2011 05:44
mysql update table where something not null
Being Processed Before:
http://goo.gl/JfLwg
1. update T_Image set isFetched=1 where url<>''
2. update T_Image set isFetched=1 where dir<>''
Being Processed After:
http://goo.gl/ooxfj
@alexzhan
alexzhan / add auto_increment id set primary
Created November 28, 2010 13:41
add auto_increment id set primary
对于item_detail:
先用
alter table item_detail drop primary key;
删除原来的主键;
然后用:
alter table item_detail add column id int unsigned not null auto_increment primary key;
增加自增的主键id