Skip to content

Instantly share code, notes, and snippets.

View stoeffel's full-sized avatar
🦔

Christoph Hermann stoeffel

🦔
View GitHub Profile
@stoeffel
stoeffel / autotools.nix
Last active December 4, 2019 14:55
setup nix
pkgs: args:
with pkgs;
let defaultAttrs = rec {
system = builtins.currentSystem;
builder = "${bash}/bin/bash";
args = [ ./builder.sh ];
setup = ./setup.sh;
gcc = clang;
binutils = clang.bintools.bintools_bin;
baseInputs = [
@stoeffel
stoeffel / Comparison.elm
Last active June 8, 2016 10:21
Predicate / Comparison in elm
import Html exposing (text, div, p)
-- based on https://medium.com/@drboolean/monoidal-contravariant-functors-are-actually-useful-1032211045c4#.r6oaoxdxd
-- Order
concatOrder : Order -> Order -> Order
concatOrder a b =
if a == EQ then
import Html exposing (text)
import String
type alias ZipList a b = List (a -> b)
zipper : ZipList number number
zipper = [(*) 1, (*) 2, (*) 3]
zipper2 : ZipList number number
zipper2 = [(*) 1, (*) 2, (*) 3, (*) 4]
import Html exposing (Html, Attribute, text, div, input, button)
import Html.App exposing (program)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
import List
import String
import Char
import Random
-- Model
import Html exposing (text)
import String
fizzbuzz : Int -> List String
fizzbuzz to =
let
current =
case (to % 3, to % 5) of
(0, 0) -> "Fizz Buzz"
@stoeffel
stoeffel / These.elm
Last active May 26, 2016 20:59
data.these in elm
import Html exposing (..)
type These a b
= This a
| That b
| Both a b
| Neither
const l = console::console.log
const safeProp = prop => R.compose(S.toMaybe, R.prop(prop))
const withDefault = R.curry((def, safeFun) => (...args) => {
const maybe = safeFun(...args)
return S.maybe(def, R.identity, maybe)
})
const name = withDefault('anon', safeProp('name'))
@stoeffel
stoeffel / save-lenses.js
Created January 14, 2016 11:53
save lenses
const log = R.map(R.compose(console::console.log, R.toString));
const saveProp = x => R.pipe(R.prop(x), S.toMaybe)
var xSave = R.lens(saveProp('x'), R.assoc('x'));
var xLens = R.lens(R.prop('x'), R.assoc('x'));
log([
R.view(xLens, {x: 1, y: 2})
, R.view(xLens, {noX: 1, y: 3})
, R.view(xSave, {noX: 1, y: 3})
, R.set(xLens, 4, {x: 1, y: 2})
const even = R.converge(R.equals, [R.always(0), R.modulo(R.__,2)]);
const odd = R.converge(R.equals, [R.always(1), R.modulo(R.__,2)]);
// 1. map/filter implemented with reduce
// map with reduce
const map = (f, functor) =>
R.reduce((acc, next) => R.concat(acc, f(next)), [], functor)
@stoeffel
stoeffel / composeComponent.js
Last active September 25, 2015 20:49
React compose thisless components
import {
compose,
initialState,
didMount
} from 'react';
export const MyComponent = compose(
initialState( () => {
return {
hidden: true