Skip to content

Instantly share code, notes, and snippets.

🏐
Focusing

Operations Research Engineering Software+ ORESoftware

🏐
Focusing
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
ORESoftware / async-constructor.js
Last active Jan 14, 2017
An asynchronous constructor pattern
View async-constructor.js
// asynchronous constructor example,
// like always do not explictly return anything from the constructor
function Queue(){
this.ready = false;
let callable = true;
let ee = new EE(); // new event emitter
View create-queue.js
// import opq
const Queue = require('opq');
// below we create a new client to the queue,
// and create the queue on the filesystem if it does
// not exist. the port is used by Live-Mutex;
// fp is our queue filepath
const q = new Queue({
View promises-vs-rxjs.js
const Rx = require('rxjs');
console.log(1);
new Promise(function(resolve,reject){
console.log(2);
resolve();
});
@ORESoftware
ORESoftware / obs-vs-promises-resolution.js
Last active Jan 14, 2017
Async or sync resolution?
View obs-vs-promises-resolution.js
console.log(1);
new Promise(function(resolve,reject){
console.log(2);
resolve();
}).then(function(val){
console.log(3);
});
@dfkaye
dfkaye / import-scripts-proposal.md
Last active Apr 9, 2017
importScripts boilerplate pattern proposal alternatives for javascript
View import-scripts-proposal.md

"JavaScript doesn't need more features; it just needs a couple of small things fixed" - Ryan Dahl

The CommonJS and AMD module syntaxes are unfriendly to each other, requiring boilerplate everywhere, which UMD tries to solve with more boilerplate.

The ES6 module syntax adds new keywords in strict mode, that then depend on a sharply modified cross-origin requests shims, and internal module management. An ES6 Module Transpiler aims to solve the not-yet-supporting environments problem with a source transformation step.

We don't need more syntax like imports x from 'x.js'. We don't need a module keyword that will break QUnit module() or Node.js modules.

@thinkerbot
thinkerbot / multiple_writers
Created Sep 1, 2013
Demonstrates that multiple writers to a single fifo often get inputs interleaved, regardless of sync.
View multiple_writers
#!/bin/bash
# 8... always?
mkfifo fifo
ruby -e '100000.times {|i| puts "a"}' > fifo &
ruby -e '100000.times {|i| puts "b"}' > fifo &
ruby -e '100000.times {|i| puts "c"}' > fifo &
ruby -e '100000.times {|i| puts "d"}' > fifo &
ruby -e '100000.times {|i| puts "e"}' > fifo &
ruby -e '100000.times {|i| puts "f"}' > fifo &
ruby -e '100000.times {|i| puts "g"}' > fifo &
@ORESoftware
ORESoftware / stringifiable.ts
Last active Jul 8, 2018
stringifiable type with TS
View stringifiable.ts
export type Stringifiable = object | string | boolean | number | null;
export const stdMarker = 'gfy';
export const getJSONCanonical = function (v: Stringifiable, marker?: string) {
marker = marker || stdMarker;
@ORESoftware
ORESoftware / rw.md
Last active Jan 28, 2019
Readers-writer lock for payment processing
View rw.md

No official CS education but I learned about readers-writer locks after implementing a mutex library. I happened to come across a real-world use case that I would need this for.

Say we have many people signing up to take a class, their payment (through Stripe, or whatever) might be in flight. And imagine the teacher cancels the class, which would trigger a refund event.

Without proper locking, the refund might fail to execute for those students whose payments are in flight at the time of the class cancelation.

@ORESoftware
ORESoftware / cleanup.md
Last active May 28, 2019
Cleanup docker artifacts/items
View cleanup.md

Clean up docker images/containers/volumes/networks

#!/usr/bin/env bash


set +e;
@ORESoftware
ORESoftware / domain.md
Created Dec 16, 2018
Simple use cases for Node.js domain module
View domain.md

First run this code:

const exec = () => {
   setTimeout(() => {
      throw 'nothing can catch this, except domains';
   },10);
};
You can’t perform that action at this time.