Skip to content

Instantly share code, notes, and snippets.

View DanielFGray's full-sized avatar

Daniel Gray DanielFGray

View GitHub Profile

Keybase proof

I hereby claim:

  • I am danielfgray on github.
  • I am danielfgray (https://keybase.io/danielfgray) on keybase.
  • I have a public key ASCZBK5f_xYF8vv7J8Iszrg7lNorAHLcO7_UZ3WCVk9k5go

To claim this, I am signing this object:

@DanielFGray
DanielFGray / fp-curry-pa.md
Last active August 23, 2017 20:51
currying and partial application
Error in user YAML: (<unknown>): mapping values are not allowed in this context at line 2 column 30
---
layout: post
title: Functional programming: currying and partial application
category: computers
tags: [programming, javascript, fp]
date: 2017/08/23
---

An explanation of currying and partial application using JavaScript

@DanielFGray
DanielFGray / gist.js
Last active September 1, 2017 02:35
request all a user's gists
const { curry } = require('ramda')
const { Observable } = require('rxjs/Observable')
require('rxjs/add/observable/interval')
require('rxjs/add/operator/concatMap')
require('rxjs/add/operator/takeWhile')
require('rxjs/add/operator/reduce')
const request$ = curry((base, header, method, endpoint, query = {}) =>
Observable.defer(() => request(method, `${base}${endpoint}`).set(header).query(query))
.map(x => x.body))
@DanielFGray
DanielFGray / gitlog.sh
Last active September 18, 2017 19:24
fancy git-log stuff
git log --graph --oneline --decorate --all --color=always |
fzf --ansi +s --preview='git show --color=always {2}' \
--bind='pgdn:preview-page-down' \
--bind='pgup:preview-page-up' \
--bind='enter:execute:git show --color=always {2} | less -R' \
--bind='ctrl-x:execute:git checkout {2} .'
@DanielFGray
DanielFGray / index.js
Last active November 9, 2017 19:36
nodejs dzen bar script
#!/usr/bin/env node
const { spawn } = require('child_process')
const { Observable } = require('rxjs')
const {
curry,
head,
identity,
join,
map,
memoize,
@DanielFGray
DanielFGray / cmd.js
Last active March 4, 2018 22:25
spawn child processes with a promise
const { spawn } = require('child_process')
const readToEnd = stream =>
new Promise(((resolve, reject) => {
const parts = []
stream.on('error', reject)
stream.on('data', part => parts.push(part))
stream.on('end', () => resolve(Buffer.concat(parts)))
}))
const net = require('net')
const { Observable } = require('rxjs')
const R = require('ramda')
const {
T,
concat,
cond,
drop,
equals,
@DanielFGray
DanielFGray / category-intro.md
Last active March 22, 2018 19:39
an attempt at explaining category theory
layout title category tags date
post
computers
programming
javascript
fp
2018/1/4

Introduction

@DanielFGray
DanielFGray / rc.lua
Created March 30, 2018 05:13
rc.lua
-- Standard awesome library
gears = require('gears')
awful = require('awful')
require('awful.autofocus')
-- Widget and layout library
wibox = require('wibox')
-- Theme handling library
beautiful = require('beautiful')
-- Notification library
naughty = require('naughty')
const search = curry((pattern, str) => $(
pattern,
match(/!?(".*?"|\S+)/g),
reject(test(/^\W*$/)),
map(replace(/"(.*)"/, '$1')),
partition(startsWith('!')),
over(lensIndex(0), ifElse(isEmpty, T, $(drop(1), map(includesI), complement(anyPass)))),
over(lensIndex(1), $(map(includesI), allPass)),
([n, p]) => and(n, p, str),
))