Skip to content

Instantly share code, notes, and snippets.

View lilactown's full-sized avatar
🌊
Do not follow in the footsteps of the sages. Seek what they sought.

Will Acton lilactown

🌊
Do not follow in the footsteps of the sages. Seek what they sought.
View GitHub Profile
@lilactown
lilactown / pledge.re
Created September 28, 2017 03:18
Making it easier to keep our Promises
module type Promise = {
type t 'a;
let then_: ('a => t 'b) => t 'a => t 'b;
let resolve: 'a => t 'a;
let all: array (t 'a) => t (array 'a);
let race: array (t 'a) => t 'a;
let make: (resolve::('a => unit) [@bs] => reject::(exn => unit) [@bs] => unit) => t 'a;
};
module Make (P: Promise) => {
@lilactown
lilactown / example.js
Last active September 19, 2017 17:05
fetch('/endpoint')
.then(res => {
if (res.ok) {
return res.json();
}
throw new Error(res.statusText);
})
// handle response here
.then(({ status, payload }) => {
switch (status) {
@lilactown
lilactown / promises.re
Last active August 20, 2022 07:56
Notes on using JavaScript Promises in ReasonML/BuckleScript
/**
* Making promises
*/
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok"));
/* Simpler promise creation for static values */
Js.Promise.resolve("easy");
Js.Promise.reject(Invalid_argument("too easy"));
@lilactown
lilactown / unfold.re
Last active September 17, 2017 15:18
external _unfold : ('a => Js.t 'whatever) => 'a => stream 'b = "unfold" [@@bs.module "most"];
module Unfold = {
type t 'value 'seed =
| Value 'value 'seed
| Done;
};
external convertUnfoldValue : Js.t {. _done : bool} => Js.t {. seed : 'a, value : 'b} =
"%identity";
@lilactown
lilactown / fizzbuzz.re
Created September 10, 2017 23:28
FizzBuzz in Reason
let fizzbuzz num => {
let shouldFizz = num mod 3 == 0;
let shouldBuzz = num mod 5 == 0;
switch (shouldFizz, shouldBuzz) {
| (true, true) => "FizzBuzz"
| (true, false) => "Fizz"
| (false, true) => "Buzz"
| (false, false) => string_of_int num
}
};
@lilactown
lilactown / user.clj
Created August 10, 2017 16:22
Figwheel + nREPL + CIDER boilerplate
;; Something similar to this goes in project.clj:
;;
;; :profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.2"]
;; [figwheel-sidecar "0.5.10"]]
;; :source-paths ["ui_src" "dev"]}}
(ns user
(:require [figwheel-sidecar.repl-api :as ra]))
(defn fig-start [] (do
type Reduced<Value> = { value: Value, completed: boolean };
type Reducer<Accumulator, Input> = (whatever: Accumulator, input: Input) => Accumulator | Reduced<Accumulator>;
type Transducer<Input, Output> =
<Accumulator>(reducer: Reducer<Accumulator, Output>) => Reducer<Accumulator, Input>;
// utils
function reduced<Value>(value: any, completed: boolean): Reduced<Value> {
return { value, completed };
}
@lilactown
lilactown / promise.cljc
Created May 16, 2017 17:11
A simple macro to aid with dealing with promise chains in ClojureScript
(ns lilactown.promise)
;; This is a simple macro to aid with dealing with promise chains
;; in ClojureScript. Often external JS libraries (such as request-promise
;; or other async libs) return a promise object, so we write code like:
;;
;; (-> promise-value
;; (.then do-something)
;; (.then #(do-something-else %))
;; (.then (fn [val] (and-again val)))
@lilactown
lilactown / erl-get
Last active February 28, 2017 03:49
A script to download an Erlang program from Gist/Hastebin and open a REPL with it compiled and loaded
#!/bin/bash
##########################
# Description:
# Downloads an Erlang program from a Gist or Hastebin, then opens an Erlang shell with it
# compiled and loaded.
#
# Installation:
# Download and install this script in /usr/local/bin
#

Keybase proof

I hereby claim:

  • I am lokeh on github.
  • I am lilactown (https://keybase.io/lilactown) on keybase.
  • I have a public key ASCapdmYRqCZdN5lH20UYAK97qiesOSuzTC7P68aBL04Xwo

To claim this, I am signing this object: