Skip to content

Instantly share code, notes, and snippets.

View jsocol's full-sized avatar
🙃
for oss: hoping to get back to a monthly check-in/update cadence

James Socol jsocol

🙃
for oss: hoping to get back to a monthly check-in/update cadence
View GitHub Profile
@jsocol
jsocol / data-uri.py
Created July 18, 2011 14:48
Give an image, get a data-uri
#!/usr/bin/env python
"""Command line script to convert a file, usually an image, into a data URI
for use on the web."""
import base64
import mimetypes
import os
import sys
@jsocol
jsocol / ClientStatsD.js
Created August 3, 2011 15:46 — forked from chowse/ClientStatsD.js
StatsD for Client-Side Interactions
if (!Date.now) {
Date.now = function() {
return (new Date()).getTime();
};
}
var StatsD = (function($, undefined) {
@jsocol
jsocol / jsocol-master-whoa
Created August 23, 2011 13:52
output of `git lg`
[james ((c0ff882...)) kitsune]$ git lg -15
* c0ff882 - (HEAD, origin/master, origin/HEAD) Merge branch 'remove_long_filename' of github.com:readevalprint/kitsune into remove_long_filename (14 hours ago) <Tim Watt
|\
| * f3837cb - (tim/remove_long_filename) removed (correct) gallery tests (14 hours ago) <Tim Watts :timw>
| |\
| | * 5baa3a0 - removed gallery tests (15 hours ago) <Tim Watts :timw>
| * | cd91d23 - removed (correct) gallery tests (14 hours ago) <Tim Watts :timw>
| |/
| * 9619f86 - removed file and test (4 days ago) <Tim Watts :timw>
* | 82c5e8c - Merge branch 'master' of github.com:jsocol/kitsune into remove_long_filename (14 hours ago) <Tim Watts :timw>
@jsocol
jsocol / forms.py
Created September 21, 2011 03:50
Form-based user settings
from django import forms
from tower import ugettext_lazy as _lazy
class SettingForm(forms.Form):
auto_watch_new_threads = forms.BooleanField(
default=True, required=False, initial=True,
help_text=_lazy('Automatically watch threads I create.'))
auto_watch_reply = forms.BooleanField(
@jsocol
jsocol / gist:1242521
Created September 26, 2011 15:38
Moxie report generator
#!/usr/bin/env python
"""Written for Python 2.5. If 2.6, remove the from __future__ import."""
from __future__ import with_statement
import optparse
import os
import stat
import sys
TEMPLATE = """<?php
SET @gid = (SELECT id FROM group WHERE name = 'staff');
INSERT INTO profile_groups SELECT
@gid, id FROM auth_user WHERE email LIKE '%@mozilla...;
@jsocol
jsocol / pack.js
Created November 10, 2011 23:38
Packing rectangles...
/**
* Return an array of paired factors (arrays) of an integer.
*/
function factor(n) {
var fact = [[1, n]],
check = 2,
root = Math.sqrt(n);
while (check <= root) {
if (n % check == 0) {
fact.push([check, n / check]);
@jsocol
jsocol / Explain.rst
Last active September 28, 2015 07:27
@json_view decorator

I finally put this in its own package! Check out django-jsonview.

This is a decorator that guarantees a response will be JSON, and sends meaningful (to a developer) error messages. It relies on a BadRequest exception I created elsewhere, because there is no standard way of handling that in Django (frex, we should really return HTTP 400 on form validation failures but they don't make that particularly easy). That could easily be removed, though.

@jsocol
jsocol / links.rst
Created December 19, 2011 21:09
Go Big or Go Home - Building Bid Django Sites
@jsocol
jsocol / gist:1568904
Created January 6, 2012 04:03
Bookmarklet to add inline full-size images to Reddit.
javascript: (function () {
var things = document.querySelectorAll("div.thing");
for (var j = things.length - 1; j > 0; j--) {
var thing = things[j],
entry = thing.querySelectorAll("div.entry")[0],
thumb = thing.querySelectorAll("a.thumbnail")[0],
img = new Image;
img.style.display = 'block';
if (thumb) {
var href = thumb.href;