Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
riding my bicycle

Giles gilesbradshaw

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

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 Feb 14, 2019
This crashes sql server (running in docker on linux)
View sql-crash.js
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 Jan 24, 2019
currying compose
View what.md

given

const compose = (...functions) =>
  (...params) =>
    functions
      .reduce(
        (acc, func) => [func(...acc)],
        params,
      )[0]
@gilesbradshaw
gilesbradshaw / compose.js
Created Jan 22, 2019
composes functions
View compose.js
export default (...functions) =>
param =>
functions
.reduce(
(acc, func) => func(acc),
param,
)
@gilesbradshaw
gilesbradshaw / serialiser.js
Created Jan 21, 2019
use promises to serialise access to an action
View serialiser.js
// 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(
View MonitoredItem.js
"use strict";
/**
* @module opcua.server
*
*/
const assert = require("node-opcua-assert").assert;
const _ = require("underscore");
View reduce.js
// 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();
View mergeScan.js
import { marbles } from 'rxjs-marbles';
/* eslint-env mocha */
/* eslint-disable no-unused-expressions */
describe('merge scan', () => {
it(
'should work',
marbles(
View edge.js
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) => {
View map-with-reduce.js
function map(func) {
return this.reduce(
(acc, val) => [
...acc
func(val),
],
[],
);
}
You can’t perform that action at this time.