Skip to content

Instantly share code, notes, and snippets.

@jasonmw
jasonmw / Homework2.js
Created November 11, 2011 05:44
Homework 2 from Mastering JS Class
Math.sin = (function(){
var original_sin = Math.sin;
var cache = {};
return function(n){
if(cache[n] == null){
cache[n] = original_sin(n);
console.log('adding sin of ' + n.toString() + ' to cache');
} else {
console.log('sin cache hit: ' + n.toString());
}
@jasonmw
jasonmw / Homework1.js
Created November 11, 2011 05:44
Homework 1 from Mastering JS Class
var logCar = function(){
var inp = arguments[0];
return function(){
console.log("I'm a " + inp.color + ' ' + inp.make);
};
};
var Car = function(make,color){
this.make = make;
var countdown = function(){
var index = 10;
var log = function(){console.log(index)};
var iterate = function(){
log();
if(index>1) setTimeout(iterate, 1000);
index--;
}
if(index>1){
iterate();
function isCreditCard( CC ) {
if (CC.length > 19)
return (false);
sum = 0; multiplier = 1; l = CC.length;
for (i = 0; i < l; i++)
{
digit_to_process = getCharAtIndexFromEndOfString(CC,i);
tmp_product = parseInt(digit_to_process) * multiplier;
# These are my notes from the PragProg book on CoffeeScript of things that either
# aren't in the main CS language reference or I didn't pick them up there. I wrote
# them down before I forgot, and put it here for others but mainly as a reference for
# myself.
# assign arguments in constructor to properties of the same name:
class Thingie
constructor: (@name, @url) ->
# is the same as:
@jasonmw
jasonmw / FailoverFunc.cs
Created May 10, 2011 20:15
Failover Func
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Jason.Tests {
[TestClass]
public class TryParseTests {
[TestMethod]
public void TestTryParse_Func_Bad() {
Assert.AreEqual(0, "s".TryParse(Failover<int>));