Skip to content

Instantly share code, notes, and snippets.

👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
Block or report user

Report or block therealklanni

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fixed-spec.js
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) {
View keybase.md

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:

View authorized.ex
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 Jan 24, 2016
Rollup build script (good example)
View rollup.build.js
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 Jan 24, 2016
Rollup build script (bad example)
View rollup.build.js
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'
View async-quicksort.js
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
View yl-example.js
// 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']
View y-example-7.js
// 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 => {
View y-example-6.js
const Yfact = Y(inner => n => n <= 1 ? n : n * inner(n - 1))
console.log(Yfact)
// n => n <= 1 ? n : n * inner(n - 1)
View y-example-5.js
const Y = Yfact => {
return (x => Yfact(v => x(x)(v)))(x => Yfact(v => x(x)(v)))
}
You can’t perform that action at this time.