Skip to content

Instantly share code, notes, and snippets.

#!/usr/local/bin/thrift --gen py
service QuantiosJobs {
string addEmployee(1:string email, 2:string first_name, 3:string last_name, 4:string phone_number, 5:binary why_hire_me)
}
(defmacro import-headers [class-name]
`(do
(import ~(symbol (format "com.myfit.%s.thrift.%s" class-name class-name)))
(import ~(symbol (format "com.myfit.%s.thrift.ServerImpl" class-name)))))
(defn run [class-name addr port]
(import-headers class-name)
...)
def geography(datum):
if datum in ("CT","DE","ME","MD","MA","NH","NJ","NY","PA","RI","VT"):
return (1, 0, 0, 0, 0)
elif datum in ("AL","AR","GA","KY","LA","MS","NC","SC","TN","VA","WV"):
return (0, 1, 0, 0, 0)
elif datum in ("IL","IN","IA","KS","MI","MN","MO","NE","ND","OH","SD","WI"):
return (0, 0, 1, 0, 0)
elif datum in ("AZ","NM","OK","TX"):
return (0, 0, 0, 1, 0)
elif datum in ("AK","CA","CO","HI","ID","MT","NV","OR","UT","WA","WY"):
{
"name": item['brand'],
"store": item['store_host'],
"url": item['url'],
"crawl_history": [datetime.datetime.utcnow()]
}
self.mongo_conn.brands.insert({
"name": item['brand'],
@maxhodak
maxhodak / recruiting.thrift
Created April 30, 2011 00:32
Engineering recruiting puzzle
#!/usr/local/bin/thrift --gen py
service RecruitingService {
string addCandidate(1:string email, 2:string first_name, 3:string last_name)
}
@maxhodak
maxhodak / thrift-puzzle.mdown
Created April 30, 2011 00:37
thrift-puzzle

Add Yourself

Difficulty: Easy; Requires Thrift version 0.6.0 or later

Add yourself to our employee candidate database using Thrift. It's really simple: there's a server, RecruitingService, running on http://sanger.transcriptic.com:9194 that responds to one call, addCandidate. Pass it the right params and you'll be on your way. The Thrift interface spec you need is here: https://gist.github.com/949280

End result: You'll get the string "Success!" returned.

>> fd = User.new
=> #<User id: nil, created_at: nil, updated_at: nil>
>> fd.save
SQL (0.4ms) BEGIN
SQL (10.6ms) INSERT INTO `users` (`created_at`, `updated_at`) VALUES (?, ?) [["created_at", Mon, 20 Jun 2011 01:01:40 UTC +00:00], ["updated_at", Mon, 20 Jun 2011 01:01:40 UTC +00:00]]
(1.6ms) COMMIT
=> true
>> fd
=> #<User id: 0, created_at: "2011-06-20 01:01:40", updated_at: "2011-06-20 01:01:40">
>> User.find 1
ActiveRecord::Schema.define(:version => 20110620010115) do
create_table "users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
end
end
@maxhodak
maxhodak / authors.txt
Created August 18, 2011 01:51
authors
select count(*) as num, substr(firstname, 1, 1) as initial, lastname
from paper_authors
where pmid in (
select pmid
from papers
where journal_id in (1095, 7348, 15276, 994, 6684) and kind like '%Journal Article%'
) and lastname not in (
'Bagla', 'Balter', 'Bhattacharjee', 'Bohannon', 'Clery', 'Cho', 'Cohen', 'Coontz', 'Couzin-Frankel', 'Culotta',
'Enserink', 'Ferber', 'Gibbons', 'Grimm', 'Xin', 'Kaiser', 'Kean', 'Kerr', 'Kintisch', 'Lawler', 'Leslie', 'Mann', 'Marshall',
'Mervis', 'Miller', 'Morell', 'Norman', 'Normile', 'Pennisi', 'Regalado', 'Roberts', 'Service', 'Shulman', 'Stokstad', 'Stone',
def foo():
mydata = a list of interesting whatever
return {
"aggdata": [
{
"date": x["date"],
"colA": x["something"],
....
} for x in mydata
]