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 / 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) {
@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 / 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
<!doctype html>
<html>
<head>
<!-- ALL OTHER FILES -->
<style>
.green {
color: green;
}
</style>
<script src="jquery-1.11.1.js"></script>
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)
Shoes.app(:title => 'FTP File Uploader', :width => 500, :height => 400, :resizable => false) do
require 'net/ftp'
background gradient rgb(255, 255, 255), rgb(150, 150, 150), :angle => 45
stack :margin => 20 do
end
end
Shoes.app(:title => 'FTP File Uploader', :width => 500, :height => 400, :resizable => false) do
require 'net/ftp'
background gradient rgb(255, 255, 255), rgb(150, 150, 150), :angle => 45
stack :margin => 20 do
caption 'FTP File Uploader'
flow :margin => 3 do
Shoes.app(:title => 'FTP File Uploader', :width => 500, :height => 400, :resizable => false) do
require 'net/ftp'
background gradient rgb(255, 255, 255), rgb(150, 150, 150), :angle => 45
stack :margin => 20 do
caption 'FTP File Uploader'
flow :margin => 3 do
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Char
{-
http://projecteuler.net/index.php?section=problems&id=22
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
tmp = Tempfile.new("out")
tmp << "things"
tmp.close
puts File.read(tmp.path)