This file contains 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
conn.delete(1) | |
conn.delete([2, 3]) | |
conn.commit() |
This file contains 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
conn.delete_query('title:foo') | |
conn.delete_query(['title:foo', 'title:bar']) | |
conn.commit() |
This file contains 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
results = conn.query('foo:bar') | |
print "Your query executed in %s microseconds" % results.header['QTime'] | |
for result in results.results: | |
print result['title'] |
This file contains 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
import traceback | |
def app_view_processor(request): | |
"""Add the current application and view names to the context.""" | |
params = {} | |
for item in reversed(traceback.extract_stack()): | |
if item[0].endswith("/views.py"): | |
params['CURRENT_APP'] = item[0].split("/")[-2] | |
params['CURRENT_VIEW'] = item[2] | |
return params |
This file contains 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
db.test.save({grouper:1, checker:false}); | |
db.test.save({grouper:1, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:1, checker:false}); | |
db.test.find({checker:false}).forEach(function(test) { | |
db.test.update({checker:test.checker}, {$set:{checker:true}}, false, true); |
This file contains 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
db.test.save({grouper:1, checker:false}); | |
db.test.save({grouper:1, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:2, checker:false}); | |
db.test.save({grouper:1, checker:false}); | |
while (true) { | |
var test = db.test.findOne({checker:false}); |
This file contains 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
db.journeys.find({is_bot:false, event_count:{$gt:3000}}).forEach(function(journey) { | |
var bot_user = db.users.findOne({is_bot:true, user_agent:journey.user_agent, _id:{$ne:journey.user}}); | |
if (bot_user) { | |
var user = db.users.findOne({_id:journey.user}); | |
db.journeys.update({user:journey.user}, {$set:{is_bot:true, user:bot_user._id}}, false, true); | |
db.users.update({_id:bot_user._id}, {$inc:{journey_count:user.journey_count, event_count:user.event_count}, $addToSet:{ip_addresses:user.ip_addresses}}); | |
db.events.update({user:journey.user}, {$set:{is_bot:true, user:bot_user._id}}, false, true); | |
} else { | |
db.users.update({_id:journey.user}, {$set:{is_bot:true}}, false, true); | |
db.journeys.update({user:journey.user}, {$set:{is_bot:true}}, false, true); |
This file contains 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
to 8783 | |
a 8394 | |
I 7733 | |
in 4816 | |
it 4509 | |
of 4294 | |
is 4280 | |
on 4256 | |
my 4052 | |
me 3687 |
This file contains 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
<?php | |
function tokenize($message) { | |
preg_match_all("#[@\#][\w]+|http://[^\s]+|[:;][^\s]*[\(\)D\]\[\{\}pP]|[\w'\-]+#", $message, $matches); | |
return $matches; | |
} | |
$messages = array( | |
"@leemcveigh Yup, they're not pretty.", |
This file contains 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
import pymongo | |
import unittest | |
class TestIndexFailure(unittest.TestCase): | |
def setUp(self): | |
self.coll = pymongo.Connection()['test']['test'] | |
self.coll.drop() | |
self.coll.save({"key":"Value1"}) | |
self.coll.save({"key":"Value2"}) |