Skip to content

Instantly share code, notes, and snippets.

View DeTeam's full-sized avatar
🍪
le cookie

Timur Amirov DeTeam

🍪
le cookie
View GitHub Profile
@DeTeam
DeTeam / core-async-thread.clj
Last active June 27, 2017 14:40
Example of killing a thread from core async pool. After thread is dead — new one will be created.
(ns deteam.core-async-sandbox
(:require [clojure.core.async :as async]
[clojure.tools.logging :as log]))
(def tmp-chan (async/chan 5))
(def waiting-time-ms 500)
(defn -main []
(log/info "Started the program")
@DeTeam
DeTeam / codeship.sh
Created December 30, 2014 19:13
Codeship Haskell setup commands
# Codeship + Haskell (cabal)
cabal update
cabal install cabal-install
export PATH=$HOME/.cabal/bin:$PATH
cabal sandbox init
cabal install --only-dependencies --enable-tests
cabal configure --enable-tests
cabal build
module Main where
import Control.Monad.State (StateT(..), runStateT, modify, get)
import Control.Monad.Reader (ReaderT(..), runReaderT, ask)
import Control.Monad.Trans.Class (lift)
import Control.Monad.IO.Class (liftIO)
type MySuperMonad = ReaderT String (StateT Int IO)
<!doctype html>
<html>
<head>
<!-- ALL OTHER FILES -->
<style>
.green {
color: green;
}
</style>
<script src="jquery-1.11.1.js"></script>
@DeTeam
DeTeam / state-osci.hs
Created May 19, 2014 08:22
State-based oscilator in haskell
module Main where
import Control.Monad.State.Lazy
step start stop (currentValue, modifier) = (currentValue, newState)
where reverseModifier = (currentValue + modifier > stop) || (currentValue + modifier < start)
modifier' = if reverseModifier
then
-modifier
else
@DeTeam
DeTeam / buy-stuff-state.js
Created March 30, 2014 18:48
Doing some functional stuff with state data structure. Here's an example of usage.
var housePrice = 15000;
var buyCoke = setupPrice('coke', 50);
var buyHotDog = setupPrice('hot-dog', 150);
var buyHouse = setupPrice('house', housePrice);
var salary = 500;
var getPaid = modifyState(sum.bind(null, salary));
var saveForHouse = replicate( Math.floor(housePrice / salary), getPaid);
@DeTeam
DeTeam / maybe-applicative-functor.js
Last active August 29, 2015 13:57
Full of fun Maybe ap functor in JS.
// The Type
function Maybe(){};
// `Nothing` Type Constructor
function Nothing() {
this.value = null;
};
// `Just` Type Constructor
function Just(value) {
module Main where
import Control.Monad.State.Lazy
import Control.Applicative ((<$>), (<*>))
myInc = state (\n -> (n, n * n))
myState = (,) <$> myInc <*> myInc
main = print $ computeState
@DeTeam
DeTeam / ApiSettings.hs
Created January 15, 2013 10:59
Thinking about data-type for storing all API-related settings.
data ApiSettings = ApiSettings {
settingsAuth :: Maybe BasicAuth
}
// It JavaScript it's okay to do like that:
friend.gift = function(){
var deferred = $.Deferred();
somewhenInFuture(function(gift){
deferred.resolve(gift);
})
return deferred.promise();
}