Skip to content

Instantly share code, notes, and snippets.

View Kroisse's full-sized avatar

Eunchong Yu Kroisse

View GitHub Profile
@Kroisse
Kroisse / gist:1441484
Created December 7, 2011 04:37 — forked from longfin/gist:1441283
Class Factory??
tag_types = ['location', 'category']
class Tag(db.Model, BaseEntityMixIn,
IgnoreDeletionMixIn):
__tablename__ = "tag"
name = db.Column(db.Unicode(255), index=True)
type = db.Column(db.Enum(*tag_types, native_enum=False), index=True)
__mapper_args__ = {'polymorphic_on': type}
from flask import *
class Recorder(object):
def __init__(self):
self._record = []
def __getattr__(self, name):
def method(*args, **kwargs):
if not kwargs and len(args) == 1 and callable(args[0]):
def r(target):
main :: IO ()
main = do
let xs = replicate 4 getLine
head xs >>= print
@Kroisse
Kroisse / model.py
Created June 18, 2012 08:03
Delaying argument evaluation in SQLAlchemy, to avoid circular references
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Widget(Base):
__tablename__ = 'widgets'
id = Column(types.BigInteger, primary_key=True)
@Kroisse
Kroisse / <console>
Created June 18, 2012 08:47
PyPy fails on formatting bool
Python 2.7.2 (0e28b379d8b3, Feb 09 2012, 18:31:14)
[PyPy 1.8.0 with GCC 4.2.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``PyPy is vast, and contains
multitudes''
>>>> print True
True
>>>> print '{0}'.format(True)
1
>>>> print '%s' % True
@Kroisse
Kroisse / autocommit.py
Created September 27, 2012 15:12
(autoflush=True, autocommit=True) considered harmful
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import types
from sqlalchemy.schema import Column
from sqlalchemy import create_engine
Base = declarative_base()
class Widget(Base):
@Kroisse
Kroisse / sierpinski.hs
Created October 31, 2015 09:32
Draw a Sierpinski triangle
module Main where
import Data.List (genericLength, genericReplicate)
import System.Environment (getArgs, getProgName)
import System.Exit (exitSuccess)
sierpinskiRows :: Integer -> [String]
sierpinskiRows 0 = []
sierpinskiRows 1 = ["*"]
sierpinskiRows n
@Kroisse
Kroisse / EXAMPLE.md
Last active December 11, 2015 02:18
Don't use any relative paths in your settings.py
$ django-admin.py startproject temp
$ cd temp
temp$ ls
manage.py* temp/
temp$ python manage.py startapp basic
temp$ vi basic/views.py 
temp$ mkdir templates
temp$ vi templates/home.html
temp$ vi temp/settings.py 
>>> from module import class1
>>> # edit and save module.py
>>> import module
>>> class1 = reload(module).class1