Skip to content

Instantly share code, notes, and snippets.

@nichoth
nichoth / toNdjson.js
Created March 11, 2015 05:34
Simple CLI for JSON transformation using Node.js streams
#!/usr/bin/env node
// Clean up JSON from openlibrary.org and output as NDJSON.
// use:
// curl 'http://openlibrary.org/subjects/love.json' | ./toNdjson.js
var JSONStream = require('JSONStream');
var map = require('through2-map');
var cherryPick = map.obj(function(obj) {
return {
@nichoth
nichoth / form-test.js
Last active February 26, 2016 21:25
Playing with yoshuawuyts/virtual-form
var loop = require('vdom-loop');
var xtend = require('xtend');
var observify = require('observify');
var oStruct = require('observ-struct');
var oArray = require('observ-array');
var observ = require('observ');
var form = require('virtual-form');
var h = loop.h;
var fields = [
@nichoth
nichoth / Makefile
Created August 13, 2016 07:04 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@nichoth
nichoth / build.sh
Created August 28, 2016 22:20
Browserify build example (taken from choo)
#!/bin/sh
usage () {
printf "Usage: build-umd <argument>\n"
}
# use zopfli for better compression if available
gzip () {
zopfli -h 2>/dev/null
if [ $? -eq 0 ]; then
// see https://github.com/karissa/karissa.github.io/blob/master/js/force.js
var d3 = require('d3')
var json = {
nodes: [
{name: 'karissa', image: '/images/github.ico', url: 'http://github.com/karissa'},
{name: '@okdistribute', image: '/images/twitter.ico', url: 'http://twitter.com/okdistribute'},
{name: 'karissamck', image: '/images/linkedin.ico', url: 'https://www.linkedin.com/in/krmckelv'},
{name: 'karissa.mckelvey', image: '/images/facebook.ico'},
{name: 'indiana', image: '/images/indiana.ico', url: 'http://indiana.edu'},
@nichoth
nichoth / .bash_profile
Last active August 18, 2018 18:07
bash_profile
alias oneline="tr -d '\n' | tr -s ' ' | sed -e '\$a\\'"
alias random="node -e \"console.log(require('crypto').randomBytes(32).toString('hex'));\""
alias lsd="ls -lF -G | grep --color=never '^d'"
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
# Trim new lines and copy to clipboard
alias c="tr -d '\n' | pbcopy"
@nichoth
nichoth / cypress-ci.js
Last active February 5, 2019 19:47
cypress + budo (browserify) in a CI server
var cypress = require('cypress')
var Budo = require('budo')
var getPort = require('getport')
getPort(9966, function (err, port) {
if (err) throw err
var budo = Budo.cli(process.argv.slice(2), {
port
}).on('connect', function () {
@nichoth
nichoth / config.yml
Created February 5, 2019 20:58
Use xvbf with tape-run on circleci
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: cypress/browsers:chrome67
@nichoth
nichoth / package.json
Created February 7, 2019 19:01
Cypress + CI using package.json scripts
{
"scripts": {
"start": "node-sass src/style/main.scss --source-map-embed > public/style.css && concurrently --kill-others \"npm run serve\" \"npm run sass-watch\"",
"serve": "env $(cat .env | xargs) VERSION=`cat package.json | json version` budo src/index.js:bundle.js --pushstate --dir=public --live -- -t babelify -g aliasify -t [ envify --NODE_ENV development ] -dv",
"cypress-ci": "start-server-and-test start http://localhost:9966 cy:run",
"cy:run": "cypress run --config baseUrl=\"http://localhost:9966\""
},
"devDependencies": {
"start-server-and-test": "^1.7.11",
}
@nichoth
nichoth / hash.js
Last active November 7, 2023 04:20
Create a sha256 hash in the browser
const webcrypto = window.crypto
import * as uint8arrays from 'uint8arrays'
// data should be Uint8Array
function getHash (data) {
let _data = data
if (typeof data === 'string') {
const te = new TextEncoder()
_data = te.encode(data)