Skip to content

Instantly share code, notes, and snippets.

# not actually tested
from gevent.queue import Queue
from gevent.pool import Pool
class GreenPile(object):
def __init__(self, size_or_pool=1000):
if isinstance(size_or_pool, Pool):
self.pool = size_or_pool
@maxcountryman
maxcountryman / kaa.py
Created November 15, 2010 01:35
A very simple non-blocking IRC bot using gevent
import gevent
from gevent import socket, queue
from gevent.ssl import wrap_socket
import logging
logger = logging.getLogger('irc')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
@progrium
progrium / gist:956006
Created May 4, 2011 20:50
Greenlet exception handling in gevent
import gevent
import gevent.pool
class GroupWithExceptionCatching(gevent.pool.Group):
def __init__(self, *args):
super(GroupWithExceptionCatching, self).__init__(*args)
self._error_handlers = {}
def _wrap_errors(self, func):
"""Wrap a callable for triggering error handlers
@jmoiron
jmoiron / crawler.py
Created May 27, 2011 20:37
Simple gevent/httplib2 web crawler.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple async crawler/callback queue based on gevent."""
import traceback
import logging
import httplib2
import gevent
@denik
denik / ServerRack.py
Created June 5, 2011 09:31
class for managing multiple servers in gevent
# Class for managing multiple servers or anything with start() and stop() methods
class ServerRack(object):
def __init__(self, servers):
self.servers = servers
def start(self):
started = []
try:
@drewww
drewww / client.py
Created November 28, 2011 21:48
Connect to socket.io server from python, using websocket
#!/usr/bin/env python
# encoding: utf-8
"""
client.py
Based heavily on:
- https://github.com/mtah/python-websocket/blob/master/examples/echo.py
- http://stackoverflow.com/a/7586302/316044
Created by Drew Harry on 2011-11-28.
@richard-flosi
richard-flosi / bottle-cors.py
Created September 26, 2012 16:55
Bottle with Cross-origin resource sharing (CORS)
"""
Example of setting up CORS with Bottle.py.
"""
from bottle import Bottle, request, response, run
app = Bottle()
@app.hook('after_request')
def enable_cors():
"""
@mmohiudd
mmohiudd / CustomManager.py
Created October 17, 2012 03:13
MySQL INSERT … ON DUPLICATE KEY UPDATE with django 1.4 for bulk insert
import datetime
from pprint import pprint
from django.db import models, signals
from django.utils import timezone
import django.dispatch
{"nodes":[
{"name":"Agricultural 'waste'"},
{"name":"Bio-conversion"},
{"name":"Liquid"},
{"name":"Losses"},
{"name":"Solid"},
{"name":"Gas"},
{"name":"Biofuel imports"},
{"name":"Biomass imports"},
{"name":"Coal imports"},
@chrislkeller
chrislkeller / README.md
Last active March 13, 2018 15:19
A pair of python scripts to create a flat json file from a given csv file that can be used in a handlebars.js template.

Snippets: Build a flat json file for handlebars.js template or jquery-vertical-timelines

UPDATED I've made some updates to the handlebars-json.py script.

  • Script now accepts a "usage" argument for "handlebars" or "timeline" or "array"
  • Script assumes a header row and strips underscores and spaces and converts header fields to lowercase when creating keys.
  • Because the resulting JSON file can also be used to power Vertical Timelines, I've re-named the script to csv-to-json.py.
  • The handlebars-json-csvkit.py script remains unchanged. I will attempt to re-work it to create handlebars or timeline JSON in the coming weeks.

See more in the Usage section below.