Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@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) {
@pamelafox
pamelafox / helpwidget.js
Created May 29, 2013 14:35
HelpWidget JavaScript
(function(wndw) {
/*
This library pops up a help window when the user clicks on the specified element.
For example, if you have a help tab like this:
<div class="course-help-widget-tab"
data-helpwidget data-helpwidget-link-docs="http://support.coursera.org" data-helpwidget-linkdiscuss="http://class.coursera.org/mooc/"
tabindex="0" role="button" aria-haspopup="true" aria-expanded="false">Help
</div>
And you call this JS: