Skip to content

Instantly share code, notes, and snippets.

View JulianKniephoff's full-sized avatar

Julian Kniephoff JulianKniephoff

View GitHub Profile
/**
* Exhaustive visitation for discriminated unions.
* Let's say you have something like
*
* type T = { type: "number", value: number } | { type: "string", value: string };
* const t: T = ...;
*
* Then you can say
*
* discriminate(t, "type", {
/**
* Type guard for cases where one field of a structure determines
* the nullability of a selection of other fields.
* In the best case this will only check the `discriminator` field
* against the given `discriminant`, but you will also get a runtime error
* if any of the given `entailed` fields are `null`-ish when you don't
* expect them to be.
*/
export function checkAndEntail<T, I extends keyof T, J extends keyof T>(
t: T,
@JulianKniephoff
JulianKniephoff / foo.js
Created June 29, 2019 05:35
Demonstrate a bug in webpack-contrib/exports-loader
var global = 42;
@JulianKniephoff
JulianKniephoff / default.rb
Created September 30, 2012 08:23
A very readable way to define default keyword style options to a method in Ruby.
module Kernel
# Define default options for a method.
#
# def foo(bar, options = {})
# default options, baz: "qux"
# end
def default(options, default_options)
options.replace(default_options.merge(options))
end
end
VoodooPad Random Page Script Plugin
===================================
A script plugin to add an essential missing feature to the personal desktop
wiki VoodooPad: opening a random page.
Just hit the button in your Plugins menu to open a page randomly picked from
your current document. Every page has an equal probability of appearing;
independent of how many aliases it has. Also this plugin does not pick the
files you store in your VoodooPad document.
module ApplicationHelper
def b(value, options = {})
options = {
:true => :positive,
:false => :negative,
:scope => [:boolean],
:locale => I18n.locale
}.merge options
boolean = !!value
CMAKE_MINIMUM_REQUIRED(
VERSION
2.8
)
PROJECT(
speech
)
FIND_LIBRARY(