Skip to content

Instantly share code, notes, and snippets.

View wegry's full-sized avatar

Zach Wegrzyniak wegry

  • Northeastern University
  • Boston
  • 05:26 (UTC -05:00)
View GitHub Profile
@wegry
wegry / Main.elm
Created May 24, 2018 19:30
Lucrative Hangman app
module Main exposing (..)
import Char
import Set
import Html exposing (Html, pre, text, div, h1, img, button, span)
import Html.Attributes exposing (src)
import Html.Events exposing (onClick)
---- MODEL ----
@wegry
wegry / Tree.bs.js
Last active June 10, 2018 17:50
Toy example of reason codegen
// Generated by BUCKLESCRIPT VERSION 2.2.3, PLEASE EDIT WITH CARE
import * as Block from "stdlib/block";
import * Belt_Array from "stdlib/belt_Array";
function depthFirstTraversal(param) {
if (typeof param === "number") {
return /* array */[];
} else if (param.tag) {
var match = param[0];
@wegry
wegry / Tree.purs
Created June 10, 2018 18:48
Purescript binary tree codegen
module Main where
import Prelude
data Tree a = Empty | Leaf a | Node a (Tree a) (Tree a)
depthFirstTraversal x =
case x of
Empty -> []
Leaf a -> [a]
let range: (int, int) => array(int) = [%bs.raw
(a, b) => {j|
const ranger = {};
ranger[Symbol.iterator] = function* () {
let current = a;
while (a <= b) {
yield a++;
}
}
@wegry
wegry / rebuild_restart.sh
Created July 27, 2018 11:34
Rebuild and restart specific docker-compose containers without restarting docker-compose entirely
rebuild_restart () {
if [ -n "$1" ]
then
echo "Rebuilding and restarting $@"
docker-compose up --build --no-deps -d "$@"
else
echo "You need a container name (e.g. rebuild_restart my-container other-container)"
fi
}
@wegry
wegry / JsonNetExtension.fs
Created November 13, 2018 09:59
Use Option<T> instead of null with Json.NET and F#
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open System
/// F# options-converter
type OptionConverter() =
inherit JsonConverter()
override __.CanConvert t = t.IsGenericType && typedefof<option<_>>.Equals(t.GetGenericTypeDefinition())
override __.WriteJson(writer, value, serializer) =
@wegry
wegry / Tsv.fs
Created November 16, 2018 09:49
Write TSV relatively regularly
module Csv
// Transliterated from https://stackoverflow.com/a/4685745/1924257
module private Internals =
let quote = "\""
let escapedQuote = "\\\""
let delimiter = "\t"
let escapedCharacters = ['\t'; '\n'] |> Set.ofList
@wegry
wegry / server.rs
Last active August 4, 2019 22:56
Basic Rust 2018 Static File Server
use colored::*;
use futures::{future, Future};
use hyper::header::{HeaderName, HeaderValue};
use hyper::service::service_fn;
use hyper::{Body, Request, Response, Server};
use hyper::{Method, StatusCode};
use lazy_static::lazy_static;
use maplit::btreemap;
use std::collections::BTreeMap;
use std::path::Path;
@wegry
wegry / debounce.js
Created February 21, 2019 11:04
Minature debounce borrowed and tweaked from vue-js-tips
// https://github.com/vuejs-tips/tiny-debounce/blob/master/index.js
function debounce(fn, delay) {
let timeoutID = null;
return (...args) => {
clearTimeout(timeoutID);
timeoutID = setTimeout(() => {
fn(...args)
}, delay);
}
}
@wegry
wegry / result.out.js
Last active July 10, 2019 13:24
Typescript Result Types
"use strict";
// Typescript 3.5.2
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = __importDefault(require("lodash"));
function Err(value) {
return {
kind: 'error',