Skip to content

Instantly share code, notes, and snippets.

View greim's full-sized avatar

Greg Reimer greim

View GitHub Profile

Elm: Supplementary Notes

In which I get angry because some aspect of Elm seems weird to me, and the docs aren't helping, so I jot down these notes because writing forces me to think deeply about things in a way that I'm incapable of doing otherwise gaaasspp

Grokking JSON Decoders

Preliminary: We'll be dumping Json.Decode into our namespace to reduce typing, such that we have naked functions such as int, which is actually Json.Decode.int, and so forth:

import Json.Decode exposing (..)
@greim
greim / queue.elm
Created June 24, 2016 20:26
Queue data structure in Elm
type Queue a
= Empty
| Mono a
| Multi a (Queue a) a
enq : a -> Queue a -> Queue a
enq val queue =
case queue of
Empty ->
'use strict';
/*
* Binary search tree with in-order iteration.
* http://greim.github.io/gen/dist/00-intro.html
*/
class Tree {
add(value) {
if (this.root) this.root.add(value);

Private members in ES6 classes

"Let's create an ES6 class!" you say. "Let's give it a private variable x."

class Foo {
  constructor(x) {
    this.x = x;
  }
  getX() {

How you can help reduce node_modules bloat

This recent reddit thread reveals discontent among the web development community about the sheer volume of stuff in a typical node_modules dir. 140MB in this case!

Is it a design flaw in npm?

Opinions in the thread varied from "I'm surprised npm even works" to "everything is fine". I'm not going to offer an opinion, just these two observations:

  1. node_modules dirs typically do contain lots of stuff that doesn't need to be there.
  2. The latest version mitigates overall size by flattening the dependency tree, but some of the bloat is beyond npm's control.
@greim
greim / reverse-proxy.md
Last active August 23, 2022 10:12
Using a Reverse Proxy for Rapid Prototyping

Using a Reverse Proxy for Rapid Prototyping

Note: This will be a contrived example, but hopefully illustrates some real-world trade-offs.

Example scenario: Suppose you're an independent web developer, and a client asks you to prototype a redesign of their website header. You'll be paid for your time, and if the client likes it, you'll be hired to do the full implementation. Your incentive is to show the client a quick, functional demo of the updated header. The problem is that quick and functional tend to be mutually-exclusive.

At One Extreme: Do It Fast

@greim
greim / https-mitm-proxy-poc.js
Last active September 18, 2022 06:44
HTTPS MITM Proxy Proof of Concept
import https from 'https'
import http from 'http'
import url from 'url'
import adapt from 'ugly-adapter' // callback => promise adapter; need to npm install this
import tls from 'tls'
import net from 'net'
import fs from 'fs'
import os from 'os'
import path from 'path'
import childProcess from 'child_process'
@greim
greim / asynchronous-quick-sort.js
Created June 10, 2015 06:04
Implementing async quicksort with generators
'use strict'
/*
* QuickSort algorithm adapted from here:
* http://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/
*/
var co = require('co')
function swap(items, firstIndex, secondIndex){
@greim
greim / gist:2dcedcf3c42ad6b5258f
Created February 9, 2015 16:36
Binary walk function
/*
* Home in on a number in binary search fashion.
* binWalk(2048) === 1024
* binWalk(2048, -1) === 512
* binWalk(2048, -1, -1) === 256
* binWalk(2048, -1, -1, -1) === 128
* binWalk(2048, -1, 1) === 1536
*/
function binWalk(n){
@greim
greim / gist:8221971
Created January 2, 2014 16:36
I'm building a decorative wooden header for some shelves with arches cut out at the top. The board was 5" wide and I wanted the arch to be half that, so I wrote this program to calculate the radius.
/*
For an arch with a rise of X, what's the radius.
Start with this right triangle:
b
|
a----------------c
a = left edge of arch