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
*/
// 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";
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";
}
//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() {
//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"};
@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;
}