Skip to content

Instantly share code, notes, and snippets.

View shangliuyan's full-sized avatar

leo shang shangliuyan

View GitHub Profile
@e000
e000 / socks.py
Created March 14, 2011 20:21
socksipy + urllib2 handler
"""SocksiPy - Python SOCKS module.
Version 1.00
Copyright 2006 Dan-Haim. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@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):
@yosemitebandit
yosemitebandit / send_pdf_with_boto_ses.py
Created June 6, 2012 17:56
send PDF attachment with boto and SES
''' quick example showing how to attach a pdf to multipart messages
and then send them from SES via boto
'''
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import boto
# Metaprogramming/Singleton.py
class Singleton(type):
instance = None
def __call__(cls, *args, **kw):
if not cls.instance:
cls.instance = super(Singleton, cls).__call__(*args, **kw)
return cls.instance
class ASingleton(object):
@mlavin
mlavin / NOTES.rst
Created September 23, 2013 14:17
Celery Late Ack Example

Running the Example

Start the worker:

celery -A tasks worker --loglevel=info -c 2 --pidfile=celery.pid

In another terminal send 6 tasks:

python script.py
@pckujawa
pckujawa / a4.py
Created December 15, 2013 20:17
Simple audio classifier (speech vs music) using scikit-learn (Naive Bayes classifier). Made for Multimedia Processing course.
""" usage:
a4.py train TRAIN_FEATURE_FILE [--new] [--validate]
a4.py classify MUSIC_FEATURE_FILE
The files should be CSV with 6 columns, the last of which is the target/label/class (or empty, if classifying), and the first of which is ignored.
"""
#-------------------------------------------------------------------------------
# Name: Pat Kujawa
# Purpose: MM audio classification asn 4
#-------------------------------------------------------------------------------
@jqlblue
jqlblue / sentry.conf.py
Created December 18, 2013 06:38
sentry config example
# This file is just Python, with a touch of Django which means you
# you can inherit and tweak settings to your hearts content.
from sentry.conf.server import *
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
'default': {
# You can swap out the engine for MySQL easily by changing this value
@johnpaulhayes
johnpaulhayes / celery_tasks.py
Created January 13, 2014 16:22
correct task definitions when using tasks by name.
from celery_app import Celery
celery = Celery("tasks", backend="amqp", broker="amqp://guest@localhost")
@celery.task(name='test_task')
def test_task():
return "boom!"
function scroll_to(splash, x, y)
local js = string.format(
"window.scrollTo(%s, %s);",
tonumber(x),
tonumber(y)
)
return splash:runjs(js)
end
@drgarcia1986
drgarcia1986 / __main__.py
Last active August 9, 2023 21:20
Example of OAuth2 autentication server with Client Credentials grant (using python-oauth2 and tornado)
# !/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Diego Garcia'
import tornado.web
import tornado.ioloop
import oauth2.tokengenerator
import oauth2.grant
import oauth2.store.redisdb
import oauth2.store.mongodb