Skip to content

Instantly share code, notes, and snippets.

@TheDahv
TheDahv / Compromise.re
Created September 22, 2020 02:06
Example of using Bucklescript bindings and ReasonML for JavaScript package interop
type t;
[@bs.module] external make: string => t = "compromise";
module Extraction = {
/* return an array of meta-data for the adjectives and their adverbs */
[@bs.send] external adjectives: t => t = "adjectives";
/* return an array of meta-data for the adverbs in this text */
[@bs.send] external adverbs: t => t = "adverbs";
@TheDahv
TheDahv / .block
Last active July 7, 2020 03:47
COVID in WA State
license: mit

Keybase proof

I hereby claim:

  • I am thedahv on github.
  • I am thedahv (https://keybase.io/thedahv) on keybase.
  • I have a public key ASCW6Esb-WTGH3uL7pDZRhrg6-PwRYlADu73U8F1Top4OAo

To claim this, I am signing this object:

@TheDahv
TheDahv / annotated-app.js
Last active March 30, 2018 06:29
State flow control (Redux, Flux, etc.) in 100 lines or less
/**
* This example tries to show how a one-way state flow control library--similar
* to libraries like Redux, Flow, Elm, etc.--could work. For a quick refresher
* on the problem we're solving, we want a way to:
*
* - make the state of our app easier to find and express
* - confine changes to our state to clear, simple, pure functions
* - update the app in response to events--either from the user or from the
* browser
*
@TheDahv
TheDahv / mtm.js
Created November 13, 2017 23:13
Moz The Monster snippet - https://codepen.io/TheDahv/pen/BmZRaj
/**
* A silly little snippet to get #MozTheMonster out from under your bed and
* hiding under the source code of your web page.
*
* For devs reading this to evaluate and/or learn JS, please don't follow this
* style. It is not meant to be readable nor maintainable, and I would handily
* reject this kind of code in my professional contexts. It takes a *bunch* of
* hacks and shortcuts to keep code small (I was originally challenging myself
* to fit it into a Tweet...not gonna happen).
*
@TheDahv
TheDahv / recursive-walking.elm
Last active September 23, 2016 16:05
Figuring out how to model and walk recursive relationships in Elm
type alias Content =
{ title : String
, copy : String
, children : Children
}
type Children
= Children (List Content)
if ENV['RACK_ENV'] == 'development'
# Connect to development db
elsif ENV['RACK_ENV'] == 'test'
# Connect to test db
else
# Last case. Connect to production
end
## Example using case statement
switch ENV['RACK_ENV']
@TheDahv
TheDahv / template.fs
Created April 23, 2012 19:01
FSharp Html Templating
namespace FSharpTemplate
module Template =
type HtmlElement =
| Html of HtmlElement list
| Head of HtmlElement list
| Title of string
| Body of HtmlElement list
(* id, class, children *)
| Div of string * string * HtmlElement list
@TheDahv
TheDahv / gist:2173457
Created March 23, 2012 18:22
NPM Install Failure Report
# node -v => v0.6.13
# npm -v => 1.1.9
# python (IronPython) -v => IronPython 2.7.1 (2.7.0.40) on .NET 4.0.30319.17379
PS C:\Applications\node\js-browser-automation> npm install jsdom
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/request
@TheDahv
TheDahv / gist:2142285
Created March 20, 2012 23:11
Teach Cromer how to do JavaScript
// wrapped in anonymous function to protect against
// leaks to global NS
(function () {
// Factory to create objects
var make_thing = function (initial_value) {
var thing = that = {};
thing.value = initial_value;
thing.dosomething = function () {
return that.value; // 'that' is 'closed over'