Skip to content

Instantly share code, notes, and snippets.

View jonahwilliams's full-sized avatar

Jonah Williams jonahwilliams

View GitHub Profile
@jonahwilliams
jonahwilliams / index.js
Last active December 11, 2015 18:24
Option<?A> in JavaScript
type Maybe = Some | None;
class Option<A> {
value: A;
constructor(x: ?A) {
if (x == null) {
return new None();
} else {
return new Some(x);
}
@jonahwilliams
jonahwilliams / index.html
Created January 22, 2016 22:30
Flux pattern w/ Webworker
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Webworker Redux</title>
</head>
<body>
<div id="app"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-dom.js"></script>
@jonahwilliams
jonahwilliams / index.html
Created January 28, 2016 23:53
D3 Chart with React / d3-shape
<!doctype html>
<html>
<head>
<title> D3 Shape Test</title>
<style type="text/css">
path {
stroke: black;
fill: none;
stroke-width: 0.5px;
shape-rendering: optimizeQuality;
@jonahwilliams
jonahwilliams / index.js
Last active August 5, 2016 03:02
Redux with Rxjs
"use strict";
const Rx = require('rx');
const fetch = require('isomorphic-fetch'); /* use the fetch api on client and server */
/**
* Given a subreddit, pull down post ids. that is, changing the subreddit by calling terms$.onNext(SUBREDDITNAME)
* automatically calls the reddit api and populates the store.
* To try it out, npm install rx and isomorphic-fetch, then
* var S = require('./index.js');
* S.store$.subscribe(x => console.log(x)); // listen to every state change
function mergesort(xs) {
if (xs.length < 2) {
return xs
}
const n = xs.length / 2 | 0;
return merge(mergesort(xs.slice(0, n)), mergesort(xs.slice(n)));
}
function merge(xs, ys) {
@jonahwilliams
jonahwilliams / index.js
Created May 4, 2016 21:56
the board problem
'use strict';
const example = [
['a', 'c', 'l', 'b'],
['r', 'e', 'b', 'u'],
['i', 'n', 'g', 's'],
['l', 'm', 'n', 'o']
];
console.log(contains(example, 'caring'));
@jonahwilliams
jonahwilliams / index.hs
Created May 4, 2016 23:09
board search in Haskell
type Board = [[Char]]
data Link = Link { pos :: (Int, Int)
, vis :: [(Int, Int)]
, mat :: [Char] } deriving Show
neighbors :: Board -> Int -> Int -> [(Int, Int)]
neighbors b i j = [(x, y) | x <- [(i - 1) .. (i + 1)],
y <- [(j - 1) .. (j + 1)],
@jonahwilliams
jonahwilliams / index.hs
Last active May 5, 2016 17:56
Better board search
{-
Given a matrix of characters like
[['a', 'c', 'l', 'b'],
['r', 'e', 'b', 'u'],
['l', 'n', 'c', 's'],
['c', 'm', 'n', 'o']]
determine if a given string like "care" can
be found by navigating through the matrix without
repeating characters - ie snake rules
{-
Given a matrix of characters like
[['a', 'c', 'l', 'b'],
['r', 'e', 'b', 'u'],
['l', 'n', 'c', 's'],
['c', 'm', 'n', 'o']]
determine if a given string like "care" can
be found by navigating through the matrix without
repeating characters - ie snake rules
use std::collections::VecDeque;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::env::args;
use std::time::Instant;
const MAX_ITER: usize = 1000000000000;
const DIRECTIONS: [Move; 4] = [Move::Down, Move::Up, Move::Left, Move::Right];
fn main() {