Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
friendlyanon / pipe.js
Last active April 3, 2019 17:56
Node IPC on Windows
import net from "net";
import EventEmitter from "events";
const PipeEmitter = class PipeEmitter extends EventEmitter {
constructor(pipeName, listen) {
super();
this.pipeAddress = "\\\\.\\pipe\\" + pipeName;
this.listen = listen;
this.server =
const CallbackWrapper = class CallbackWrapper {
constructor() {
this.executor = this._executor.bind(this);
this.resolve =
this.reject =
this.root =
this.args =
this.memoizedArgs =
this.method = null;
"use strict";
const { toString } = Object.prototype;
class Queue {
constructor(list) {
this._clearThreshold = 50;
this._offset = 0;
this._list = [];
this.enqueueIterable(list);
"use strict";
class GetRequest {
constructor(args) {
const first = args[0];
if (typeof first !== "string") throw new TypeError("Invalid args");
const slice = first.slice(0, first.indexOf(":"));
switch (slice) {
case "http": case "https": this.agent = this[slice]; break;
default: throw new TypeError("Unknown protocol");
}
@friendlyanon
friendlyanon / fizzbuzz.js
Last active October 11, 2018 16:07
Beceause everyone needs to show off how they know how to fizzbuzz.
"use strict";
// VERSION 1
// less generic, more performant
function fizzBuzz(start = 1, limit = 100) {
const result = [];
let i3 = start % 3;
let i5 = start % 5;
while (1) {
let str;
if (!i3) str = `Fizz`;
"use strict";
class CaptchaScraper {
constructor(key, referer) { this.key = key, this.referer = referer; }
then(resolve) {
this._https.get(
`https://www.google.com/recaptcha/api/fallback?k=${this.key}`,
{ headers: { Referer: this.referer } },
resolve
);
}
if (!Object.fromEntries) {
Object.defineProperty(Object, "fromEntries", {
value: function fromEntries(iterable) {
const obj = {};
for (const pair of iterable) {
if (typeof pair !== "object" || pair === null) {
throw new TypeError("iterable for fromEntries should yield objects");
}
obj[pair[0]] = pair[1];
}
"use strict";
// combine
function Combine(...iters) {
if (!new.target) {
return new Combine(...iters);
}
const { toString } = arguments;
for (const iter of iters) {
function isIsogram(s) {
var map, str, c, i, l, e, h;
if (typeof s !== "string") return false;
if ((l = s.length) < 2) return true;
c = (str = s.toLowerCase()).codePointAt();
if ((h = c > 0xFFFF) && l < 4) return true;
(map = {})[c] = true, e = l - 2, i = +h;
do {
if (map[c = str.codePointAt(++i)]) return false;
if (c > 0xFFFF) if (i === e) return true; else ++i;
"use strict";
var pow = Math.pow,
floor = Math.floor,
powArray = Array(54).map(function(_, i) { return pow(2, i); });
function intersection53() {
var map, key, i, j, len, mask, arr, value, n1, n2, b, r, argsLen, result;
for (map = {}, i = 0, argsLen = arguments.length; i < argsLen; ++i) {