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 random | |
def name_generator(): | |
adjectives = ['narly', 'arrogant', 'fickle', 'eager', 'modest', 'greasy', 'tart', 'swift', 'quaint', 'unslightly', 'fancy', 'brave', 'delightful', 'jolly', 'shy', 'itchy', 'obedient', 'voiceless', 'raspy', 'silly', 'powerful', 'tender', 'clumsy', 'juicy', 'bitter', 'damp', 'fluffy', 'substantial', 'sticky', 'ancient', 'foolish'] | |
nouns = ['carrot', 'barley', 'banana', 'garlic', 'pickle', 'mouse', 'baboon', 'herring', 'tramp', 'panda', 'owl', 'parsnip', 'whale', 'lettuce', 'yam', 'mammoth', 'rock', 'mushroom', 'elephant', 'panther', 'phoenix', 'onion', 'cloth', 'chair', 'lemonade', 'tyvek', 'underpants', 'willow', 'girdle', 'clover', 'society', 'beaver', 'tart', 'wolf', 'leather', 'pantyhose', 'socks'] | |
return random.choice(adjectives) + random.choice(nouns) |
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
# -*- coding: utf-8 -*- | |
import urllib | |
import re | |
import decimal | |
import uuid | |
import datetime | |
from google.appengine.ext import db | |
try: | |
import json |
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 timeit | |
t = timeit.Timer(stmt="""\ | |
def test(pwd, n_iter): | |
for i in range(n_iter): | |
pwd = hashlib.sha1(pwd).hexdigest() | |
test('hello', 50000) | |
""", setup='import hashlib') | |
print t.timeit(100) / 100 |
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
<html> | |
<body> | |
<a href="javascript: | |
(function() { | |
var el=document.createElement('div'), | |
b=document.getElementsByTagName('body')[0], | |
otherlib=false, | |
msg=''; |
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
class Votable(BaseModel): | |
points = db.IntegerProperty(default=1) | |
score = db.FloatProperty() | |
up_votes = db.StringListProperty() # contains user key_names | |
down_votes = db.StringListProperty() # contains user key_names | |
def update_score(self): | |
"""Adapted from reddit's algorithm | |
http://code.reddit.com/browser/r2/r2/lib/db/sorts.py?rev=4778b17e939e119417cc5ec25b82c4e9a65621b2 | |
""" |
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
### app.yaml ### | |
- url: /upload | |
script: main.py | |
login: admin | |
### views.py ### | |
class BlobstoreUpload(BaseHandler): | |
def post(self): | |
key = self.get_argument('key') |
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
f = open('/path/csv.txt', 'r') | |
entities = [] | |
for line in f: | |
arg1, arg2, arg3 = line.split(',') | |
data = models.SomeData(arg1=arg1, arg2=arg2, arg3=arg3) | |
entities.append(data) | |
if len(entities) > 40: | |
db.put(entities) | |
entities = [] |
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
class Topic(BaseModel): | |
author = db.ReferenceProperty(User, required=True, collection_name='topics') | |
title = db.StringProperty() | |
body = db.TextProperty() | |
@classmethod | |
def topics(cls): | |
topics = cls.all().order('-updated').fetch(100) | |
prefetch_refprop(topics, cls.author) | |
return topics |
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
for i in range(0, len(x)): | |
for j in range(0, len(x)): | |
indice = i * len(x) + j | |
value = x[i] ** (len(x) - j) | |
M.put(indice, value) |
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 urllib | |
import re | |
import uuid | |
from django.utils import simplejson | |
def google_translate(text, source='en', target='fr'): | |
subs = {} | |
for arg in re.findall('(\{.+?\})', text): |