Skip to content

Instantly share code, notes, and snippets.

View ryaninhust's full-sized avatar

Bowen Yuan ryaninhust

  • NYC
  • 19:22 (UTC -04:00)
View GitHub Profile
@ericdouglas
ericdouglas / super-tip.txt
Last active February 25, 2024 10:09
Change 4 spaces to 2 spaces indentation and change tab to spaces - Vim tip
// 4 spaces to 2 spaces
%s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g
// Tab to 2 spaces
:%s/\t/ /g
@MLnick
MLnick / MovieSimilarities.scala
Created April 1, 2013 17:49
Movie Similarities with Spark
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 {
@jrydberg
jrydberg / supervisor.py
Created November 14, 2012 17:28
simple gevent supervisor
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."""
@onlytiancai
onlytiancai / python_infrastructure.md
Created October 12, 2012 08:55
python 基础设施讨论贴

python项目通用组件和基础服务

很多公司都大量使用了python,其中有一些开发规范,code guidline, 通用组件,基础框架是可以共用的。

每个公司都自己搞一套, 太浪费人力,我想开一帖和大家讨论一下这些python基础设施的搭建。

原则是我们尽量不重新发明轮子,但开源组件这么多,也要有个挑选的过程和组合使用的过程,在这里讨论一下。

另一方面,有些开源组件虽然强大,但我们不能完全的驾驭它,或只使用其中很少的一部分,我们就可以考虑用python实现一个简单的轮子,可控性更强,最好不要超过300行代码。

@goodwillcoding
goodwillcoding / gist:3808931
Created October 1, 2012 01:17
JSON Serializable SQLAlchemy Object
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 :
@methane
methane / mylite.py
Created June 22, 2012 12:27
Copy table from mysql to sqlite
#! /usr/bin/python
# coding: utf-8
"""Copy table from mysql to sqlite.
Require:
* SQLAlchemy
* MySQLdb or PyMySQL
Usage:
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active July 22, 2024 17:28
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@dmitric
dmitric / backend.py
Created March 24, 2012 18:06
SqlAlchemy usage with tornado backend
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
@ghoseb
ghoseb / gevent_example.py
Created July 27, 2011 09:27
Gevent spawn / link example
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):