Skip to content

Instantly share code, notes, and snippets.

@jdeisenberg
jdeisenberg / Art.res
Last active July 27, 2020 17:25
bs-fetch "fetch not found"
let fetchData = () => {
Fetch.fetch("data.csv");
}
fetchData();
type marshalled_location = {.
"administrative_area_level_1": string,
"country": string,
"locality": string,
"postal_code": string,
"route": string,
"street_number": string };
let quote = (s:string): string => {
"\"" ++ s ++ "\"";
@jdeisenberg
jdeisenberg / gist:fc954308e1c794b4a20c8bae116f2e4f
Last active March 22, 2018 21:41
Test of lists vs. JSON in reason
[@bs.module] external lab : Js.t({..}) = "./lab.json";
let components = lab##components;
let length = list => {
let rec addUpLength = (innerList, currentTotal) =>
switch (innerList) {
| [] => currentTotal
| [head, ...tail] => {Js.log(head); Js.log("****"); addUpLength(tail, currentTotal + 1)}
@jdeisenberg
jdeisenberg / QueryString.re
Last active August 22, 2019 04:25
Parse a query string in ReasonML
/*
* Define a type that can be either a single string or a list of strings
*/
type queryItem =
| Single(string)
| Multiple(list(string));
/*
* Make a string “safe” by
open Array;
let concatStringArray = (arr : array(string)) : string =>
fold_left( (acc, item) => acc ++ item, "", arr);
let s = "operation";
let d = None;
let parsingResult = "something I parsed";
Js.log(concatStringArray ([|
@jdeisenberg
jdeisenberg / problem_spec.md
Last active August 14, 2017 13:21
Description of a problem to solve in Haskell

Here's the problem at hand: I have a file with some data like this:

   Name;email;zip;status
   Joe Doakes;[email protected];07123;A
   Nancy Smith;[email protected];98146;I
   Armando Gonzales;[email protected];77194;A

I want to semi-anonymize it by changing all the email addresses to end in @example.com and replacing the ZIP code with a random 5-digit number.

@jdeisenberg
jdeisenberg / gist:0ee8864a8e30e31726225382106b9b68
Created August 11, 2017 14:57
Confusing output from purescript REPL
> :clear
> import Prelude
> newtype Cat = Cat {name::String, breed::String}
> myCat = Cat {name: "Marco", breed: "Domestic shorthair"}
> :t myCat
Cat
> :paste
… getName :: Cat -> String
… getName (Cat c) = c.name
@jdeisenberg
jdeisenberg / Initials.hs
Last active May 8, 2017 14:14
Find frequency and cumulative frequency of first letter of last name initials
import System.IO
import Numeric
import qualified Data.Map as M
-- Given a file with people's first and last initials,
-- one person per line, find the frequency and cumulative
-- frequency for each letter.
freqCount:: M.Map Char Int -> String -> M.Map Char Int
freqCount m s =
@jdeisenberg
jdeisenberg / socketstuff.js
Last active January 3, 2016 04:23
socket stuff
var sockets = [null, null, null];
var areas = ["main", "auxiliary", "extras"];
function receive_message(event) {
console.log(event.data);
}
function open_connections() {
for (var i = 0; i < sockets.length; i++) {
sockets[i] = new WebSocket("ws://localhost:3001");
@jdeisenberg
jdeisenberg / domReplacer.html
Created September 10, 2014 18:52
Crawl through DOM to replace text content
<!DOCTYPE html>
<html xml:lang="en" lang="en"
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Text Replacer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function domReplacer(startNode, replaceFunction) {
textReplacer(startNode.firstChild, replaceFunction);