Skip to content

Instantly share code, notes, and snippets.

View erhhung's full-sized avatar

Erhhung Yuan erhhung

  • Silicon Valley
  • 17:44 (UTC -07:00)
View GitHub Profile
Verifying my Blockstack ID is secured with the address 1Bi1NDUmdb4nXzcWW1Xm9DXxKvuAFqnJDf https://explorer.blockstack.org/address/1Bi1NDUmdb4nXzcWW1Xm9DXxKvuAFqnJDf
@erhhung
erhhung / throttled.js
Last active August 11, 2018 01:14
Throttled download progress bar example for "bubkoo/ascii-progress"
var ProgressBar = require('../index.js');
var bars = [];
var total = 1000;
var left = total;
var count = 0;
var simul = 5;
var timer = setInterval(function () {
@erhhung
erhhung / chip
Last active May 26, 2020 21:44
Perl script from eons ago for adding/deleting entries in /etc/hosts
#!/usr/bin/perl
#
# chip - add/change/delete IP entry in "/etc/hosts"
#
# Usage: add/change: chip [-q] {host_name} {ip_address}
# delete: chip {host_name} -
#
# -q: quiet - don't validate if Data::Validate::IP
# module cannot be found
#
@erhhung
erhhung / depthmap-loader.js
Created September 15, 2016 20:17
Load 16-bit PNG depth map using PngToy
class DepthmapLoader {
/**
* load 16-bit PNG depthmap from URL and return
* the normalized bitmap as a Canvas ImageData
*
* @param {string} url - URL of PNG image
* @return {Promise} -> {width,height,imageData}
*/
fetch(url) {
let pngtoy = new PngToy();
@erhhung
erhhung / myip
Last active November 13, 2020 04:04
Perl script from eons ago for getting my local IP address
#!/usr/bin/perl
#
# myip - get the IP address of this host
#
# Usage: myip [-6] [prefix]
# myip -p
#
# -6 - get IPv6 address instead of IPv4
# -p - get public IPv4 address from ISP
# prefix - match the first NIC having partial
@erhhung
erhhung / mkid
Last active May 27, 2021 00:38
Make 30-char typed object ID
#!/usr/bin/env node
//
// mkid - Make Object ID
//
// Usage: mkid [type|""]
// type: 3-char type
//
// Requires global NPM modules:
//
// uuid^8.3.2
@erhhung
erhhung / images2video.js
Created October 7, 2016 02:02
Node.js class to encode a sequence of image files into VP9 WEBM video using FFmpeg.
/*
* encode image sequence into WEBM video
*/
import {exec} from 'child-process-promise';
import format from 'string-template';
import fsAsync from 'file-async';
import shell from 'shelljs';
import path from 'path';
import os from 'os';
@erhhung
erhhung / emptyb
Last active January 29, 2022 01:20
Empty an entire S3 bucket, including object versions
#!/usr/bin/env bash
#
# empty entire S3 bucket
# usage: emptyb <bucket>
#
# author: Erhhung Yuan <erhhung@alum.mit.edu>
bucket=$1
if [ -z "$bucket" ]; then
@erhhung
erhhung / bsize
Last active January 29, 2022 04:41
Get the size and object count of an S3 bucket
#!/usr/bin/env bash
#
# show S3 bucket size/count
# usage: bsize <bucket>
#
# author: Erhhung Yuan <erhhung@alum.mit.edu>
bucket=$1
if [ -z "$bucket" ]; then
@erhhung
erhhung / postman_modules.md
Created April 4, 2022 18:12
Load external modules in Postman

This document describes one way to load external JavaScript modules into Postman pre-request or test scripts to augment the functionality of your own scripts.

In the collection pre-request script, export common utility functions (feel free to add additional functions for your own use case as this is a common technique for sharing code among individual requests):

// get latest version
_ = require('lodash');

// export common utility functions
pm.globals.set('util', String(() => ({