Skip to content

Instantly share code, notes, and snippets.

View storborg's full-sized avatar

Scott Torborg storborg

View GitHub Profile
import os.path
import requests
from PIL import Image
lowest_x = 928
highest_x = 1002
lowest_y = -1088
highest_y = -1069
from pyweaving import Draft
from pyweaving.render import ImageRenderer
# 1-indexed
threading = [
4, 3,
6, 5,
8, 7,
1, 2, 3, 4, 5, 6, 7, 8,
2, 1,
@storborg
storborg / example-cmd-wrapper.py
Last active August 29, 2015 14:03
How to use Pyramid to turn a Python function into a local "GUI" app
"""
The basic idea here is to wrap a Python function (in the case below, it is
``do_programming_crap()``) and make a basic GUI interface to call that
function.
Theoretically, it's much easier to create a packaged executable which is only
dependent on Pyramid vs. depending on something like PyGTK, WxWidgets, Kivy,
SDL, whatever.
"""
--- src/dumb/dumb_input.c.orig 2002-10-26 20:44:10.000000000 -0500
+++ src/dumb/dumb_input.c 2012-07-26 07:27:34.000000000 -0500
@@ -79,7 +79,7 @@
/* Read one line, including the newline, into s. Safely avoids buffer
* overruns (but that's kind of pointless because there are several
* other places where I'm not so careful). */
-static void getline(char *s)
+static void frotz_getline(char *s)
{
int c;
>>> from mako.template import Template
>>>
>>> templ = Template('''
... % for el in els:
... <p>${el}</p>
... % else:
... <p>No elements.</p>
... % endfor
... ''')
>>>
" Python indent file
" Language: Python
" Maintainer: Eric Mc Sween <em@tomcom.de>
" Original Author: David Bustos <bustos@caltech.edu>
" Last Change: 2012 Aug 15
"
" Updated 2012 Aug 15 by Scott Torborg <storborg@gmail.com>
" - Adds support for more esoteric PEP8 indentation conditions, particularly
" E125 and E127.
#include <pthread.h>
#include <stdio.h>
#define NUM_WAITING_THREADS 20
#define NUM_WORKING_THREADS 20
pthread_mutex_t quux;
void waste_some_time(int cycles) {
@storborg
storborg / sharecounts.py
Created February 27, 2012 18:08
getting social media counts for urls
import simplejson as json
from urllib import urlencode
import requests
import re
def facebook_likes_for_url(url):
r = requests.get('http://graph.facebook.com/%s' % url)
obj = json.loads(r.content)
return obj['likes']
@storborg
storborg / datepicker-configuration.js
Created February 9, 2012 19:18
Reconfigure the bootstrap datepicker to use a different date format globally.
(function() {
/* Update date_input plugin so that MM/DD/YYYY format is used. */
$.extend($.fn.datepicker.defaults, {
parse: function (string) {
var matches;
if ((matches = string.match(/^(\d{2,2})\/(\d{2,2})\/(\d{4,4})$/))) {
return new Date(matches[3], matches[1] - 1, matches[2]);
} else {
return null;
}
"""
Poor man's firehose: use your friends to grab twitter data, bypassing the IP
rate limit by using a bunch of different clients. This works by serving up
javascript which will make the client grab a JSONP feed from twitter and then
re-submit it to your server.
Obviously, modify this to be more useful, e.g. by setting the page to
auto-refresh itself or use long polling to get more URLs to fetch.
Call this like: