Skip to content

Instantly share code, notes, and snippets.

View roman's full-sized avatar

Roman Gonzalez roman

View GitHub Profile
@roman
roman / background.clj
Last active August 29, 2015 14:07
Naive approach for Bg process handling using Rx + Clojure
(ns clj-playground.background
(:require [rx.lang.clojure.core :as rx]
[rx.lang.clojure.interop :as rxi]
[clj-http.client :as http]
[monads.core :refer [Monad]]
[monads.macros :as monadic])
(:import
[java.util.concurrent Executors]
[rx Observable]
[rx.schedulers Schedulers]))
(be/util-eval-on-load ("evil" "be-scala" "scala-mode2")
(evil-define-key 'normal scala-mode-map
(kbd ",gi") 'be/init-scala-repl
(kbd ",rr") 'be/init-sbt-runner
(kbd ",rt") 'be/init-sbt-tester
(kbd ",fl") 'be/scala-repl-load-file
(kbd ",fr") 'be/scala-repl-load-file
(kbd "M-.") 'sbt-find-definitions))
@roman
roman / Example.hs
Last active August 29, 2015 14:03
Example of an "Actor-Like" Reactive Extension management in Haskell
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Rx.Actor
( GenericEvent, EventBus
, ActorBuilder, ActorM, ActorDef, Actor, RestartDirective(..), InitResult(..)
, SupervisorBuilder, SupervisorStrategy, SupervisorDef, Supervisor
-- ^ * Actor Builder API
, defActor, actorKey, preStart, postStop, preRestart, postRestart
, onError, desc, receive
@roman
roman / LongPolling.hs
Created January 31, 2014 21:52
Composition of Observables in rxhs
getLastPublishedMessages :: PubSub -> ClientId -> IO (Either SomeException [WebResponse])
getLastPublishedMessages pubsub cid = do
msubject <- getClientSubject pubsub cid
case msubject of
Just subject ->
Observable.toEither .
Observable.first .
Observable.filter (not . null) .
Observable.bufferInterval (Time.microSeconds 1000) .
Observable.concatMap excludeClientId $
@roman
roman / HelloShelly.hs
Created December 16, 2013 23:24
Experiments with Shelly
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Control.Lens
import Control.Monad.Trans (MonadIO(..))
@roman
roman / CloudUtil.hs
Last active December 30, 2015 20:09
Possible memory leak in Maestro.Distributed.Process.Platform.Supervisor v2
{-# LANGUAGE ScopedTypeVariables #-}
module CloudUtil
( module Control.Distributed.Process
, cloud
, cloudWithRemotable
, cloudWithRemotableAsync)
where
import Control.Exception (try, SomeException, bracket)
import Control.Concurrent (threadDelay)
@roman
roman / Monad.hs
Last active December 29, 2015 03:39
Naive Async Monad implementation Now without the extra-thread problem (paired with @ujihisa!!!!)
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Maestro.Control.Concurrent.Async
( AsyncM(..)
, AsyncStep(..)
, module Control.Concurrent.Async
) where
import Control.Monad.Trans (MonadIO(..))
import Control.Monad.Error (MonadError(..))
@roman
roman / Ghetto.hs
Created September 26, 2013 02:32
Session Haskellñol
module Main where
main :: IO ()
main = putStrLn "Hello World"
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
@roman
roman / Makefile
Created August 31, 2013 01:45
A way to build cabal files with multiple executables that share the same exact build-depends, without repeating packages over and over again!
# Assuming all cabal gen files (myproject.cabal.tmpl, build_depends and test_build_depends)
# are in gen/cabal/ folder
CABAL_FILE = myproject.cabal
CABAL_GEN_FILES = $(wildcard gen/cabal/*)
$(CABAL_FILE) : $(CABAL_GEN_FILES)
@echo "Building new cabal file"
@bin/build_cabal_file.sh \
gen/cabal/maestro-proxy.cabal.tmpl \
@roman
roman / Confetti.hs
Created August 16, 2013 17:08
ghc: panic! (the 'impossible' happened) (GHC version 7.6.3 for x86_64-unknown-linux): tc_hs_type: record Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
module Confetti where
type Greeting = String
data Hello
= NoGreet
| Hello { _helloGreet :: Greeting }
| Hallo Greeting { _helloGreet :: Greeting }