Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gray DanielFGray

View GitHub Profile
View alarm.sh
#!/usr/bin/env bash
declare loud=0
declare urgent
declare old_volume
declare old_volume
cleanup() {
set_volume "$old_volume"
View useFetch.js
import { useState, useEffect } from 'react'
export default function useJson(props) {
const [state, _setState] = useState({
data: props.initData,
error: null,
loading: true,
})
const setState = patch => s => _setState({ ...s, ...patch })
@DanielFGray
DanielFGray / hash.js
Created Apr 3, 2019
promise wrapper around crypto.createHash
View hash.js
const crypto = require('crypto')
module.exports = function hash({ method }, input) {
return new Promise((res, rej) => {
const h = crypto.createHash(method)
h.on('readable', () => {
const data = h.read()
if (data) {
res(data.toString('hex'))
} else rej()
View index.js
const tput = require('./tput')()
tput.write('smcup')
tput.write('cup 0 0')
process.stdout.write('foo')
process.on('exit', () => {
tput.write('rmcup')
process.exit()
})
View .bashrc
multiple () {
local l x y p c
c=0 p=0 l=()
while :; do
case $1 in
-p)
if [[ $2 = -* ]]; then
echo '-p requires an argument'
return
fi
@DanielFGray
DanielFGray / gulpfile.js
Last active Sep 9, 2018
webpack in gulp
View gulpfile.js
/* eslint-disable no-console,import/no-dynamic-require,global-require */
const path = require('path')
const gulp = require('gulp')
const R = require('ramda')
const watch = require('gulp-watch')
const webpack = require('webpack')
const { terminal } = require('terminal-kit')
const { ProgressPlugin } = webpack
const webpackPath = './webpack.config.js'
@DanielFGray
DanielFGray / ternaryindent.md
Last active Apr 10, 2018
formatting of different branching styles
View ternaryindent.md

nested ternary conditional

const type = a => (
  a === null ? 'null'
  : a === undefined ? 'undefined'
  : Object.prototype.toString.call(a).slice(8, -1))

if/else

View Main.jsx
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),
))
View 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')
@DanielFGray
DanielFGray / category-intro.md
Last active Mar 22, 2018
an attempt at explaining category theory
View category-intro.md
layout title category tags date
post
computers
programming
javascript
fp
2018/1/4

Introduction

You can’t perform that action at this time.