Skip to content

Instantly share code, notes, and snippets.

View zootella's full-sized avatar
🏔️

Kevin Faaborg zootella

🏔️
View GitHub Profile
// 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";
// 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); }
console.log("hello 1");
/*
try running
$ node hello1.js
logs out "hello 1" and exits
*/
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
});
/*
var platformChildProcess = require("child_process");
function demo(name) { return process.argv[2] == "demo" && process.argv[3] == name; }
var log = console.log;
function trim(d) { return (d+"").trim(); }
/*
goals
//1. native operators, best looking but depends on primitive types or operator overloading
if (1 + 5 - 2 <= 9) return;
//2. methods, correct java-inspired design employed by most modules
if (int(1).add(5).subtract(2).lessThanOrEqualTo(9)) return;
//3. first custom design, works alongside 2
if (int(1)._("+", 5)._("-", 2)._("<=", 9)) return;
console.log("file\\");
var test = require("tape");
var tap_spec = require("tap-spec");
var tap_json = require("tap-json");
var stream_buffers = require("stream-buffers");
//run these like "$ node popquiz.js 1" and so on
var n = process.argv[2];
console.log("file\\");
var test = require("tape");
var tap_spec = require("tap-spec");
var tap_json = require("tap-json");
var stream_buffers = require("stream-buffers");
//run these like "$ node popquiz.js 1" and so on
var n = process.argv[2];
stream workshop ideas
[big file]
read a small file into memory to get its size
read a big file into memory, see that break
fix it with a stream that counts the bytes as they come in
[zip]
zip a file
unzip a file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>spin5</title>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="http://cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script>
</head>
<body>