Skip to content

Instantly share code, notes, and snippets.

View zootella's full-sized avatar
🏔️

Kevin Faaborg zootella

🏔️
View GitHub Profile
console.log("hello 2");
process.stdin.resume();//standard in starts paused by default, resume it to be able to get data
process.stdin.on("data", function(d) {//we got some data
console.log("hello 2 received data:");
console.log(d+"");//turn it into a string before logging it to standard out
});
/*
console.log("hello 1");
/*
try running
$ node hello1.js
logs out "hello 1" and exits
*/
@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
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;
}
// ----
var start = new Date();
// ----
var size = 10000;
var a = [];
for (var i = 0; i < size; i++) {
a.push(i);
var newFile = function() {
var state = newState();
function close() {//maybe state.close = function() instead
if (state.already()) { log('already closed'); return; }
};
state.pulse = function() {
// 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 makePerson = function (name, age) {
var me = {}, my = {};
//members
my.name = name;
my.age = age;
//private methods
// A 0+ integer of unlimited size
function Int(p) { // Takes a number like 5, a string of numerals like "789", a bignumber.js BigNumber, or another Int
if (isType(p, "Int")) return p; // Return the given Int instead of making a new one, the value inside an Int can't change
var o = {};
o.v = _3type(p); // Parse the given parameter, keeping together v.s() numerals, and v.n() number and v.b() BigNumber once we have them or they are necessary
o.inside = o.v.inside; // Point to function, see which types v has built up with text like "bns" or "--s" for testing
o.add = function(q) { return _add(o.v, q); } // Math
o.subtract = function(q) { return _sub(o.v, q); }
o.multiply = function(q) { return _mul(o.v, q); }
// A 0+ integer of unlimited size
function Int(p) { // Takes a number like 5, a string of numerals like "789", a bignumber.js BigNumber, or another Int
if (isType(p, "Int")) return p; // Return the given Int instead of making a new one, the value inside an Int can't change
var o = {};
o.v = _3type(p); // Parse the given parameter, keeping together v.s numerals, and v.n number and v.b BigNumber once we have them or they are necessary
o._ = function(c, q) { return _calculate(o.v, c, _3type(q)); } // Who says JavaScript can't do operator overloading?
o.text = o.v.s();
o.hasNumber = function() { return o.v.fit; } // True if our value is small enough it will fit in a number as an integer, not a floating point number
o.toNumber = function() { return o.v.n(); } // Throws if too big
o.type = "Int";