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 / 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 / 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)
@nichoth
nichoth / npm-tricks.md
Last active May 12, 2025 17:22
Little things you can do with `npm`

misc

npm list

npm list <module>

Show all the different copies of a module that are installed.

@nichoth
nichoth / get-last-item.js
Last active November 18, 2022 18:05
Get the last segment of a path or url
// get the last segment of a path or URL
function getLastItem (thePath) {
const pathArr = thePath.split('/')
// handle trailing slash
return (pathArr[pathArr.length - 1] || pathArr[pathArr.length - 2])
}
@nichoth
nichoth / untildify.js
Last active November 18, 2022 18:04
untildify
'use strict';
const os = require('os');
const homeDirectory = os.homedir();
module.exports = pathWithTilde => {
if (typeof pathWithTilde !== 'string') {
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
}