var Person = Backbone.Model.extend();
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
# Torndb is a very thin wrapper around MySQLdb that makes it even easier to use MySQL. | |
# Because it is very light, one can just go through the one-file python source | |
# to learn how to use it. | |
# Installation: pip install torndb | |
# Official doc: http://torndb.readthedocs.org/en/latest/ | |
# Source: https://github.com/bdarnell/torndb/blob/master/torndb.py | |
from torndb import Connection |
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
// Example: | |
JavaScript.load("/javascripts/something.js"); | |
// With callback (that’s the good thing): | |
JavaScript.load("http://www.someawesomedomain.com/api.js", function() { | |
API.use(); // or whatever api.js provides ... | |
}); |
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 UpdateTwitterHandler(tornado.web.RequestHandler, tornado.auth.TwitterMixin): | |
@tornado.web.asynchronous | |
@tornado.gen.engine | |
def post(self): | |
access_token = self.get_current_user_access_token() | |
result = yield tornado.gen.Task(self.twitter_request, | |
"/account/update_profile_background_image", | |
image=open('new_image.png', 'rb').read(), | |
access_token=access_token) |
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
//一种用普通的字符串的方法,另外一种用正则,还是正则的扩展性高一点。。 | |
//方法一:字符串方法 | |
function ifRepeat(str) { | |
var ss = str; | |
for (var i = 0; i < ss.length; i++) { | |
var cha = ss.charAt(i); | |
var sub = ss.substring(0,i)+ss.substring(i+1); | |
if (sub.indexOf(cha)!=-1) { | |
console.log("有重复"); |
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 AdminFileHandler(BaseHandler): | |
@authenticated | |
def get(self, file_name): | |
_file_dir = os.path.abspath("")+"/my/path/downloads" | |
_file_path = "%s/%s" % (_file_dir, file_name) | |
if not file_name or not os.path.exists(_file_path): | |
raise HTTPError(404) | |
self.set_header('Content-Type', 'application/force-download') | |
self.set_header('Content-Disposition', 'attachment; filename=%s' % file_name) |
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
from time import sleep | |
from tornado.httpserver import HTTPServer | |
from tornado.ioloop import IOLoop | |
from tornado.web import Application, asynchronous, RequestHandler | |
from multiprocessing.pool import ThreadPool | |
_workers = ThreadPool(10) | |
def run_background(func, callback, args=(), kwds={}): | |
def _callback(result): |
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
#!/usr/bin/env python | |
import sys | |
import pika | |
connection = pika.BlockingConnection(pika.ConnectionParameters( | |
'localhost')) | |
channel = connection.channel() | |
channel.queue_declare(queue='hello', durable=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
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
import sched, time | |
from threading import Thread, Timer | |
import subprocess | |
s = sched.scheduler(time.time, time.sleep) | |
class Job(Thread): |
OlderNewer