This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cat in ruby | |
vim rcat | |
#!/usr/bin/env ruby | |
# Usage: rcat [file ...] | |
puts ARGF.read | |
chmod +x rcat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# show platform | |
$ python -c "from platform import system; print system()" | |
Darwin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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])%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, |