Skip to content

Instantly share code, notes, and snippets.

View denniszhao's full-sized avatar
🎯
Focusing

Dennis denniszhao

🎯
Focusing
View GitHub Profile
@denniszhao
denniszhao / gist:7bae86328257a6345154
Created August 4, 2014 02:46
Utility script to get department codes and course UIDs for all classes at Cal through the dev api.
/**
*
* Little utility script to get list of all department codes
*
*/
var request = require('request');
var async = require('async');
var _ = require('lodash');
var fs = require('fs');
@denniszhao
denniszhao / gist:21c24ee200291fb7a6e6
Created August 15, 2014 19:56
Return true if valid phone number
function isValidUSPhoneNum(number) {
var USPhoneNumRegex = /^(?:\([2-9]{3}\)(?:[\s]*|[-])|[2-9]{3}(?:[\s]*|[-]))[0-9]{3}(?:[\s]*|[-])[0-9]{4}$/;
// booleanize
return !!number.match(USPhoneNumRegex);
}
function isValidUSPhoneNum(number) {
// Matches valid US numbers of the form
// xxx (whitespace or -) xxx (whitespace or -) xxxx
var USPhoneNumRegex = /^(?:\([2-9][0-9]{2}\)(?:[\s]*|[-])|[2-9][0-9]{2}(?:[\s]*|[-]))[0-9]{3}(?:[\s]*|[-])[0-9]{4}$/;
// booleanize bitch
return !!number.match(USPhoneNumRegex);
}
/**
*
* Computes the average number of students per section in the sandbox/demo API.
*
*/
var request = require('request');
// We know that there's only one district in the dummy data from a call
// to the `districts` endpoint, ie
/**
* Formats number of seconds to hh:mm:ss format.
*/
formatTime: function (seconds) {
var minutes = Math.floor(seconds / 60),
hours = Math.floor(minutes / 60),
h = (hours !== 0) ? hours + ":" : "",
m = (minutes % 60 !== 0) ? (minutes % 60) + ":" : ((h === "") ? "" : "00:"),
s = (seconds % 60 !== 0) ? (seconds % 60) : "00";
/**
* Converts YouTube formatted duration to seconds.
*
* Expects input String of the form "PT#M#S", in which the letters PT indicate
* that the value specifies a period of time, and the letters M and S refer to
* length in minutes and seconds, respectively. The # characters preceding the
* M and S letters are both integers that specify the number of minutes (or
* seconds) of the video. For example, a value of PT15M51S indicates that the
* video is 15 minutes and 51 seconds long.
*/
@denniszhao
denniszhao / lab6.md
Created September 30, 2015 19:30
CS61B Lab 6

~ number: 6 ~ title: Collections, Iterators, and Meta-iterators

Navigation