Skip to content

Instantly share code, notes, and snippets.

View doobeh's full-sized avatar

Anthony Plunkett doobeh

View GitHub Profile
@doobeh
doobeh / python
Created December 21, 2011 19:44
Basic Reportlab barcode/label code.
x = marginLeft + (j*labelWidth)
y = marginTop + (i*labelHeight)
c.setFillColorCMYK(0,0,0,1)
c.setFont("Helvetica",12)
c.drawString(x + (10 * mm), y + (21 * mm), item.product.upper())
drawing = Drawing()
barcode = Ean13BarcodeWidget()
barcode.value = str(item.upc[1::])
barcode.barHeight = 12 * mm
@doobeh
doobeh / ipn.py
Created February 20, 2012 15:39
PayPal Flask IPN Engine
# -*- coding: utf-8 -*-
"""
IPN Engine
~~~~~~~~~~
PayPal's Instant Payment Notification (IPN) helps integrate PayPal more
deeply into your web application. When activated, PayPal will send a
POST request to a specified URL when a transaction's status changes.
The most obvious use is to trigger a state change, enable an account,
@doobeh
doobeh / expand.py
Created May 10, 2012 18:31
Expand a UPC8 to EAN13 with Python
# expands a condensed UPC to an EAN. Expects the supplied upc to exclude the
# check-digit. Obviously you could test for length==6 and crop that check digit
# off if the barcode scanner can't be configured to supress it.
#
# Our Symbol PDT scanners send 'ssss' on the front of a scanned UPC, so this also
# strips that out, but it shouldn't cause any problems for a more standard barcode
# scanner.
upc = "0413924" # Kikkoman Soy Sauce
@doobeh
doobeh / app.wsgi
Created May 31, 2012 19:58
General WSGI setup for Apache/mod_wsgi & Flask
activate_this = '/home/user/environments/website/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys, os
abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)
from app import app as application
@doobeh
doobeh / app.wsgi
Created May 31, 2012 19:58
General WSGI setup for Apache/mod_wsgi & Flask
activate_this = '/home/user/environments/website/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys, os
abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)
from app import app as application
@doobeh
doobeh / gist:3146222
Created July 19, 2012 19:30
Bootstrap Form Rendering for Jinja2
{% macro bs_field(field,help=False,icon=False,counter=False) %}
<div class="control-group{% if field.errors %} warning{% endif %}">
{% if field.type in ('EmailField','PasswordField','TextField','TextAreaField','FileField','QuerySelectFieldCustom','DecimalField','SelectField') %}
{{ field.label(class="control-label") }}
<div class="controls">
{% if icon %}
<div class="input-prepend">
<span class="add-on"><i class="{{ icon }}"></i></span>
{% endif %}
from flask import Flask, render_template, abort, current_app
app = Flask(__name__)
@app.route('/')
def home():
return 'home'
from bp import mod
app.register_blueprint(mod,cows='moo')
@doobeh
doobeh / gist:3188318
Created July 27, 2012 14:27
Installing WeasyPrint on Windows

Installing WeasyPrint on Windows

WeasyPrint converts HTML including images to PDF, it's cross platform but Windows requires a decent amount of massaging to persuade it to work.

To install Pango and Cairo download the [all in one bundle][GTK] of the GTK+ stack and extract the archive to C:\GTK.

You'll need to add the GTK bin folder to your system path so the various

@doobeh
doobeh / example.py
Created November 6, 2012 19:42
Quick S3 Example
def s3_upload(filename):
# Destination Filename
destination_filename = os.path.basename(filename)
# Connect to S3
conn = boto.connect_s3(app.config["S3_KEY"], app.config["S3_SECRET"])
b = conn.get_bucket(app.config["S3_BUCKET"])
# Upload the File
@doobeh
doobeh / stringio_example.py
Created November 6, 2012 19:59
StringIO Example
stringio_object = your_string_io_object
destination_filename = 'whatever'
# Connect to S3
conn = boto.connect_s3(app.config["S3_KEY"], app.config["S3_SECRET"])
b = conn.get_bucket(app.config["S3_BUCKET"])
# Upload the File
sml = b.new_key("/".join([app.config["S3_UPLOAD_DIRECTORY"],destination_filename]))
sml.set_contents_from_string(stringio_object.getvalue())