Skip to content

Instantly share code, notes, and snippets.

@robkuz
robkuz / Main.js
Last active May 6, 2016 13:29
Access Global Object from Purescript
"use strict";
// module Main
exports.instGlobal = function(name){
return function (value) {
global[name]=value;
return global[name];
}
}
@robkuz
robkuz / typesig.md
Created April 26, 2016 15:41
Why need the full blown type signature?

I have the following value and its signature

type JsonResponse = Affjax.AffjaxResponse Json
getUser :: forall e m. (MonadAff (ajax :: Affjax.AJAX | e) m) => String -> m (Either Error JsonResponse)
getUser user = liftAff $ attempt $ Affjax.get $ "http://someservice.com?user=" ++ user

Now I want to use that in combination with a Maybe. Easy enough just use map (or the alias operator)

applyUser' = getUser <$> Just "Bob"
@robkuz
robkuz / main.md
Created April 26, 2016 11:29
Using a synonym for a Monad

Id like to make the signature of foo a bit better readable

foo :: forall e m. (MonadAff (ajax :: AJAX | e) m) => m (Either Error (AffjaxResponse Json))

What I'd like to do is

type AjaxAff = MonadAff (ajax :: AJAX | e)
foo :: forall m. (AjaxAff m) => m (Either Error (AffjaxResponse Json))

but this gives me

@robkuz
robkuz / Aff.md
Last active April 25, 2016 15:41
Fun with Aff

I understand what get1 does and that is fine

get1 = attempt $ Affjax.get "http://www.google.com"

I think I know what liftAff does BUT the compiler knows better a

get2 = liftAff $ attempt $ Affjax.get "http://www.google.com"

and gives the following the error message

@robkuz
robkuz / KeyValueMap.purs
Last active August 11, 2022 16:50
Some thoughts on Purescript Tuples, Records and Dict
--The only way to create what other languages call a **Dictionary** Is to create a `Array (Tuple String a)`.
--This is excessively lengthy (imo). Specifically as the change to 0.7 also removed the Haskell Tuple syntax.
--example
d = [Tuple "x1" 1, Tuple "x2" 2, Tuple "y1" 3, Tuple "y2" 4]
-- prior t0 0.7 you could at least do it this way
d = [("x1", 1), ("x2", 2), ("y1", 3), ("y2", 4)]
-- the problem with the above however is that it is possible to assign the same "label" multiple times.
@robkuz
robkuz / normalizer.hs
Created February 23, 2016 10:42
How to extract a nested unbalanced structure
-- I was thinking on how to normalize a structure like
-- (Either String (Either String Int)) into
-- Either String Int
-- my first attempt was to pattern match
normalizer :: (Either String (Either String Int)) -> Either String Int
normalizer n = do
case n of
Left l -> Left l
Right r -> r
@robkuz
robkuz / SassMeister-input.scss
Created April 16, 2015 11:17
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
$default-font-size: 14px;
$hc-yellow: yellow;
$hc-darkblue: blue;
$hc-darkyellow: darkyellow;
$hc-blue: blue;
@robkuz
robkuz / gist:03d4900eb9c2fd5ad641
Created September 1, 2014 09:31
A Elixir Parser - Transforming a List of Tokens into a "Tree" (List of List)
defmodule Parser do
def read(input) do
tokens = Tokenizer.tokenize(input)
parse tokens, []
end
def parse([], stack) do
stack
end
@robkuz
robkuz / Example1.clj
Last active December 25, 2015 04:29
I have an adjust-state fn which I use to, well adjust the state ;-) thru which I stream all my events. And then I have a changedx fn (basically its the riemann.streams.changed fn with added debug output). Now If I run this I get multiple outputs for every host/service combination event thou the state hasn't changed. If I stream events directly f…
(defn transform-event [event options]
(let [ event-path (event-to-vector event)
state-values (find-state-thresholds event-path options)
state (find-state (:metric event) state-values)
new-event (assoc event :state state)]
new-event))
(defn adjust-state [options & children]
(fn [e]
(let [ new-event (transform-event e options)]
@robkuz
robkuz / gist:6689840
Last active December 23, 2015 20:29
Run on Linux. I completely do not understand why this gives me an error
(require '[clojure.java.shell :as shell])
(require '[clojure.contrib.string :as string])
(def foo (-> (shell/sh "df" "-P")
(:out)
(string/split-lines)
(map (fn [z] z))))
foo
; IllegalArgumentException Don't know how to create ISeq from: user$fn__2690 clojure.lang.RT.seqFrom (RT.java:505)