start new:
tmux
start new with session name:
tmux new -s myname
from gevent import monkey; monkey.patch_all() | |
import gevent | |
import gevent.greenlet | |
from functools import partial | |
from random import random | |
import urllib | |
import urllib2 | |
def on_exception(fun, greenlet): |
class Backend(object): | |
def __init__(self): | |
engine = create_engine("mysql://{0}:{1}@{2}/{3}".format(options.mysql_user, options.mysql_pass, options.mysql_host, options.mysql_db) | |
, pool_size = options.mysql_poolsize | |
, pool_recycle = 3600 | |
, echo=options.debug | |
, echo_pool=options.debug) | |
self._session = sessionmaker(bind=engine) | |
@classmethod |
#! /usr/bin/python | |
# coding: utf-8 | |
"""Copy table from mysql to sqlite. | |
Require: | |
* SQLAlchemy | |
* MySQLdb or PyMySQL | |
Usage: |
class JsonSerializableMixin(object): | |
""" | |
Converts all the properties of the object into a dict for use in json. | |
You can define the following as your class properties. | |
_json_eager_load : | |
list of which child classes need to be eagerly loaded. This applies | |
to one-to-many relationships defined in SQLAlchemy classes. | |
_base_blacklist : |
class UnhandledExceptionError(Exception): | |
"""The exception could not be handled by the supervisor.""" | |
class SupervisorKilledError(Exception): | |
"""The supervisor was killed.""" | |
class SupervisorAbortedError(Exception): | |
"""The supervisor gave up after maximum number of failures.""" |
import spark.SparkContext | |
import SparkContext._ | |
/** | |
* A port of [[http://blog.echen.me/2012/02/09/movie-recommendations-and-more-via-mapreduce-and-scalding/]] | |
* to Spark. | |
* Uses movie ratings data from MovieLens 100k dataset found at [[http://www.grouplens.org/node/73]] | |
*/ | |
object MovieSimilarities { |
// 4 spaces to 2 spaces | |
%s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g | |
// Tab to 2 spaces | |
:%s/\t/ /g |