Skip to content

Instantly share code, notes, and snippets.

View dszakallas's full-sized avatar
💭
correct is simple

Dávid Szakállas dszakallas

💭
correct is simple
View GitHub Profile
@dszakallas
dszakallas / fp4_recursion.md
Last active October 8, 2016 09:56
FP Training

FP Training 4: Recursion

Agenda

  • Example 1: factorial
  • Example 2: map
  • Example 3: join

1. We implemented the factorial example in JavaScript imperatively:

@dszakallas
dszakallas / ShortestPaths.md
Last active April 3, 2018 23:44
ShortestPaths.md

As a rookie Haskeller coming from imperative languages I am still often shocked how elegantly mathematical problems can be expressed in this great language. Last time a wrote a blogpost about recursion. As an example, I presented the Relation type and implemented an operation to it I called join. If you are familiar with relational algebra you might have recognized that this is a specific case of equijoin, where you join pairs so that the first pair's second element matches the second pair's first element. I was thinking about a more complex problem I could solve with this toolkit, one

@dszakallas
dszakallas / fib.md
Last active April 3, 2018 23:54
Evolving a Fibonacci

We all know about the Fibonacci sequence. Some of us also know a song that uses it to achieve a spiraling feeling (yes, Tool fans!).

In Haskell:

fib 1 = 0
fib 2 = 1
fib x = fib (x - 1) (x - 2)
@dszakallas
dszakallas / hashes.js
Created January 27, 2017 22:20
benchmark hashes
'use strict'
var crypto = require('crypto')
var promise = Promise.resolve()
var data = []
for (var i = 0; i < 1e5; ++i) {
promise = promise.then(function () {
return new Promise(function (resolve, reject) {
@dszakallas
dszakallas / dbVerify.js
Created February 1, 2017 12:11
avoiding callback pyramids
#!/usr/bin/env node
'use strict'
var mysql = require('mysql')
var fs = require('fs')
var path = require('path')
function exitOnError (f) {
return function (err) {
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
deriving (Eq, Ord, Show, Read, Bounded, Enum)
-- and that's it. we have everything we need
-- david@mac:~% stack ghci
-- λ> Monday == Tuesday
-- False
-- λ> Monday == Monday
-- True
-- λ> Tuesday > Monday
@dszakallas
dszakallas / rng.hs
Created February 11, 2017 18:49
randomNumberGenerator
{-# LANGUAGE NoImplicitPrelude #-}
module Rng where
import GHC.Show (Show)
import GHC.Base (Eq, ($))
import GHC.Num ((*), (+), Integer)
import GHC.Float (Float, Double)
import GHC.Real (fromIntegral, (/))
import GHC.Enum (maxBound)
import Data.Int (Int64, Int32, Int16, Int8)
@dszakallas
dszakallas / coroutine.js
Last active February 1, 2018 20:35
Javascript Snippets
// Turn a generator function into a coroutine
const coroutine = (f) => (...args) => {
const g = f(...args) // instantiate the generator
const iter = ({ done, value }) => done // iterate over suspensions
? value
: value.then(
(d) => iter(g.next(d)),
(e) => iter(g.throw(e))
)
return Promise.resolve().then(() => iter(g.next())) // start iterating asynchronously
@dszakallas
dszakallas / readme.md
Last active September 6, 2017 07:55
Modern JavaScripting a MIDI controller

Modern JavaScripting a MIDI controller

Abstract: Blogpost summarizing the challenges of creating a flexible and customizable MIDI controller mapping for Mixxx targeting multiple Novation Launchpad grid controllers.

Keywords: JavaScript, MIDI, Mixxx, ES6 modules, Babel, Flow

I own two Novation Launchpads. The most iconic use-cases of this cool grid controller is launching samples. Launchpad cover videos are very popular on YouTube. These are done by slicing up the songs, and playing back live, spiced with some flashy visual effects.

You can also use launchpads for DJing. While being fit for a handful of things: cueing samples, beatjumping and looping, etc.; the Launchpad have neither a jogwheel nor any rotary controls or faders, so it falls short on functions like scratching or crossfading. Thus, it’s best to use as companion to your other DJ gear.

@dszakallas
dszakallas / KleeneWithTypeClasses.scala
Last active June 20, 2017 11:28
Kleene logic in Scala
/* Copyright 2017 David Szakallas, MIT License */
import simulacrum.{op, typeclass}
@typeclass trait GenKleeneLike[-A] {
@op("|=|") def eq(x: A, y: A): Option[Boolean]
@op("|!|") def ne(x: A, y: A): Option[Boolean]
}
object GenKleeneLike {
class GenKleeneLikeForOption[Opt <: Option[Any]] extends GenKleeneLike[Opt] {
override def eq(x: Opt, y: Opt): Option[Boolean] =