Skip to content

Instantly share code, notes, and snippets.

'use strict'
const fs = require('fs')
// Flattens a nested array recursively.
const flatten = arr =>
arr.filter( Array.isArray ).length
? flatten( Array.prototype.concat( ...arr ) )
: arr
@ronanyeah
ronanyeah / gitCheck.sh
Last active December 21, 2016 18:01
run git status against all folders in the current folder
#!/bin/bash
find . -maxdepth 1 -mindepth 1 -type d -exec sh -c '(echo {} && cd {} && git status -s && echo)' \;
@ronanyeah
ronanyeah / diceTest.js
Last active December 21, 2016 18:01
roll a js dice x times
'use strict'
// Number -> Object
module.exports = rolls =>
Array.from( Array(rolls) )
.map(
() =>
Math.ceil( Math.random() * 6 )
)
.reduce(
@ronanyeah
ronanyeah / nodeReplPlus.sh
Last active December 21, 2016 18:00
supercharge your node repl
#!/bin/bash
# Notes:
# - Requires Node.js to be managed by nvm.
# - Can require packages that are globally or locally installed.
NODE_PATH=$(realpath ${NVM_BIN}/../lib/node_modules) node -e "require(\"/path/to/file.js\")" -i
@ronanyeah
ronanyeah / ExternalCSS.elm
Created December 29, 2016 18:34
Load external CSS in Elm
{--
You *can* load an external CSS file in Elm, but currently,
in Pure Elm that means adding a style element to the body instead of the head.
It does cause a flash of unstyled content, so I think it's only useful
for testing in Reactor.
--}
import Html exposing (..)
@ronanyeah
ronanyeah / PostExample.elm
Created February 15, 2017 13:40
Basic elm http + json demo.
module PostExample exposing (..)
--TO RUN
--1. $ npm install -g elm
--2. $ elm-reactor
--3. Go to `http://localhost:8000/PostExample.elm`.
import Html exposing (Html, button, div, p, strong, text)
import Html.Events exposing (onClick)
import Html.Attributes exposing (style)
const { zipObj } = require('ramda')
// (String, [String]) -> Object
const translate = (path, array) =>
zipObj(
array,
array.map(
value =>
this.$translate.instant(`${path}${value}`)
)
@ronanyeah
ronanyeah / index.html.eex
Created May 13, 2017 12:33
Inject initial values into Elm using Phoenix.
<script src="<%= static_path(@conn, "/js/admin.js") %>"></script>
<script>
Elm.Main.fullscreen({ first_name: "<%= @data.first_name %>" });
</script>
@ronanyeah
ronanyeah / sw.js
Created January 21, 2018 00:18
SW Caching Strategy
const assets = [].map(url => self.location.origin + url);
self.addEventListener("fetch", e =>
e.respondWith(
fetch(e.request)
.then(res => {
if (res.ok && assets.includes(e.request.url)) {
caches.open("cache-name").then(cache => cache.put(e.request, res));
}
return res.clone();
@ronanyeah
ronanyeah / Esc.elm
Created March 3, 2018 18:42
Escape Listener
onEsc : msg -> Decoder msg
onEsc msg =
Decode.map2
(\keyCode key ->
keyCode == 27 || key == "Escape"
)
keyCode
(Decode.field "key" Decode.string)
|> Decode.andThen
(\match ->