Skip to content

Instantly share code, notes, and snippets.

@jayd3e
jayd3e / enum.go
Created September 16, 2017 15:41
var (
ProductionEnvironmentType EnvironmentType = "production"
DevelopmentEnvironmentType = "development"
TestingEnvironmentType = "testing"
)
int a = 0;
// In C++ there is copy initialization
int b = a;
// And direct initialization
int c(0);
// They are not the same, and have different behavior. People tend to favor
// copy initialization, except for direct initialization in a few cases.
// See this SO answer http://stackoverflow.com/a/4293816
def dictify(variables):
# replace all dicts with AttrDicts
return {key: AttrDict(val) if isinstance(val, dict) else val for key, val in variables.items()}
class AttrDict(dict):
# only called if k not found in normal places
def __getattr__(self, k):
try:
# Throws exception if not in prototype chain
def humanize(size_bytes):
"""
Format a size in bytes into a 'human' file size, e.g. bytes, KB, MB, GB, TB, PB
Note that bytes/KB will be reported in whole numbers but MB and above will have greater precision
e.g. 1 byte, 43 bytes, 443 KB, 4.3 MB, 4.43 GB, etc
"""
if size_bytes == 1:
# because I really hate unnecessary plurals
return "1 byte"
class RouteNamesViewPredicate(object):
def __init__(self, route_names, config):
self.route_names = route_names
def text(self):
return 'route_names = %s' % (self.route_names)
phash = text
def __call__(self, context, request):
17:21:40.335134 upload-debug-info.go:48: error adding upstart-flynn-host.log: open /var/log/upstart/flynn-host.log: permission denied
17:21:40.335286 upload-debug-info.go:48: error adding tmp-flynn-host.log: open /tmp/flynn-host.log: no such file or directory
17:21:40.335700 upload-debug-info.go:53: Get http://127.0.0.1:1111/services/flynn-host/leader: dial tcp 127.0.0.1:1111: connection refused
17:21:40.505630 upload-debug-info.go:60: could not capture command 'virsh -c lxc:/// list': exit status 1
17:21:40.510062 upload-debug-info.go:60: could not capture command 'virsh -c lxc:/// net-list': exit status 1
17:21:40.684832 upload-debug-info.go:71: Debug information uploaded to: https://gist.github.com/42194ef2ddb91b5410fe
sudo -u postgres psql -c "drop database redd";
sudo -u postgres psql -c "create database redd";
sudo -u postgres psql -c "grant all privileges on database clusterflunk to jayd3e";
sudo -u postgres psql -c "insert into networks(created, name, aliases, domain) values (now(), 'School of Hard Knocks', '', 'knocks.edu')" clusterflunk;
sudo -u postgres psql -c "insert into auth_users(created, username, password) values (now(), 'stompy', 'ddb7859d6ee2b49afcca946d6d1d605a5fb0c30c09507aef3d1a3511f824c041568895baee5733a0')" clusterflunk;
sudo -u postgres psql -c "insert into users(created, username, network_email, avatar_set, cached_avatar_set, active_network_id, auth_user_id) values (now(), 'stompy', 'jayd3e@knocks.edu', false, false, 1, 1)" clusterflunk;
sudo -u postgres psql -c "insert into memberships(user_id, network_id) values (1,1)" clusterflunk;
curl -c cookies -XGET http://localhost:6543/api/1/login
curl -b cookies -XGET http://localhost:6543/api/1/posts
rm cookies
curl -XGET http://localhost:6543/api/1/posts
#
# Pyramid is choosing this view
#
from pyramid.view import forbidden_view_config
from pyramid.httpexceptions import HTTPFound
@forbidden_view_config()
def login_redirect(request):
@event.listens_for(Engine, "handle_error")
def handle_exception(context):
if isinstance(context.original_exception,
psycopg2.OperationalError) and \
"SSL disconnect" in str(context.original_exception):
context.is_disconnect=True