Skip to content

Instantly share code, notes, and snippets.

@shazow
shazow / gist:4227021
Created December 6, 2012 18:48
Closure scopes in JavaScript.
(function() {
// This is a new closure. If things that happen here don't have side-effects on outside scope,
// then whatever happens here will not be visible outside of it.
(function() {
// You can make closures inside of closure (inside of closures). Wee.
})();
})();
@shazow
shazow / v1
Last active June 6, 2017 06:57
post-receive hook to push-deploy with git
#!/bin/bash
# post-receive hook to push-deploy multiple branches using a git repo.
#
# Deploy by pushing $DEPLOY_BRANCH
# Rollback by force-pushing a new reference to $OVERRIDE_TAG
#
# 1. Setup your git repo:
#
# git init --bare
#
@shazow
shazow / develop.screenrc
Created January 5, 2013 23:35
Open development daemons in split gnu screen.
startup_message off
hardstatus alwayslastline
hardstatus string "%= %{r} Quit by hitting: qq"
escape q;
bind q quit
screen -t "Serve HTTP" 1 make serve
screen -t "Serve CSS" 2 make css_watch
@shazow
shazow / autobackup.sh
Last active December 11, 2015 05:18
Database autobackup script.
#!/bin/bash
# Backup all the things, and delete old backups. (Perfect for a nightly cron job.)
# How many old backups should we keep?
NUM_OLD_BACKUPS=5
# Which databases should we worry about?
DATABASE_PREFIX="foo"
##
@shazow
shazow / settings.py
Last active December 14, 2015 09:59
Django settings.py query logging
# ...
LOGGING = {
# ...
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
# ...
},
@shazow
shazow / meta.py
Created March 6, 2013 23:20
My latest SQLAlchemy model base class.
"""SQLAlchemy Metadata and Session object"""
import datetime
import json
import time
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
__all__ = ['Session', 'metadata', 'Model', 'SchemaEncoder']
@shazow
shazow / account.py
Last active December 14, 2015 17:58
My Pyramid class-based view base class.
# A sample view from my upcoming meta-framework.
# You probably won't have things like `request.features` or `api` or `expose_api` etc. Coming soon.
@expose_api('account.create')
def account_create(request):
if request.features.get('invite_required'):
raise APIControllerError("Method not permitted: %s" % account_create.exposed_name)
email, password, password_confirm = get_many(request.params, required=['email'], optional=['password', 'password_confirm'])
@shazow
shazow / api.py
Created March 9, 2013 21:40
My API controller for my Pyramid meta-framework thing.
import json
from pyramid.httpexceptions import HTTPSeeOther, HTTPBadRequest
from pyramid.response import Response
from jobcupid.lib.exceptions import APIControllerError, LoginRequired
from jobcupid.model.meta import SchemaEncoder
API_METHOD_MAP = {}
@shazow
shazow / salt.md
Last active December 15, 2015 06:09
Questions & Feedback for SaltStack

Questions & Feedback for SaltStack

I've read as much introduction documentation as I can find. Here are some outstanding questions that I'm still seeking answers for. Links or answers in comments are welcome.

Questions

  1. Is it possible to define salt configurations for different server roles (e.g. webserver, database, loadbalancer, etc) which could be distributed to an arbitrary number of servers? (e.g. one server that is a {webserver,database,loadbalancer} or three servers where each is one of the kid.) I have a feeling this has something to do with Grains, but not sure how.

    Answered: Use grains or nodegroups.

@shazow
shazow / sa_enum_type.py
Created April 28, 2013 22:20
SQLAlchemy custom Enum type that uses Integer-based indexing.
from sqlalchemy import types
class Enum(types.TypeDecorator):
impl = types.Integer
def __init__(self, value_map, strict=True, *args, **kw):
"""Emulate Enum type with integer-based indexing.
value_map: