Skip to content

Instantly share code, notes, and snippets.

View therealklanni's full-sized avatar
👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
View GitHub Profile
@therealklanni
therealklanni / clean_modules.sh
Last active October 17, 2020 22:32
Automatically remove stale modules (based on last-modified date)
# Remove stale modules directories, fast!
#
# Paste or source this file in your shell rc file (should work with Bash and ZSH)
#
# Optionally provide a path as first arg, and optionally a duration in days as second arg (default=30)
# e.g. clean_modules ~/github 60
# Remove the "-exec du" line for faster operation (i.e. do not print sizes, which can be slow)
PROJECT_DIR=~/Projects
# If `bfs` is installed, use that for faster searching
@therealklanni
therealklanni / fixed-spec.js
Created January 28, 2019 00:43
Sudoku Checker
import { sudokuVerifier } from '../src/sudoku_verifier'
import problems, { sudoku } from '../problems'
function assertValid(problem, solution) {
expect(
sudokuVerifier({ problem, solution })
).toEqual({ status: 'valid', invalidIndexes: [ ] })
}
function assertIncomplete(problem, solution) {

Keybase proof

I hereby claim:

  • I am therealklanni on github.
  • I am therealklanni (https://keybase.io/therealklanni) on keybase.
  • I have a public key ASBtBpAqGlRXLoRQ-cZhbgTarUvu5VJIqMslZcPK0W6Bpgo

To claim this, I am signing this object:

@therealklanni
therealklanni / authorized.ex
Last active April 9, 2016 22:03
Authorized plug
defmodule Org.Plugs.Authorized do
@behaviour Plug
import Logger
import Plug.Conn
import Phoenix.Controller
def init(default), do: default
def call(%{assigns: %{current_user: current_user}} = conn, role) do
@therealklanni
therealklanni / rollup.build.js
Created January 24, 2016 20:15
Rollup build script (good example)
import { rollup } from 'rollup';
import babel from 'rollup-plugin-babel';
rollup({
entry: 'index.js',
plugins: [ babel({ presets: [ 'es2015-rollup' ] }) ]
}).then(bundle => Promise.all([
bundle.write({
dest: 'dist/module.js',
format: 'cjs',
@therealklanni
therealklanni / rollup.build.js
Created January 24, 2016 20:10
Rollup build script (bad example)
import { rollup } from 'rollup';
import babel from 'rollup-plugin-babel';
rollup({
entry: 'index.js',
plugins: [ babel({ presets: ['es2015-rollup'] }) ]
}).then(bundle => bundle.write({
dest: 'dist/module.js',
format: 'cjs',
sourceMap: 'inline'
function asyncQuicksort(xs = []) {
// get the "head" and "tail" of the array
let [h, ...t] = xs
// create the initial Promise
return new Promise((res, rej) => {
// resolve immediately if "head" was undefined
if (!h) return res([])
// recurse for the "left" half of the partition
asyncQuicksort(t.filter(a => a <= h)).then(a => {
// recurse for the "right" half of the partition
// pronounce Yl like "while" ;)
let Yl = Y(f => (g, i) => {
let r = g(i - 1)
return r !== false ? r : f(g, i - 1)
})
// extremely contrived example using Yl
let people = [ 'Shannon', 'Joseph', 'Eric', 'Mike']
// original
const Y = f => (x => f(v => x(x)(v)))(x => f(v => x(x)(v)))
// expanded as
const Y = f => {
// return the result of this IIFE
// f produces the fixed point function
return (x => {
// outer:
f(v => {
const Yfact = Y(inner => n => n <= 1 ? n : n * inner(n - 1))
console.log(Yfact)
// n => n <= 1 ? n : n * inner(n - 1)