Skip to content

Instantly share code, notes, and snippets.

@homam
homam / expression-parser.ls
Last active October 4, 2016 00:33
FP101x Functional Parsers and Monads in LiveScript
{any, tail, fix, concat-map, empty, map, foldr1, id, sqrt, sin, abs} = require \prelude-ls
is-digit = (c) -> 48 <= (c.char-code-at 0) <= 57
is-space = (c) -> code = c.char-code-at 0 ; [9, 32] |> any (== code)
# the argument of parse-digit, parse-pint and parse-decimal must be a valid parsable string
parse-signed-number = (parser, cs) -->
@homam
homam / spawn-lazy-promises.ls
Created December 7, 2014 21:44
spawn lazy primises
next-i = do ->
j = 1
(i) ->
success, reject <- new Promise _
success i + j
spawn = (gen) ->
success, reject <- new Promise _
next = (last) ->
@homam
homam / LiveScript in 15 minutes.md
Last active August 29, 2015 14:12
LiveScript in 30 minutes

Installation

$ npm install -g LiveScript

Start LiveScript REPL:

$ lsc -d

Syntax

{map, foldr1} = require \prelude-ls
class Plottable
(@continuations, @options, @_plotter) ->
plotter: ({result, view}) ~>
@_plotter @continuations, @options, {result, view}
timeseries = new Plottable do
(chart, callback) -> callback null, chart # noop continuation
@homam
homam / nginx
Last active August 29, 2015 14:14 — forked from psd/nginx
map $query_string $new_url {
~a=1 http://www.gov.uk/1;
~a=2 http://www.gov.uk/2;
~a=3&b=1|b=1&a=3 http://www.gov.uk/31;
~\ba=4\b.*\bb=2\b|\bb=2\b.*\ba=4\b http://www.gov.uk/42;
}
server {
server_name lrc.businesslink.gov.uk;
@homam
homam / promise-unit-bind-with-error.ls
Last active August 29, 2015 14:16
Binding ES6 Promises
unit = (x) -> new Promise (resolve, reject) ->
resolve x
# or just unit = -> Promise.resolve it
double = (x) -> new Promise (resolve, reject) ->
<- set-timeout _, 500
resolve 2 * x
square-root = (x) -> new Promise (resolve, reject) ->
@homam
homam / lazier-powerset.ls
Last active August 29, 2015 14:16
Lazy Power Set using ES6 Generators
#!/Users/homam/dev/LiveScript/bin/lsc
{map, filter, id, concat-map, empty, find, any, intersection, zip, drop, take, maximum} = require \prelude-ls
trace = -> console.log it; it
json = -> JSON.stringify it, null, 2
emit = ({i, value}) ->
{
i
value: if (do -> any do
@homam
homam / Profit.md
Last active August 29, 2015 14:20
Profit

$$ Profit = Revenue - Cost $$

For a well targeted campaign, σ of revenues for each subscriber is small: $$ Revenue = ARPU \times Subscribers $$

Hence:

@homam
homam / Mobile Academy Content API
Last active August 29, 2015 14:22
Mobile Academy Content API
## Content API Information
### User Authentication
You should pass a special header containing the user ID in every API request: `-H "x-userid:3"`
We get the `userid` from _Authentication API_ that is described in another document.
Please use `x-userid:3` for testing purposes.
#return json
colors = d3.scale.category20!
view, result <- id
view.innerHTML = ""
view =
d3.select view .append \svg .attr \width, "100%" .attr \height, "100%" .node 0
window.view = view