Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Vanasco jvanasco

View GitHub Profile
@jvanasco
jvanasco / deploy.py
Last active May 9, 2016
Automated (mostly) Trac Installation for Dreamhost
View deploy.py
import os
username = 'johndoe'
svndomain = 'svn.example.com'
www_root = "/home/%(username)s/webroot/%(svndomain)s/" % {'username': username, 'svndomain': svndomain}
trac_root = "/home/%(username)s/svn_trac/" % {'username': username}
svn_root = "/home/%(username)s/svn" % {'username': username}
shared_chrome_dir = "/home/%(username)s/svn_trac/trac-deploy/htdocs" % {'username': username}
sites = [i.strip() for i in open('trac_sites.txt').readlines()]
@jvanasco
jvanasco / client.py
Last active Apr 20, 2016
statsd max connections
View client.py
class StatsClient(StatsClientBase):
"""A client for statsd."""
def __init__(self, host='localhost', port=8125, prefix=None,
maxudpsize=512, ipv6=False):
"""Create a new client."""
fam = socket.AF_INET6 if ipv6 else socket.AF_INET
family, _, _, _, addr = socket.getaddrinfo(
host, port, fam, socket.SOCK_DGRAM)[0]
self._addr = addr
@jvanasco
jvanasco / sqlalchemy_relation.py
Last active Apr 4, 2016
sqlalchemy relationship
View sqlalchemy_relation.py
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Use this file to build your own SSCCE
# SSCCE = Short, Self Contained, Correct (Compatible) Example
# see http://sscce.org/
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
View data.sql
CREATE TABLE t_b (id INT PRIMARY KEY, timestamp_event INT);
CREATE TABLE t_a (id INT PRIMARY KEY, id_latest_b INT REFERENCES t_b(id));
CREATE TABLE t_a2b (id_a REFERENCES t_a(id), id_b REFERENCES t_b(id), PRIMARY KEY (id_a, id_b));
INSERT INTO t_a VALUES (1, NULL);
INSERT INTO t_a VALUES (2, NULL);
INSERT INTO t_a VALUES (3, NULL);
INSERT INTO t_a VALUES (4, NULL);
INSERT INTO t_b VALUES (1, 10);
INSERT INTO t_b VALUES (2, 20);
INSERT INTO t_b VALUES (3, 30);
View logger_factory.js
if (typeof console === 'undefined') {
window.console = {
log: function () {}
};
}
function loggerFactory(label) {
return (function () {
var timestamp = function () {};
timestamp.toString = function () {
@jvanasco
jvanasco / feedgen_facebook.py
Last active Mar 9, 2016
This creates an extension that can be used with my fork of feedgen [https://github.com/jvanasco/python-feedgen/tree/feature-load_extension] It just adds a content element that renders as encoded cdata.
View feedgen_facebook.py
# -*- coding: utf-8 -*-
'''
feedgen_facebook.instant_article
~~~~~~~~~~~~~~~~~~~
Extends the FeedGenerator to produce Facebook InstantArticle.
:copyright: 2016, Jonathan Vanasco <jonathan@findmeon.com>
:license: FreeBSD
View feedgen_facebook.py
# -*- coding: utf-8 -*-
'''
feedgen_facebook.instant_article
~~~~~~~~~~~~~~~~~~~
Extends the FeedGenerator to produce Facebook InstantArticle.
:copyright: 2016, Jonathan Vanasco <jonathan@findmeon.com>
:license: FreeBSD
View feedgen_facebook.py
# -*- coding: utf-8 -*-
'''
feedgen_facebook.instant_article
~~~~~~~~~~~~~~~~~~~
Extends the FeedGenerator to produce Facebook InstantArticle.
:copyright: 2016, Jonathan Vanasco <jonathan@findmeon.com>
:license: FreeBSD
@jvanasco
jvanasco / parse_flake8.py
Last active Feb 18, 2016
Flake8 output was giving me a headache, so i wrote this quick parser. It will convert a `--file` of flake8 text to a "checklist" format , json or pretty-printed json.
View parse_flake8.py
import argparse
import os.path
import pprint
"""
flake8 parser.
this is a quick and dirty tool.
Flake8 output was giving me a headache, so i wrote this quick parser. It will convert a `--file` of flake8 text to a "checklist" format , json or pretty-printed json.
@jvanasco
jvanasco / parse_flake8.py
Created Feb 18, 2016
Flake8 output was giving me a headache, so i wrote this quick parser.
View parse_flake8.py
import argparse
import os.path
import pprint
_sample_data = """/Users/me/path/to/project/files/lib/data/bar.py:52:1: W293 blank line contains whitespace
/Users/me/path/to/project/files/lib/data/foo.py:101:1: W293 blank line contains whitespace
/Users/me/path/to/project/files/lib/utils/date.py:328:5: F811 redefinition of unused 'currentYear' from line 306
/Users/me/path/to/project/files/lib/utils/date.py:331:5: F811 redefinition of unused 'currentMonth' from line 310
/Users/me/path/to/project/files/lib/utils/date.py:334:5: F811 redefinition of unused 'currentDay' from line 314
/Users/me/path/to/project/files/lib/utils/foo.py:595:1: W293 blank line contains whitespace