Skip to content

Instantly share code, notes, and snippets.

View lxneng's full-sized avatar
🎯
Focusing

Eric Luo lxneng

🎯
Focusing
View GitHub Profile
http://maps.google.com/maps/api/geocode/json?address=30+WEST+63RD+STREET+CONDOMINIUM&sensor=true&language=en
http://maps.google.com/maps/api/geocode/json?address=30+WEST+63RD+STREET+CONDOMINIUM&sensor=true&language=zh_CN
@lxneng
lxneng / gist:328762
Created March 11, 2010 02:54
rspec, restful_authentication, and login_required
before :each do
@current_user = mock_model(User, :id =>1)
controller.stub!(:current_user).and_return(@current_user)
controller.stub!(:login_required).and_return(:true)
end
def getwords(doc):
splitter=re.compile('\\W*')
# Split the words by non-alpha characters
words=[s.lower() for s in splitter.split(doc)
if len(s)>2 and len(s)<20]
# Return the unique set of words only
return dict([(w,1) for w in words])
#cat in ruby
vim rcat
#!/usr/bin/env ruby
# Usage: rcat [file ...]
puts ARGF.read
chmod +x rcat
@lxneng
lxneng / gist:331320
Created March 13, 2010 13:31
show platform
# show platform
$ python -c "from platform import system; print system()"
Darwin
@lxneng
lxneng / gist:331323
Created March 13, 2010 13:34
Opens a url in the desktop's default browser
def open_url_in_browser(url):
"""
Opens a url in the desktop's default browser
"""
import threading
import webbrowser
class BrowserThread(threading.Thread):
def __init__(self, url):
threading.Thread.__init__(self)
@lxneng
lxneng / gist:331340
Created March 13, 2010 14:25
using geocoding fomarting address
In [1]: import urllib
In [2]: import json
In [3]: geo_url_fomart="http://maps.google.com/maps/api/geocode/json?address=%s&sensor=true"
In [4]: address = "627 Masonic Ave San Francisco CA 94117"
In [5]: geo_fomart_address = '+'.join(address.split())
@lxneng
lxneng / gist:331343
Created March 13, 2010 14:34
Convert list of lists to delimited string
In [1]: lists = [['dog', 1], ['cat', 2, 'a'], ['rat', 3, 4], ['bat', 5]]
In [2]: result = "\n".join("\t".join(map(str,l)) for l in lists)
In [3]: result
Out[3]: 'dog\t1\ncat\t2\ta\nrat\t3\t4\nbat\t5'
In [4]: print(result)
dog 1
cat 2 a
@lxneng
lxneng / gist:331737
Created March 14, 2010 02:54
Use rails date_select without activerecord model
#controller
@start_date = Date.civil(params[:range][:"start_date(1i)"].to_i,params[:range][:"start_date(2i)"].to_i,params[:range][:"start_date(3i)"].to_i)
#view
<%= date_select('range', 'start_date', :order => [:month, :day, :year])%>
@lxneng
lxneng / gist:331738
Created March 14, 2010 02:55
50 States Ruby Hash
states = [{:value => "AL"},{:label => "Alabama"},
{:value => "AK"},{:label => "Alaska"},
{:value => "AZ"},{:label => "Arizona"},
{:value => "AR"},{:label => "Arkansas"},
{:value => "CA"},{:label => "California"},
{:value => "CO"},{:label => "Colorado"},
{:value => "CT"},{:label => "Connecticut"},
{:value => "DE"},{:label => "Delaware"},
{:value => "DC"},{:label => "District of Columbia"},
{:value => "FL"},{:label => "Florida"},