Skip to content

Instantly share code, notes, and snippets.

View zootella's full-sized avatar
🏔️

Kevin Faaborg zootella

🏔️
View GitHub Profile
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
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>