Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / example.html
Created September 26, 2012 19:28
Specificity
<!DOCTYPE html>
<html>
<head>
<style>
a {
display: block;
}
a.foo {
background-color: green;
}
@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 / config.php
Created July 25, 2012 18:37
PHP DB Config
<?php
if (!defined('APP')) die();
define('DB_HOST', 'localhost');
define('DB_PORT', '3306');
define('DB_USER', 'myuser');
define('DB_PASS', 'mypass');
@jsocol
jsocol / gist:2925392
Created June 13, 2012 17:30
BannedSession
class BannedSession(Exception):
"""For various reasons, mostly in get_response, I don't think you
want to inherit from PermissionDenied."""
pass
class BannedMiddleware(object):
def process_exception(self, request, exception):
if isinstance(exception, BannedException):
return render(request, 'banned.html', {'reason': exception.args[0]})
@jsocol
jsocol / bad.js
Created May 16, 2012 02:46
Prongo
var mongodb = require('mongodb');
var express = require('express');
var app = express.createServer();
var db = new mongodb.Db('mysite',
new mongodb.Server('localhost', 27027, {}),
{native_parser: true});
app.get('/', function(req, res) {
// Open the connection.
@jsocol
jsocol / gist:2696070
Created May 14, 2012 19:43
Bash prompt function
_prompt() {
local _prompt=$1
local _out=$2
local _default=$3
local _val=''
if [ $_default ]; then
_prompt="${_prompt} [${_default}]"
fi
read -p "$_prompt " _val
if [ $_val ]; then
@jsocol
jsocol / test.html
Created May 9, 2012 19:15
HTML5 parsing quirk
<!DOCTYPE html>
<title>test</title>
<p><em>some </em unfinished business.</p>
<!-- EXPECTED DOM: -->
<!-- EITHER -->
<p><em>some &lt;/em unfinished business.</em></p>
<!-- OR -->
<p><em>some </em >unfinished business.</p>

Hi!

I'm not currently looking for a job as I'm pretty happy at my current job.

However Mozilla is looking for a recruiting manager in Mountain View. Mozilla also has deep ties in the open source communities and it sounds like it might be an interesting fit for you. <OPTIONAL-ADDITIONAL-TEXT>

If you're interested in applying, check out our careers link: