Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / loops_worker.js
Created April 17, 2014 07:28
Checking for infinite loop
/* global initProcessingStubs */
importScripts("processing-stubs.js?cachebust=" + (new Date()).toDateString());
self.onmessage = function(event) {
var data = event.data,
context = data.context,
code = "with(arguments[0]){\n" +
data.code +
"\nif (typeof draw !== 'undefined' && draw){draw();}}",
@pamelafox
pamelafox / gist:10879482
Created April 16, 2014 13:55
BabyHint.js - checkFunctionDecl
checkFunctionDecl: function(line, lineNumber) {
var errors = [];
var functions = line.match(/function\s+\w+/g);
_.each(functions, function(fun) {
var name = fun.split(/\s+/g)[1];
// I18N: Don't translate the '\" var %(name)s = function() {}; \"' part
var error = {
row: lineNumber,
column: line.indexOf(fun),
@pamelafox
pamelafox / jquery.delayload.js
Created January 30, 2014 09:09
Delay Loading
// Functions to help figure out whether elements are in the viewport
// and lazy-load their content if so.
// Implemented as jQuery plugins.
(function() {
$.fn.inView = function(nearThreshold) {
var $elem = $(this);
// Checks if its visible, CSS-wise
if (!$elem.is(":visible")) {
return false;
/* This class is used to create the /topic/projectfeedback page,
* which shows expandable lists of feedback requests that need answering.
*/
var ProjectFeedbackPage = React.createClass({
propTypes: {
topic: React.PropTypes.string.isRequired
},
render: function() {
var helpCollection = new DiscussionItemCollection([], {
topic: this.props.topic,
@pamelafox
pamelafox / babyhint.js
Created December 2, 2013 05:13
BabyHint
/*
* BabyHint does a line-by-line check for common beginner programming mistakes,
* such as misspelling, missing spaces, missing commas, etc. It is used in
* conjunction with JSHINT to report errors to the user.
*
* Each error returned contains the members:
* {
* row : the row at which the error was found
* column : the column at which the error was found
* text : the error messaage
@pamelafox
pamelafox / gist:6822358
Created October 4, 2013 07:44
SF Youth hackathons/trainings looking for mentors
Nov. 24, Hack 4 Queer Youth: http://mymaven.org/hack/
Oct. 12, PilotSF High School Hackathon: http://sf.gopilot.org/
Nov. 17th, OpenSV Youth Hackathon: http://opensv.org/index.php/events/open-sv-youth-forum-hackathon
Oct. 26-27 and Nov. 16-17, LPFI Hackathon: http://lpfi.org/hackathon
Assorted dates, CodeNow High School Trainings: http://codenow.org/apply/volunteer/
@pamelafox
pamelafox / gist:6718591
Last active December 24, 2015 00:40
A surprising use of JS
// Pop quiz!
// 1. What will x and y be in this code?
(function() {
var x = 5;
var y = 10;
var coordinates = x, y;
console.log('First');
console.log(x);
@pamelafox
pamelafox / gist:5905031
Created July 1, 2013 22:03
playbackRate at Coursera
/** function set_speed(speed)
* Set the video speed
*
* @param double speed - target speed
*
* @return void
*/
this.is_set_speed_enabled = function() {
var featureExists = typeof(this.mediaelement_media) === 'object'
&& this.mediaelement_media !== null
@pamelafox
pamelafox / desk.py
Created June 25, 2013 02:09
Desk.com API Python Wrapper
import logging
import requests
from django.utils import simplejson
from django.conf import settings
class DeskError(Exception):
def __init__(self, status):
Exception.__init__(self, status) # Exception is an old-school class
@pamelafox
pamelafox / gist:5714109
Last active December 18, 2015 02:49
Forum Utility functions
function setupFormSave($form, xhrOptions, autoSave) {
xhrOptions = xhrOptions || {};
var lastFormData = $form.serialize();
xhrOptions.url = xhrOptions.url || $form.attr('action');
xhrOptions.type = xhrOptions.type || $form.attr('type');
var $saveButton = $form.find('button[type="submit"]');
var $saveStatus = $($saveButton.attr('data-update'));
function changeButtonText(message) {