This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * EventArray.js - Arrays you can watch. | |
| * Copyright 2012, James Socol <me@jamessocol.com> | |
| * | |
| * Released under the MIT X11 and BSD 2-clause Licenses. | |
| * | |
| * EventArray.js is a simple wrapper around JS arrays that makes it | |
| * easier to use them for data-driven UIs by providing a way to watch | |
| * them for mutations. Think of the lovechild of an Array and an | |
| * EventEmitter. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Imagine, if you will, a simple task. You have a blog written in Node, with | |
| * its content stored in Mongo, and you want to display a single post (for | |
| * simplicity, let's pretend the URL contains the ObjectID) and its comments. | |
| * | |
| * Normally, you'd have to fall into callback/scope hell, and do something | |
| * along the lines of this, already in an onRequest handler: | |
| */ | |
| function displayPost(request, response) { | |
| // We'll look up the post and its comments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Mozillians Git-Fu. | |
| # Useful steps for moving around git branches and servers related to | |
| # the Mozillians release process. Any dev should be able to do these | |
| # in a pinch, there are no special privileges. | |
| # Always assuming 'origin' refers to github.com/mozilla/mozillians.git | |
| # Current branch is in () in my pseudo-prompt. | |
| # HowTo: Cut a new 'next' branch. | |
| # After tagging, we wipe out the current next branch and fork from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function textColor(bg) { | |
| var r = parseInt(bg.substr(0,2),16), | |
| g = parseInt(bg.substr(2,2),16), | |
| b = parseInt(bg.substr(4,2),16); | |
| var yiq = (r * 299 + g * 587 + b * 114) / 1000; | |
| return yiq >= 128 ? "black" : "white"; | |
| } | |
| function bgColor(el, i) { | |
| return ("000000" + $.trim($("a", el).eq(i).text())).substr(-6); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SET @gid = (SELECT id FROM group WHERE name = 'staff'); | |
| INSERT INTO profile_groups SELECT | |
| @gid, id FROM auth_user WHERE email LIKE '%@mozilla...; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |