Skip to content

Instantly share code, notes, and snippets.


Operations Research Engineering Software+ ORESoftware

Block or report user

Report or block ORESoftware

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ORESoftware / promise.ts
Last active Oct 13, 2019
Promise implementation in JS. IRL the Promise implementation is in C++ land, but most JS implementations than native for whatever reason.
View promise.ts
'use strict';
// note! run this with Node.js version 11, as queueMicrotask is only supported
// in Node.js version 11.
declare var queueMicrotask: any;
const CancelSymbol = Symbol('cancel');
const RejectSymbol = Symbol('reject');
ORESoftware / test-file-2.js
Last active Sep 18, 2019
Viking vs Tudor part II
View test-file-2.js
// windows version
const Viking = require('C:\\Users\\denman\\WebstormProjects\\viking'); //we have published viking on NPM and then installed it in the local project with the --save option
new Viking().start();
// *nix version
const Viking = require('/Users/denman/WebstormProjects/viking'); //we simply point to the root of the local project, which will find the package.json file which in turn points to your index.js file
new Viking().start();
ORESoftware / resize-base64.js
Last active Sep 18, 2019
resizing an image on the front-end before sending to a server
View resize-base64.js
// Using this code, we can retrieve an image from a user's filesystem, resize the image, and then upload the image
// to a server using AJAX. Because we use base64 encoding, we can just include the image data as just another string value
// in a JSON payload.
// So we can use AJAX to send the file to a server, which is convenient.
// We have one line of relevant html
// get file in the first place => <input type="file" custom-on-change="onAcqImageFileChange" class="form-control">
ORESoftware /
Created Dec 16, 2018
Simple use cases for Node.js domain module

First run this code:

const exec = () => {
   setTimeout(() => {
      throw 'nothing can catch this, except domains';
ORESoftware / cluster.log
Last active Sep 10, 2019
docker-compose logs for mongodb cluster
View cluster.log
Attaching to rydell-mongo-config-03, rydell-mongo-config-02, rydell-mongo-config-01, rydell-shard-03-node-a, rydell-shard-01-node-a, rydell-shard-02-node-a, rydell-router-02, rydell-router-01, rydell-shard-03-node-b, rydell-shard-01-node-b, rydell-shard-02-node-b, rydell-shard-02-node-c, rydell-shard-03-node-c, rydell-shard-01-node-c
rydell-mongo-config-02 | 2019-09-10T02:57:20.550+0000 I STORAGE [main] Max cache overflow file size custom option: 0
rydell-mongo-config-02 | 2019-09-10T02:57:20.552+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
rydell-mongo-config-02 | 2019-09-10T02:57:20.555+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/configdb 64-bit host=c569f8378ff2
rydell-mongo-config-02 | 2019-09-10T02:57:20.555+0000 I CONTROL [initandlisten] db version v4.0.12
rydell-mongo-config-02 | 2019-09-10T02:57:20.555+0000 I CONTROL [initandlisten] git version:
ORESoftware /
Last active Aug 26, 2019
Stdout/stderr for writing between procs can be faulty if extra stdio is included

Here is some node.js code:

#!/usr/bin/env node

const fs = require('fs');

const header = '#!/usr/bin/env bash\n\n';
try {
  const bytes = fs.writeSync(3, header, 0);
ORESoftware / domain-middleware.js
Last active Aug 17, 2019
Using Node.js domains in production
View domain-middleware.js
const d = Domain.create(); // create a new domain for this request
res.once('finish', function () {
ORESoftware / spread.js
Created Jun 25, 2019
spread operator to merge / mixin objects
View spread.js
const a = {
a: {
b: {
c: 4,
d: 'str'
ORESoftware /
Created Jun 5, 2019
JQ does not make it easy to sanitize strings for JSON inclusion
hist='sed '0,1d' "$HOME/my_bash_history" | wc -l' ### <<< we have some double quotes to escape
data="$( jq -nc --arg str "$hist" '{"attr": $str}' )"
echo "data: $data"
hist="$(echo "$data" | jq -r '.attr')"
echo "hist: $hist" # damnit it's back to where it was before
ORESoftware /
Last active May 28, 2019
Cleanup docker artifacts/items

Clean up docker images/containers/volumes/networks

#!/usr/bin/env bash

set +e;
You can’t perform that action at this time.