Skip to content

Instantly share code, notes, and snippets.

View alanrsoares's full-sized avatar

Alan Soares alanrsoares

View GitHub Profile
const assert = f => ([a, b]) =>
(x => x === b
? { passed: true }
: {
failed: true,
message: `- expected f(${a}) to be ${b}, but was ${x}`
}
)(f(a))
const runTests = (cases, f) => {
@alanrsoares
alanrsoares / currencyFormatter.js
Last active August 2, 2016 05:41
Agnostic, extensible and composable set of functions for formatting numbers to currency
// :: delimitGroups = (number, string) => string => string
const delimitGroups = (groupSize, delimiter) => s =>
s.split('')
.reduceRight((acc, x, i) =>
`${x}${(s.length - 1 - i) % groupSize ? '' : delimiter}${acc}`)
// :: format = number => object => string
export const format = options => n =>
(([left, right]) =>
`${options.symbol}${
http://jsbin.com/capeyinite/edit?output
class Observable {
constructor(value) {
this.value = value
this.events = { change: [] }
}
update(updateFn) {
this.value = updateFn(this.value)
this.events.change.forEach(fn => fn(this.value))
}
class Observable {
constructor(value) {
this.value = value
this.events = { change: [] }
}
update(updateFn) {
this.value = updateFn(this.value)
this.events.change.forEach(fn => fn(this.value))
}
@alanrsoares
alanrsoares / index.html
Created October 9, 2017 20:50
JS Bin a vanilla js + html & css analog clock // source http://jsbin.com/goyemuzabi
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="a vanilla js + html & css analog clock">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link href="https://fonts.googleapis.com/css?family=Share+Tech+Mono" rel="stylesheet">
<style id="jsbin-css">
body {
@alanrsoares
alanrsoares / index.html
Created October 9, 2017 20:52
JS Bin grouping dynamically generated datasets // source http://jsbin.com/netulis
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="grouping dynamically generated datasets">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js"></script>
@alanrsoares
alanrsoares / index.html
Last active October 9, 2017 20:54
JS Bin - Flow-typed Immutable Matrix data structure // source http://jsbin.com/vuyexi
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@alanrsoares
alanrsoares / index.html
Last active October 23, 2018 23:53
linear color interpolation -> JS Bin// source https://jsbin.com/vukayi
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
#app {
font-family: 'Courier'
}
@alanrsoares
alanrsoares / micro-router-parser.js
Last active March 5, 2019 09:56
Micro router for js
class Router {
routes = {}
baseUrl = ""
constructor(baseUrl) {
this.baseUrl = baseUrl
}
register = (method) => {