Skip to content

Instantly share code, notes, and snippets.

View gilesbradshaw's full-sized avatar
🕶️
riding my bicycle

Giles gilesbradshaw

🕶️
riding my bicycle
  • SiGyl
  • Devon
View GitHub Profile
@gilesbradshaw
gilesbradshaw / recursive.md
Last active November 14, 2019 11:39
Bluebird vs native promises for recursion

Native promise leaks memory with recursion

const cdc = ({ x, start }) => {
  if (x % 5000000 === 0) {
    gc()
    console.log({
      used: process.memoryUsage(),
      x,
      time: Date.now() - start,
@gilesbradshaw
gilesbradshaw / sql-crash.js
Created February 14, 2019 09:37
This crashes sql server (running in docker on linux)
import mssql, { Request } from 'mssql'
import colors from 'colors'
import config from 'config'
import squel from 'squel'
const squelMssql = squel.useFlavour('mssql')
// import configurationStreams from './kafka/configuration'
// import runtimeStreams from './kafka/runtime'
@gilesbradshaw
gilesbradshaw / what.md
Last active January 24, 2019 01:29
currying compose

given

const compose = (...functions) =>
  (...params) =>
    functions
      .reduce(
        (acc, func) => [func(...acc)],
        params,
      )[0]
@gilesbradshaw
gilesbradshaw / compose.js
Created January 22, 2019 13:07
composes functions
export default (...functions) =>
param =>
functions
.reduce(
(acc, func) => func(acc),
param,
)
@gilesbradshaw
gilesbradshaw / serialiser.js
Created January 21, 2019 18:30
use promises to serialise access to an action
// serialises access to an action
export default () => {
// promise to allow the next action
let next = Promise.resolve()
return (action) => {
let nextResolve
const nextNext = () => new Promise(
(resolve, reject) =>
action()
.then(
"use strict";
/**
* @module opcua.server
*
*/
const assert = require("node-opcua-assert").assert;
const _ = require("underscore");
// a reduce function for a generator
// the result of the reducer function gets passed into next
function reduce(
reducer,
seed,
) {
const gen = this(seed);
let acc = seed;
let results = [];
let next = gen.next();
import { marbles } from 'rxjs-marbles';
/* eslint-env mocha */
/* eslint-disable no-unused-expressions */
describe('merge scan', () => {
it(
'should work',
marbles(
var edge = require('edge'); // http://tjanczuk.github.io/edge
var Rx = require('rxjs'); // https://github.com/Reactive-Extensions/RxJS
var createSubject = edge.func({
// this is c#
source: function () {/*
using System.Reactive.Linq;
using System.Reactive.Subjects;
using ClassLibrary1;
async (dynamic input) => {
function map(func) {
return this.reduce(
(acc, val) => [
...acc
func(val),
],
[],
);
}