Skip to content

Instantly share code, notes, and snippets.

@btubbs
btubbs / Makefile
Created April 9, 2015 21:47
Makefile for Mettle, a soon-to-be-open-sourced system for executing and monitoring ETL jobs. It integrates the installation of dependencies from pip, npm, and bower, and handles compiling React's JSX code into JS. There are also helpers for the system's Postgres and RabbitMQ backends.
.PHONY: dbsetup clean_files clean_rabbit clean migrate dev js
# Both Python and Node programs will be put here.
BIN=$(shell dirname `which python`)
STATIC_DIR=mettle/static
JSX_DIR=$(STATIC_DIR)/jsx
# Our React components have dependencies on each other. This ordering is important.
JSX_MODULES=jobs targets runs pipelines services app
JSX_TARGETS=$(foreach module,$(JSX_MODULES),$(JSX_DIR)/$(module).js)
@mmerickel
mmerickel / main.py
Last active August 17, 2016 20:09
sqlalchemy with no threadlocals
from pyramid.config import Configurator
from pyramid.view import view_config
def main(global_config, **app_settings):
config = Configurator(settings=app_settings)
config.include('.model')
config.scan(__name__)
return config.make_wsgi_app()
@mmerickel
mmerickel / pyramid_services.py
Last active August 29, 2015 14:04
pyramid services
from pyramid.interfaces import IRequest
from zope.interface.registry import Components
def includeme(config):
config.add_request_method(find_service)
config.add_request_method(lambda _: Components(), 'service_cache',
reify=True)
config.add_directive('register_service', register_service)
config.add_directive('register_service_factory', register_service_factory)
@zzzeek
zzzeek / gist:8443477
Last active January 27, 2022 03:18
expands upon the SQLAlchemy "test rollback fixure" at http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#joining-a-session-into-an-external-transaction to also support tests that have any combination of ROLLBACK/COMMIT within them, by ensuring that the Session always runs transactions inside of a savepoint.
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# a model
class Thing(Base):
__tablename__ = 'thing'
id = Column(Integer, primary_key=True)
@mmerickel
mmerickel / README.rst
Last active December 19, 2015 12:49
A workflow for docker that separates build-time dependencies from run-time dependencies.

A workflow for docker that separates build-time dependencies from run-time dependencies.

Create the image used for building apps.

docker build -t pybuilder pybuilder

Create the image used for running apps.

@SavinaRoja
SavinaRoja / sudokubot.py
Last active December 11, 2015 20:48
A bot for solving Sudoku Puzzles. Currently works only on linux, and automated OCR is dubious. Accepts user input to discover the board then automates the input of the solution.
#! usr/bin/python
"""
A bot for solving Sudoku Puzzles. It uses PyUserInput for cross-platform
keyboard and mouse support. It supplies the pymouse and pykeyboard modules.
Using OCR may be a upcoming feature.
The first step is to define the game window so that the script can click and
type appropriately.
@inklesspen
inklesspen / README.md
Last active September 6, 2023 17:11
Fast and flexible unit tests with live Postgres databases and fixtures

(This gist is pretty old; I've written up my current approach to the Pyramid integration on this blog post, but that blog post doesn't go into the transactional management, so you may still find this useful.)

Fast and flexible unit tests with live Postgres databases and fixtures

I've created a Pyramid scaffold which integrates Alembic, a migration tool, with the standard SQLAlchemy scaffold. (It also configures the Mako template system, because I prefer Mako.)

I am also using PostgreSQL for my database. PostgreSQL supports nested transactions. This means I can setup the tables at the beginning of the test session, then start a transaction before each test happens and roll it back after the test; in turn, this means my tests operate in the same environment I expect to use in production, but they are also fast.

I based my approach on [sontek's blog post](http://sontek.net/blog/

@Nezzerath
Nezzerath / simple irc python bot
Created January 9, 2013 09:05
python simple irc bot
import sys
import socket
import string
import os
import threading
import time
import random
windowtitle = "Nezzbot IRC Client"
from os import system
system("title "+windowtitle)
@Nurdok
Nurdok / python_conversion.md
Last active December 16, 2022 03:45
Python Conversion

Python Number Conversion Chart

From To Expression
@kennethreitz
kennethreitz / hstore.py
Created July 6, 2012 08:41
PostgreSQL hstore + SQLAlchemy
import collections
import sqlalchemy.types
class Hstore(sqlalchemy.types.UserDefinedType, sqlalchemy.types.MutableType):
"""The ``hstore`` type that stores a dictionary. It can take an any
instance of :class:`collections.Mapping`.
It can be extended to store other types than string e.g.::