Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@joshburgess
joshburgess / ramda-sanctuary.md
Created March 6, 2018 22:06 — forked from Avaq/ramda-sanctuary.md
Comprehensive Ramda to Sanctuary list
Ramda Sanctuary
add(a, b) add(b, a)
addIndex(f) ``
adjust(f, i, xs) ``
all(f, xs) ``
allPass(fs, x) allPass(fs, x)
always(x) K(x)
and(a, b) and(a, b)
any(f, x) ``
import React from 'react'
import hoistNonReactStatics from 'hoist-non-react-statics'
export default function withFlexibleRender (OriginalComponent) {
class ComponentWithFlexibleRender extends OriginalComponent {
render () {
const { children, render } = this.props
const args = {
@joshburgess
joshburgess / README.md
Created May 9, 2018 22:35 — forked from dwhitney/README.md
Quick React Native with PureScript
  1. create-react-native-app purescript-app; cd purescript-app

  2. pulp init --force

  3. pulp build

  4. src/Main.js

var React = require("react");
var RN = require("react-native");

exports.text = function(props){
@joshburgess
joshburgess / match.js
Created May 10, 2018 03:48
Ramda match functions
// a simpler version of Ramda's `cond` where you can only match a value against
// an object's static key, like how JavaScript's `switch` statement works with `case`
// if you need to dynamically match against expression evaluations, use `cond` instead
const matchObj = casesObj => fallback => val => casesObj[val] || fallback
// or with a syntax more like Ramda's `cond`, taking in an array of pairs instead
const matchPairs = compose(matchObj, fromPairs)
@joshburgess
joshburgess / expMatch.js
Last active May 10, 2018 16:47
A utility to match on expressions built by dynamically building a switch statement and evaluating it with eval
// try in ramda's repl: https://goo.gl/VsRkoY
const expMatch = cases => fallback => matchVal => {
const sanitize = maybeString =>
typeof maybeString === 'string' || maybeString instanceof String
? `'${maybeString}'`
: maybeString
// dynamically build a switch statement to be eval'd
const switchStart = `switch (true) {\n`
@joshburgess
joshburgess / hkt.rs
Created May 18, 2018 06:37 — forked from 14427/hkt.rs
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
@joshburgess
joshburgess / DictTrick.hs
Created May 25, 2018 15:20 — forked from jship/DictTrick.hs
Small example showing the Dict trick to discover available instances from a GADT
#!/usr/bin/env stack
-- stack --resolver lts-10.8 --install-ghc exec ghci
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
-- A key type for pretend use in looking up a doggo in a database.
newtype Key a = Key { unKey :: String }
const classNamesBy = mapper => R.compose(
R.trim,
R.join(' '),
R.chain(mapper),
R.toPairs,
)
const classNames = R.curry((base, obj) => {
const standard = ([k, v]) => [v ? k : '']
const reversed = R.compose(standard, R.reverse)
@joshburgess
joshburgess / Ref.js
Created June 24, 2018 08:50 — forked from maddie927/Ref.js
react-basic Ref component
"use strict";
var React = require("react");
var ReactDOM = require("react-dom");
exports.makeRef = function(toMaybe) {
var Ref = function(props) {
this.DOMNode = null;
return this;
};
@joshburgess
joshburgess / foo.ts
Created June 27, 2018 02:23 — forked from OliverJAsh/foo.ts
Type safe routing with `fp-ts-routing` and `unionize`
import {
end,
int,
lit,
Match,
parse,
Route as RouteBase,
zero
} from "fp-ts-routing";
import { pipe } from "fp-ts/lib/function";