Skip to content

Instantly share code, notes, and snippets.

@josgraha
josgraha / zipper.js
Created September 9, 2018 19:58
Zipper in JS
const lastIndex = list => (
list && list.length > 0 ? list.length - 1 : 0);
const isNone = val => val === null || typeof val === 'undefined';
const asList = list => (isNone(list) ? [] : list);
const isEmptyList = list => list && list.length <= 0;
const isLastIndex = (lst, index) => (asList(lst).length - 1) === index;
@josgraha
josgraha / graphs.js
Created September 8, 2018 18:35
graphs and nodes
const bt = (value, left, right) => {
return {
value: value,
left: left,
right: right
};
}
const leaf = value => {
return bt(value, null, null);
@josgraha
josgraha / fancy-tabs-demo.html
Created July 3, 2018 14:29 — forked from ebidel/fancy-tabs-demo.html
Fancy tabs web component - shadow dom v1, custom elements v1, full a11y
<script>
function execPolyfill() {
(function(){
// CustomElementsV1.min.js v1 polyfill from https://github.com/webcomponents/webcomponentsjs/tree/v1/src/CustomElements/v1.
/*
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
package recfun
object Main {
def main(args: Array[String]) {
println("Pascal's Triangle")
for (row <- 0 to 10) {
for (col <- 0 to row)
print(pascal(col, row) + " ")
println()
}
@josgraha
josgraha / thunk_example.js
Created November 13, 2017 21:27
Redux Thunk Example
// If you use Redux Thunk...
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
const store = createStore(reducer, applyMiddleware(thunk))
// You can define asynchronous action creators that return functions.
// We call such action creators "thunks":
export function getUser(id) {
// Redux Thunk will inject dispatch here:
@josgraha
josgraha / reason_examples.md
Created November 12, 2017 22:01
Reason ML Presentation

Pattern Matching

Example

type basicColor =
	| Red
	| Green
	| Blue;

let basicColorToInt = color => {
@josgraha
josgraha / fun-with-compose.js
Last active November 17, 2017 17:23 — forked from anonymous/fun-with-compose.js
fun-with-compose created by josgraha - https://repl.it/NznS/2
const R = require('ramda');
const { append, compose, filter, flatten, isArray, join, map, prepend } = R
const { log } = console
// html markup functions
const UL = 'ul'
const LI = 'li'
const tagOpen = tag => `<${tag}>`
@josgraha
josgraha / FunctionComponent.jsx
Last active October 24, 2017 09:49
Function Component Example
function IsThisUndefined(props) {
return <div>{props.title} {this === undefined ? 'Yes' : 'No'}!</div>
}
ReactDOM.render(
<IsThisUndefined title='Is this undefined?' />,
document.getElementById('app')
)
@josgraha
josgraha / Counter.jsx
Created October 24, 2017 02:17
React Class Example
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {count: 0};
this.incrementCounter = this.updateCounter.bind(this, 1);
this.decrementCounter = this.updateCounter.bind(this, -1);
}
render() {
return (
@josgraha
josgraha / typescript-pattern-matching.ts
Created July 11, 2017 15:44 — forked from rob3c/typescript-pattern-matching.ts
TypeScript pattern matching proof-of-concept
// preserved from my comment in this issue: https://github.com/Microsoft/TypeScript/issues/165#issuecomment-259598080
interface Type<T> { new(...args): T }
interface CaseResult<R> {
success: boolean;
result: R;
}
interface CaseFn<R> { (value: any): CaseResult<R> }