Skip to content

Instantly share code, notes, and snippets.

View edofic's full-sized avatar

Andraž Bajt edofic

View GitHub Profile
@edofic
edofic / sum10.hs
Last active June 5, 2017 05:58
A few soulutions to SUM10 (finding pairs in a list where their sum is 10)
module Main where
import Control.Monad (guard)
import Data.List (tails, sort, group)
import qualified Data.Discrimination as D -- package `discrimination`
import qualified Data.IntSet as IS -- package `containers`
example :: [Int]
example = [-7,1,2,3,5,5,7,17]
@edofic
edofic / indirect.py
Created May 15, 2017 06:42
Indirect parametrization in pytest
import pytest
@pytest.fixture()
def user(request):
user = 'mock user'
if hasattr(request, 'param'):
user += ': {}'.format(request.param)
return user
@edofic
edofic / Effects.elm
Last active October 3, 2016 16:49
Coproduct encoding of effects in Elm
port module Main exposing (..)
-- effect types
type Prompt u
= Read (String -> u)
| Write String u
type Api u
= Get Int (String -> u)
@edofic
edofic / urm.hs
Created September 23, 2016 21:48
Universal Registry Machine and a relocatable DSL for it
{-# LANGUAGE RecursiveDo #-}
import Control.Monad
import Control.Monad.Free
import Control.Monad.Writer
import Data.Functor.Identity
data Instruction = End
| Inc Int Int
| DeB Int Int Int

Keybase proof

I hereby claim:

  • I am edofic on github.
  • I am edofic (https://keybase.io/edofic) on keybase.
  • I have a public key whose fingerprint is DBAE 9F54 A9E7 31DE 557E E95F 7B7F 9EFB 7B09 5BF9

To claim this, I am signing this object:

@edofic
edofic / compose.scala
Created May 27, 2016 08:24
Structural function composition in Scala
scala> val f = (_: Int) + 1
f: Int => Int = <function1>
scala> val g = (_: Int).toString
g: Int => String = <function1>
scala> case class Compose[a,b,c](f: a => b, g: b => c) extends Function[a,c] {
| def apply(a: a): c = g(f(a))
| }
defined class Compose
@edofic
edofic / zoom.nix
Last active April 3, 2016 09:20
Zoom.us client nix expression
{ stdenv, fetchurl
# Linked dynamic libraries
, glib, gstreamer, libuuid, mesa, pulseaudioFull, qt55, sqlite, xorg
}:
stdenv.mkDerivation {
name = "zoom";
version = "1.1.44485.0317";
@edofic
edofic / di.js
Created March 14, 2016 10:52
dependency injection in JS via eval
function run(exp) {
var magic = "MAGIC!";
return eval(exp);
}
run("1") //1
run("'foo'") //"foo"
run("magic") //"MAGIC!"
@edofic
edofic / final_effects.hs
Created January 19, 2016 14:13
(Not really)Extensible effects using final encoding of handlers
module Main where
import Control.Concurrent.MVar
data Reader (m :: * -> *) (a :: *) = Reader { ask :: m a }
data State m s = State { get :: m s
, put :: s -> m ()
}
@edofic
edofic / hack.py
Created January 7, 2016 14:38
computed properties on python modules
import sys
class Hack(object):
bar = 2
@property
def foo(self):
return 1
sys.modules['hack'] = Hack()