Skip to content

Instantly share code, notes, and snippets.

View zootella's full-sized avatar
🏔️

Kevin Faaborg zootella

🏔️
View GitHub Profile
var makePerson = function (name, age) {
var me = {}, my = {};
//members
my.name = name;
my.age = age;
//private methods
// Calculate the average of a number of values as they are produced
var newAverage = function() {
var o = {};
var n = 0; o.n = function() { return n; } // How many values we have, 0 before you add one
var total = 0; o.total = function() { return total; } // The total sum of all the given values
var minimum = 0; o.minimum = function() { return minimum; } // The smallest value we have seen, 0 before we have any values
var maximum = 0; o.maximum = function() { return maximum; } // The largest value we have seen, 0 before we have any values
var recent = 0; o.recent = function() { return recent; } // The most recent value you added, 0 before we have any values
var newFile = function() {
var state = newState();
function close() {//maybe state.close = function() instead
if (state.already()) { log('already closed'); return; }
};
state.pulse = function() {
// ----
var start = new Date();
// ----
var size = 10000;
var a = [];
for (var i = 0; i < size; i++) {
a.push(i);
function _number(s, base) {
if (typeof s !== "string") throw "type";
var n = parseInt(s, base);
if (isNaN(n)) throw "data";
if (!match(_numerals(n, base), s)) throw "data"; // Guard against parseInt's dangerously accommodating parsing style by ensuring that the number we made becomes the same text we made it from
return n;
}
@zootella
zootella / gist:6242063
Last active December 21, 2015 03:29
made-up syntax for mixing static and dynamic typing, and variable and immutable variables, all in the same language at the same time!
//any type, variable value
*a = 7; //make a new variable and set it to 7
a = "hello"; //its a var, so we can set it to something of a different type
//one type, variable value
Text b;
b = "some text";
b = 7; //throws
//any type, permanent value
//make something available to the file from within a function in the file
//make sure it doesn't affect what's available in files that require this one
var color1 = "red";
var color2 = "orange";
//and we want to set two more colors, using the function below
function setColors() {
var extraColors = {color3:"yellow", color4:"green"};
//make something available to the file from within a function in the file
//make sure it doesn't affect what's available in files that require this one
var color1 = "red";
var color2 = "orange";
//and we want to set two more colors, using the function below
function setColors() {
var color1 = "red";
function set2() {
this["color2"] = "orange";
}
function set3(destination) {
destination["color3"] = "yellow";
}
var color1 = "red";
function set2() {
this["color2"] = "orange";
}
function set3(destination) {
destination["color3"] = "yellow";
}