Skip to content

Instantly share code, notes, and snippets.

# returnA :: x -> CB x
returnA = (x) -> (callback) -> callback null, x
# bindA :: CB x -> (x -> CB y) -> CB y
bindA = (f, g) ->
(callback) ->
(err, fx) <- f!
if !!err
for i in ./*.jpg; do mv "$i" $(echo "$i" | sed 's/\.jpg\.jpg/\.jpg/'); done
@homam
homam / find grep.sh
Created June 24, 2014 07:55
Find and grep to find a string in all files that match a pattern
find . -type f -name "package.json" -exec grep -l "\"express\"\\s*:\s*\".*4" {} \;
@homam
homam / child-process.ls
Last active August 29, 2015 14:03
Keeping child process open in node. Instead of Ctrl+c use `process.exit 0`
fs = require \fs
_ <- fs.append-file './log.txt', "Child Started #{new Date!}\n"
<- setTimeout _ , 12000
fs.append-file './log.txt', "Child Ended #{new Date!}\n\n"
@homam
homam / jqlsc.ls
Last active August 29, 2015 14:05
Alternative to jq CLI tool using LiveScript
#!/usr/local/bin/lsc -d
# example: echo "[1,2,3,4,5]" | ./jqlsc.ls "sum . map (+ 2)"
{each, obj-to-pairs} = require \prelude-ls
lsc = require \LiveScript
global <<< require \prelude-ls
trim = -> if it[*-1] == \; then it.substr 0, it.length - 1 else it
import XCPlayground
import Foundation
import UIKit
import SpriteKit
var even = { x in x%2 == 0 }
var odd = { x in !even(x) }
var letters = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
@homam
homam / Web-Rich-Media-Banners-API-Simple.md
Created September 8, 2014 07:38
Web Rich Media API - Simple

Web Rich Media Banners API

This API is going to be used in our Web Rich Media Banners. The purpose is to be able to support interstitial interactive banners and get subscribers directly from banners.

JSONP

The Request URL always contains Query String parameter: jsonp.

Response content-type must be: application/javascript.

@homam
homam / find-and-replace-all.ls
Created September 15, 2014 09:50
Find and Replace in String and Files in JavaScript
fs = require \fs
{map} = require \prelude-ls
{promises: {new-promise, parallel-limited-sequence, from-error-value-callback, from-void-callback, promise-monad}} = require \async-ls
find-and-repalce = (regex, replacement, file) -->
new-file = ""
last-index = 0
while m = regex.exec file
new-file := new-file + (file.substring last-index, m.index) + replacement m
@homam
homam / stats-test.ls
Last active August 29, 2015 14:07
Statistics, Probability, Confidence Interval
{sqrt} = require \prelude-ls
{
find-propability-of-population-mean-in-a-range-for-continuous-variable
find-confidence-interval-of-population-mean-for-continuous-variable
find-propability-of-population-mean-in-a-range-for-binomial-variable
find-confidence-interval-of-population-mean-for-binomial-variable
} = require \./stats
round = (precision, n) -->
tens = 10**precision
# *-state-maker :: (model) -> {render, cleanup}
# state-maker s are modules and can be defined in different modules
# render :: (all-state-makers, callback) -> void
# all-state-makers is an object, it's useful for explicitly specifying which states are accessible from this render function.
second = (_, b) -> b
init-state-maker = (_) ->
<- second ->
{