Skip to content

Instantly share code, notes, and snippets.

View keithlayne's full-sized avatar
🚎

Keith Layne keithlayne

🚎
View GitHub Profile
@webstrand
webstrand / git-inlined-repositories.bash
Created November 5, 2020 19:15
A tutorial script explaining how to safely inline remote repositories.
#!/bin/bash
################################################################################
# Introduction
################################################################################
# This is an attempt at explaining how to vendor git repositories by storing
# their _entire_ commit history inside of the local repository. By vendoring
# dependencies using this technique, the remote repository can entirely
# recreated from the local repository if the original were to be lost.
# Additionally, clones of the local repository also satisfy that property.
#
@webstrand
webstrand / inheritance-v-composition.js
Last active March 12, 2020 20:22
benchmarking inheritance vs composition
const Benchmark = require("benchmark");
console.log("setup");
var suite = new Benchmark.Suite();
class TestInheritance extends Set {
constructor() { super() }
op(q) { this.add(q) }
}
import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import { createFilter } from "@rollup/pluginutils";
import surplusCompiler from "surplus/compiler";
function surplus({ include, exclude, sourceMap = false }) {
const filter = createFilter(include, exclude);

Using JSDOC-Based TypeScript

Get Started

Choose your editor

  • WebStorm, Rider
    • Partial support, not enough intelli hints
    • Toggle on TypeScript language service
  • VSCode
@webstrand
webstrand / UnionToIntersection.ts
Last active April 20, 2023 14:04
UnionToIntersection implemented without using intermediate function
type UnionToIntersection<
T,
U = T extends unknown ? { _: { [_ in T & PropertyKey]: never } } : {},
V = keyof U[keyof U],
// We need to remove the primitive we branded T with when we made it a
// property key. However, if the union T contains a branded type already,
// we must avoid stripping those brands off.
X = true extends (T extends PropertyKey ? true : never) ? never : PropertyKey
> = T extends never ? never : V extends X & infer W ? W : V;
@fatcerberus
fatcerberus / monads4all.md
Last active June 11, 2025 11:22
Monads for the Rest of Us

Monads for the Rest of Us

by Bruce Pascoe - 1 May, 2019

"A monad is just a monoid in the category of endofunctors. What's the problem?" ~James Iry[^1]

The problem... is that there are several problems.

It's been said that monads bear a dreadful curse. Once you finally understand what they are, you begin to see them everywhere--but somehow become completely incapable of explaining them to anyone else. Many tutorial writers have tried to break the Great Curse--the Web is lousy with bold attempts and half successes that attest to this--and just as many have failed. Well, I'm here to address the elephant in the room[^2] and tell you that I intend to break the Great Curse once and for all.

There are basically two ways a monad tutorial tends to go. One is a paragraph or two of minimal descriptions of one or two common monads (Haskell's Maybe in particular is very popular), followed by a lot of intimidating Haskell syntax trying to explain--precisely--how it all fits together. This is well

@jhohertz
jhohertz / prometheus-extra-etcd-instance.yaml
Created November 15, 2018 20:55
Enable prometheus monitoring of etcd and etcd-events on kops clusters
# To be used with current stable/prometheus-operator helm chart on kops clusters
# where 4001/4002 ports are blocked from the worker nodes
#
# In you helm, disable etcd monitor by setting kubeEtcd.enabled=false
# Then apply this yaml, and you should see the etcd stats on your main instance
#
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus-operator-prometheus-master
@xbeta
xbeta / 00-set-authorization.groovy
Created November 25, 2014 23:38
put them in $JENKINS_HOME/init.groovy.d/
import jenkins.model.*;
import hudson.security.*;
// JVM did not like 'hypen' in the class name, it will crap out saying it is
// illegal class name.
class BuildPermission {
static buildNewAccessList(userOrGroup, permissions) {
def newPermissionsMap = [:]
permissions.each {
newPermissionsMap.put(Permission.fromId(it), userOrGroup)
@plentz
plentz / nginx.conf
Last active May 5, 2026 07:20
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active April 15, 2026 17:04
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'