Skip to content

Instantly share code, notes, and snippets.

View ralphbean's full-sized avatar

Ralph Bean ralphbean

  • Red Hat, Inc
  • Rochester, NY
View GitHub Profile
@ralphbean
ralphbean / base.py
Created February 9, 2012 14:11
tg2app/lib/base.py
# -*- coding: utf-8 -*-
"""The base Controller API."""
from tg import config
from tg import TGController, tmpl_context
from tg.render import render
from tg import request
from tg.i18n import ugettext as _, ungettext
@ralphbean
ralphbean / view.py
Created February 9, 2012 19:10
working on pyramid views
# view
@view_config(route_name="user_form", renderer="admin/user.html")
def user_form(request):
w = widgets.UserForm
w.fetch_data(request)
mw = tw2.core.core.request_local()['middleware']
mw.controllers.register(w.req(), 'user_submit')
return {'widget': w}
@ralphbean
ralphbean / tween.py
Created February 11, 2012 14:18
tween for removing jquery
from pyramid.settings import asbool
import tw2.core.core
import tw2.jquery
def remove_jq_factory(handler, registry):
""" In order to use this, you need to add the following you myapp/__init__.py:
config.add_tween('myapp.tween.remove_jq_factory')
"""
@ralphbean
ralphbean / .taskrc
Created February 13, 2012 18:20
taskrc
# Files
data.location=/home/threebean/.task
#include /home/threebean/.task/solarized-dark-256.theme
_forcecolor=yes
defaultwidth=160
include /usr/local/share/doc/task/rc/dark-violets-256.theme
report.work_report.description=now
@ralphbean
ralphbean / linkify.py
Created February 21, 2012 19:12 — forked from lmacken/linkify.py
A script to linkify URLs in text
#!/usr/bin/env python
# A simple script that can be used to turn URLs into links
#
# Using within a pipeline:
#
# $ echo 'http://lewk.org' | linkify
# <a href="http://lewk.org">http://lewk.org</a>
#
# Using on a file:
#
function twd_grow_clone(id_prefix, next_num)
{
var clone_node = document.getElementById(id_prefix + '0');
var node = clone_node.cloneNode(true);
var stemlen = id_prefix.length + 1;
var new_prefix = id_prefix + next_num;
var x = twd_get_all_nodes(node);
var old_selector = id_prefix.replace(/:/g, '\\\\:') + '0'
var new_selector = id_prefix.replace(/:/g, '\\\\:') + next_num;
for(var i = 0; i < x.length; i++)
import tw2.qrcode
my_qrcode = tw2.qrcode.QRCodeWidget(
id="demoqr",
data="Test text qrcode. This has a lot of data in it.",
level=9,
width=300,
)
  • Run the tests in python 2. Did they work? If not, quit this project and do another one.
  • Run the tests in python 3. Did they work? If so, you're actually done. This one needs to be marked as "good to go".
  • Run python-modernize.
  • Run the tests in python 2. Do they work?
  • Run the tests in python 3. Do they work?
  • If the above fails, you might try running 3to2 which will make a python3-only version. This is acceptable, but less desirable.
#!/usr/bin/env python
import github2.client
ghc = github2.client.Github()
all_repos, page = [], 0
while True:
new_repos = ghc.repos.list('toscawidgets', page)
if not new_repos:
@ralphbean
ralphbean / pruning.py
Created March 19, 2012 17:59
I'm spending all day pruning code.
#!/usr/bin/env python
import fabulous.image
import urllib
prune = "http://www.gourmet.com/images/food/2008/10/foar-prunedanishes608.jpg"
fname, wat = urllib.urlretrieve(prune)
print fabulous.image.Image(fname)