Skip to content

Instantly share code, notes, and snippets.

View aryaniyaps's full-sized avatar
🎯
Focusing

Aryan Iyappan aryaniyaps

🎯
Focusing
View GitHub Profile
@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)
@parhammmm
parhammmm / fields.py
Created September 9, 2012 15:41
Custom django field for storing hex colours
import re
from django import forms
from django.db import models
class ColourFormField(forms.IntegerField):
default_error_messages = {
'invalid': 'Enter a valid colour value: e.g. "#ff0022"',
}
def __init__(self, *args, **kwargs):
@adunkman
adunkman / index.html
Created January 14, 2012 15:28
Relay messages from RabbitMQ to a browser using Socket.io
<!DOCTYPE html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
(function () {
var onMessage = function (data) {
// Do something with the message data
};