Skip to content

Instantly share code, notes, and snippets.

// the base command class or interface
class Command {
handle() {
}
}
class CreateUserCommand extends Command {
constructor(user) {
super();
this.user = user;
@shalvah
shalvah / ast-parser.js
Last active October 12, 2019 11:11
Tokenize and create an abstract syntax tree from an infix math expression in Javascript
function ASTNode(token, leftChildNode, rightChildNode) {
this.token = token.value;
this.leftChildNode = leftChildNode;
this.rightChildNode = rightChildNode;
}
function parse(inp){
var outStack=[];
var opStack=[];
@shalvah
shalvah / throttle.js
Last active October 24, 2019 09:03
Implementation of throttle functionality in JavaScript
function throttle(f, t) {
return function (args) {
let previousCall = this.lastCall;
this.lastCall = Date.now();
if (previousCall === undefined // function is being called for the first time
|| (this.lastCall - previousCall) > t) { // throttle time has elapsed
f(args);
}
}
}
2020-02-05 11:20:19.512 [apm-server-healthcheck] DEBUG co.elastic.apm.agent.report.ApmServerHealthChecker - Starting healthcheck to http://172.24.102.69:8200/
2020-02-05 11:20:19.522 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 10:net_cls:/
2020-02-05 11:20:19.522 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 9:memory:/
2020-02-05 11:20:19.523 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 8:hugetlb:/
2020-02-05 11:20:19.523 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 7:perf_event:/
2020-02-05 11:20:19.523 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 6:devices:/
2020-02-05 11:20:19.524 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo
2020-02-05 14:08:14.431 [apm-server-healthcheck] DEBUG co.elastic.apm.agent.report.ApmServerHealthChecker - Starting healthcheck to http://172.24.102.69:8200/
2020-02-05 14:08:14.442 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 10:memory:/
2020-02-05 14:08:14.442 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 9:hugetlb:/
2020-02-05 14:08:14.442 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 8:devices:/
2020-02-05 14:08:14.443 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 7:blkio:/
2020-02-05 14:08:14.443 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 6:cpuacct,cpu:/
2020-02-05 14:08:14.443 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo -
@shalvah
shalvah / google-onetime-oauth-cli.js
Created March 15, 2020 19:42
How to get a one-time access token from Google
const TOKEN_PATH = 'token.json';
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
const gapi = require('googleapis');
const clientSecret = process.env.GOOGLE_CLIENT_SECRET;
const clientId = process.env.GOOGLE_CLIENT_ID;
const redirectUri = process.env.GOOGLE_REDIRECT_URI;
const oAuth2Client = new gapi.google.auth.OAuth2(clientId, clientSecret, redirectUri);
const fs = require('fs').promises;
@shalvah
shalvah / .NET Activity IDs structure.md
Created July 23, 2020 14:26
Examples of System.Diagnostics.Activity structure in .NET
/**
* Simple promise implementation. Doesn't have all the features of the actual Promise API, + assumes you know what you're doing.
*/
class ToyPromise {
constructor(cb) {
this.state = 'pending';
this._promiseResult = undefined;
this._fulfillmentCallbacks = [];
this._rejectionCallbacks = [];
const wordList = {
sacrilege: {popularity: 0.5207411547},
sarcasm: {popularity: 0.1913595276},
said: {popularity: 0.736293578},
sardine: {popularity: 0.2439570583},
sars: {popularity: 0.6371759558},
saw: {popularity: 0.1695272778},
say: {popularity: 0.8312312658},
scare: {popularity: 0.3623531581},
var Jimp = require('jimp');
const fileName = process.argv[2];
const width = process.argv[3];
const height = process.argv[4];
Jimp.read(fileName)
.then(photo => {
let colours = {};
for (let x = 0; x < width; x++) {