Skip to content

Instantly share code, notes, and snippets.

View theY4Kman's full-sized avatar

Zach Kanzler theY4Kman

View GitHub Profile
nodejs:
pkg.installed:
version: 'whatevers'
###############################################################################
# MY CODE
###############################################################################
class Command(object):
command = None
def __init__(self, arg=None):
self.arg = arg
def get_command(self):
from sqlalchemy import ForeignKeyConstraint
from sqlalchemy.ext.compiler import compiles
@compiles(ForeignKeyConstraint, 'mysql')
def ignore_foreign_keys_for_mysql(constraint, compiler, **kw):
pass
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_BINDS'] = {
'postgres': 'postgresql+psycopg2://wazinit:wazinit@localhost/test_binds',
'mysql': 'mysql://hivelocity:test@localhost/hivelocity_shared',
}
db = SQLAlchemy(app)
@theY4Kman
theY4Kman / query_transform.py
Last active August 29, 2015 14:20
SQLAlchemy query transformations by GET params. An extensible solution.
"""An extensible system for building a SQLAlchemy query based on GET params
Design principles:
- Database operations should be easy to identify
- User input (GET params) should be loosely coupled from models
- Not all operations are valid on all columns (icontains is invalid for FLOAT)
Example:
>>> query = Token.query.with_entities(Token.id)
@theY4Kman
theY4Kman / gulpfile.js
Last active August 29, 2015 14:19
A little helper which makes incremental path generation a cinch
// Helper to simplify incremental generation and storage of paths
var Path = function Path(_path) {
this.value = _path;
};
Path.prototype = {
'toString': function() {
return this.value;
},
'join': function() {
@theY4Kman
theY4Kman / search_dict.py
Last active May 8, 2016 16:39
Ever had an enormous dict you needed to search for a simple string?
import re
def search(d, pattern, name='root'):
if not hasattr(pattern, 'match'):
pattern = re.compile(re.escape(pattern), re.I)
results = []
_keystr = lambda key, item: '%s[%r]' % (key, item)
def _value(v, key):
@theY4Kman
theY4Kman / cache_lock.py
Created March 18, 2015 17:44
Django cache-based lock, originally for distributed Celery tasks
import gevent
from django.core.cache import cache
class CacheLock(object):
"""A lock backed by redis"""
def __init__(self, lock_id, expiry=60 * 5):
"""
:param lock_id: unique key for lock (unique through Django cache)
Routing / AJAX:
http://visionmedia.github.io/superagent/
https://github.com/visionmedia/page.js
https://github.com/flatiron/director
Utilities:
https://lodash.com/
http://momentjs.com/
http://browserify.org/
http://julian.com/research/velocity/
In [19]: \
....:
In [20]: \\
....:
....:
....:
In [21]: \\\
....: