Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
/**
* Retrieve the variant to display. Should only be called once to ensure
* no double-counting of show events.
*
* @return {number}
*/
Experiment.prototype.chooseVariant = function() {
var self = this;
@pamelafox
pamelafox / kmlmap.html
Last active December 16, 2015 06:29
KML Gadget, Standalone HTML
<!doctype html>
<html>
<body>
<style>
body, html {
height: 100%;
width: 100%;
}
</style>
<div id=mapcontainer style="width: 100%; height: 100%;"></div>
@pamelafox
pamelafox / course.processtimes.js
Created April 4, 2013 19:07
Course processing logic
processTimes: function() {
var startDate = '';
var startDisplay = 'Date to be announced';
var startDisplayShort = 'TBA';
var startCountdown = '';
var startTime = 4100745600000; // Change this in 2099
var startDiff = 99999999;
var duration = '';
var durationWeeks = 1000;
var today = moment(new Date());
@pamelafox
pamelafox / table.html
Last active December 15, 2015 13:28
An accessible table
<style type="text/css">
.hidden-accessible {
position: absolute !important;
height: 1px; width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
</style>
@pamelafox
pamelafox / browser.js
Created February 13, 2013 17:35
Browser banner warning
(function(wndw) {
var Browsers, OS, Platform, Versions, browser_name, browser_version, os, platform;
Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i
};
@pamelafox
pamelafox / gist:4674841
Last active September 24, 2020 13:43
truncate based off offscreen
function truncateText(string, nMaxChars) {
if (string.length <= nMaxChars)
return string;
var xMaxFit = nMaxChars - 3;
var xTruncateAt = string.lastIndexOf(' ', xMaxFit);
if (xTruncateAt == -1 || xTruncateAt < nMaxChars / 2)
xTruncateAt = xMaxFit;
return string.substr(0, xTruncateAt) + "&hellip;";
@pamelafox
pamelafox / linkify.js
Last active December 11, 2015 23:09
linkify
function linkifyText(string){
if (string) {
string = string.replace(
/((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url){
var full_url = url;
if (!full_url.match('^https?:\/\/')) {
full_url = 'http://' + full_url;
}
@pamelafox
pamelafox / gist:4180872
Created December 1, 2012 06:49
Detect and change playbackRate
/** function set_speed(speed)
* Set the video speed
*
* @param double speed - target speed
*
* @return void
*/
this.is_set_speed_enabled = function(){
if(typeof(this.mediaelement_media) === 'object'
@pamelafox
pamelafox / catalog_test.js
Created November 29, 2012 18:48
Coursera catalog view test
describe('catalogyBody', function() {
var chai = require('chai');
var path = require('path');
var env = require(path.join(testDir, 'lib', 'environment'));
var requirejs = env.requirejs(staticDir);
var sinon = requirejs('js/lib/sinon');
var fs = require('fs');
var server;
var router;
@pamelafox
pamelafox / test_hand_val.py
Created November 28, 2012 17:32
Basic unit test of function in Python
import unittest
BUST_VAL = 22
ACE_HIGH = 11
ACE_LOW = 1
def calculate_hand_val(low_hand_val, num_aces):
hand_val = low_hand_val
for x in range(1, num_aces + 1):