Skip to content

Instantly share code, notes, and snippets.

@EliAndrewC
EliAndrewC / gist:10328292
Created April 9, 2014 23:08
Sideboard RPM specfile
# We are assuming EL5 (<EL5 is not supported), since we don't have EL6 python27 packages yet.
%define __python_pkgname python27
%define __python_exe python2.7
# Override the global %{__python} macro to point to our own python version
%define __python %{_bindir}/%{__python_exe}
# Specify the distribute package to use
%define setuptools_package python27-distribute
# This is the "package name" that we use in naming the /etc, /var/run, /var/log, subdirs.
%define PACKAGE sideboard
@EliAndrewC
EliAndrewC / gist:953ee594ca4a46e17a92
Created July 2, 2014 20:57
some paver packaging stuff
import time
import os
import re
import shutil
import warnings
from ConfigParser import SafeConfigParser, NoOptionError
import pkg_resources
from paver.path import path
@EliAndrewC
EliAndrewC / dump_staffers.py
Created July 29, 2014 01:58
Import script for getting M12 staffers into M13 database
from common import *
import constants
from custom_tags import time_day
uninvited = [] # redacted for public gist
val2name = {}
for _name, _val in constants.__dict__.items():
if re.match('^[_A-Z0-9]+$', _name) and isinstance(_val, int):
val2name[_val] = _name
@EliAndrewC
EliAndrewC / syslog
Created September 23, 2014 03:35
Traceback from syslog for group member registration error
Sep 22 10:20:19 prime 2014-09-22 10:20:19,244 [ERROR] cherrypy.error.140059498634376: [22/Sep/2014:10:20:19] HTTP Traceback (most recent call last):
File "/usr/local/uber13/env/lib/python3.4/site-packages/SQLAlchemy-0.8.5-py3.4.egg/sqlalchemy/engine/base.py", line 867, in _execute_context
context)
File "/usr/local/uber13/env/lib/python3.4/site-packages/SQLAlchemy-0.8.5-py3.4.egg/sqlalchemy/engine/default.py", line 326, in do_execute
cursor.execute(statement, parameters)
psycopg2.DataError: invalid input syntax for uuid: "None"
LINE 3: WHERE "group".id = 'None'
^
The above exception was the direct cause of the following exception:
@EliAndrewC
EliAndrewC / config_dump.py
Created April 26, 2015 04:47
Result of "sep print_config"
{'admin_email': 'Eli Courtwright <eli@courtwright.org>',
'age_groups': {'age_unknown': {'can_register': True,
'can_volunteer': True,
'consent_form': False,
'desc': 'age unknown',
'discount': 0,
'wristband_color': ''},
'over_21': {'can_register': True,
'can_volunteer': True,
@EliAndrewC
EliAndrewC / development.ini
Created April 26, 2015 04:49
Current development.ini on the test server
path = "/uber"
hostname = "50.56.242.7"
url_root = "http://50.56.242.7:8282"
dev_box = True
send_emails = False
collect_exact_birthdate = True
event_name = "MAGStock"
organization_name = "MAGStock"
groups_enabled = False
# Current version:
def csv_file(func):
@wraps(func)
def csvout(self, session):
cherrypy.response.headers['Content-Type'] = 'application/csv'
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=' + func.__name__ + '.csv'
writer = StringIO()
func(self, csv.writer(writer), session)
return writer.getvalue().encode('utf-8')
@EliAndrewC
EliAndrewC / PerlHate
Last active August 29, 2015 14:24
What I dislike about Perl
My main problem with Perl is references and contexts. Most of the experienced programmers I've worked with find themselves unable to write or debug code that requires the use of these Perl concepts.
For example, my co-workers and I find it easy and intuitive to work with lists in Python:
xs = [5, 6]
xs.append(7)
print xs[2] # prints 7
xs.append([]) # easy to append lists to other lists
xs[3].append(6) # easy to append to the inner list
some_func(12, "hello", xs, True) # easy to pass to a function
@EliAndrewC
EliAndrewC / __init__.py
Last active September 5, 2015 04:28
Using Flask with Sideboard
"""
To use Flask with Sideboard, make a plugin and then put this file in the plugin
module's directory, e.g. sideboard/plugins/paper_bag/paper_bag/__init__.py and
the Flask site will be available at https://localhost:4443/uber/paper_bag
"""
import cherrypy
from cherrypy import wsgiserver
from flask import Flask
app = Flask(__name__)
@EliAndrewC
EliAndrewC / infinite_redirect.py
Last active March 17, 2016 21:48
Example of CherryPy going into an infinite redirect loop
import cherrypy
class Root(object):
@cherrypy.expose
def index(self):
raise cherrypy.HTTPRedirect('/')
if __name__ == '__main__':
cherrypy.quickstart(Root())