Skip to content

Instantly share code, notes, and snippets.

@jsocol
jsocol / good-forms.py
Created July 31, 2012 14:01
Django Mass Assignment
from django import forms
from myapp.models import Whatzit
class WhatzitForm(forms.ModelForm):
class Meta(object):
model = Whatzit
fields = ('foo', 'bar', 'baz')
@jsocol
jsocol / example.html
Created September 26, 2012 19:28
Specificity
<!DOCTYPE html>
<html>
<head>
<style>
a {
display: block;
}
a.foo {
background-color: green;
}
@jsocol
jsocol / gist:3940077
Created October 23, 2012 16:59
assert_raises without a TestCase subclass
class assert_raises(object):
"""A context manager that asserts a given exception was raised.
>>> with assert_raises(TypeError):
... raise TypeError
>>> with assert_raises(TypeError):
... raise ValueError
AssertionError: 'ValueError' not in ['TypeError']
@jsocol
jsocol / comment.js
Created October 25, 2012 14:31
How I'd do this
var field = document.getElementById('id_needs_change_comment');
var maxlength = Number(field.getAttribute('data-maxlength'));
var remaining = document.getElementById('comment-remaining-characters');
var remainingText = remaining.textContent;
field.addEventListener('keyup', function() {
var remainingChars = maxlength - this.value.length;
remaining.textContent = remainingText.replace('%d', remainingChars);
}, true);
@jsocol
jsocol / youtube.com.js
Created November 9, 2012 05:46
hide youtube comments with dotjs
(function(d) {
var c = d.querySelector("#watch-discussion");
c.parentNode.removeChild(c);
})(document);
@jsocol
jsocol / gist:4067398
Created November 13, 2012 18:13
R-Type-like Multitouch UI Test
<!DOCTYPE html>
<title>Multitouch Test</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<style>
html, body {
background-color: #000;
color: #fff;
height: 100%;
@jsocol
jsocol / forms.html
Created December 3, 2012 23:03
forms test
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Forms!</title>
<style>
input {
display: block;
font-size: 150%;
}
@jsocol
jsocol / chrome-trello.com.js
Created December 10, 2012 05:59
.js script: make trello card IDs visible
window.addEventListener("load", function() {
var ids = document.querySelectorAll("span.card-short-id");
Array.prototype.forEach.call(ids, function(el) {
el.classList.remove("hide");
});
}, false);
@jsocol
jsocol / README.md
Created January 28, 2013 05:34 — forked from johan/README.md

The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.

Have on.js do it for you!

@jsocol
jsocol / lcd.sh
Created May 12, 2013 15:02
Change directories and list contents.
# I found myself doing this a lot: cd path/<enter>ls<enter> and thought "that's silly".
# Put this in your .bashrc or another file that is sourced (*not* executed) into your
# shell environment. Then you'll have the "lcd" command available.
# Change directory and list contents.
lcd () {
if [ $# -eq 1 ]; then
cd $1 && ls
elif [ $# -eq 2 ]; then
cd $2 && ls $1