Skip to content

Instantly share code, notes, and snippets.

View lxneng's full-sized avatar
🎯
Focusing

Eric Luo lxneng

🎯
Focusing
View GitHub Profile
@lxneng
lxneng / gist:1046300
Created June 25, 2011 08:44 — forked from makenosound/gist:1046087
bare bones method for grabbing and updating a users latest tweet (with no error handling whatsoever)
$.ajax({
url: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=someonesplendid',
dataType: 'jsonp',
success: function(data) {
var tweet = data[0].text;
tweet = tweet.replace(/(http\:\/\/[A-Za-z0-9\.\/_]+)/g, '<a href="$1">$1</a>');
tweet = tweet.replace(/@([a-zA-Z0-9_]+)/g, '<a href="http://twitter.com/$1">@$1</a>');
$('#tweet').html(tweet);
}
});
>>> string = base64.urlsafe_b64encode('hello').strip('=')
>>> base64.urlsafe_b64decode(string + '=' * (-len(string) % 4))
'hello'
@lxneng
lxneng / gist:1031014
Created June 17, 2011 07:30
Exception: `curl-config' not found -- please install the libcurl development files
(env)~/env pip install pycurl
Downloading/unpacking pycurl
Downloading pycurl-7.19.0.tar.gz (71Kb): 71Kb downloaded
Running setup.py egg_info for package pycurl
sh: curl-config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/eric/env/build/pycurl/setup.py", line 90, in <module>
raise Exception, ("`%s' not found -- please install the libcurl development files" % CURL_CONFIG)
Exception: `curl-config' not found -- please install the libcurl development files
find query.log | xargs grep “感冒” ( 在query.log文件中查找“感冒”)
find /fse/ | xargs grep “感冒” (在 fse 文件夹中搜索 “感冒”)
@lxneng
lxneng / gist:1024309
Created June 14, 2011 04:20
merge dict in python
>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 10, 'c': 11}
>>> z = dict(x.items() + y.items())
>>> z
{'a': 1, 'c': 11, 'b': 10}
>>> z = dict(x, **y)
>>> z
{'a': 1, 'c': 11, 'b': 10}
#!/bin/bash
if [ ! -n "$1" ]; then
echo "解压工具,支持各种常见格式的压缩包。"
exit $E_BADARGS
fi
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
@lxneng
lxneng / gist:1018155
Created June 10, 2011 02:46
Get query string values in JavaScript
// Revised, cooler.
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(window.location.search);
return match ?
decodeURIComponent(match[1].replace(/\+/g, ' '))
: null;
@lxneng
lxneng / gist:1018152
Created June 10, 2011 02:40
How can I make a redirect page in jQuery?

jQuery is not necessary, and window.location.replace(...) will best simulate an HTTP redirect.

It is better than using window.location.href =, because replace() does not put the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, use location.href. If you want to simulate an HTTP redirect, use location.replace.

For example:

@lxneng
lxneng / gist:1018144
Created June 10, 2011 02:33
jquery get div>img and change src, jQuery('img', this).attr('src', /path/new)
$('.typeImage').each(function() {
$('img', this).attr('src', 'http://lxneng.com/images/xxx.gif');
});