Skip to content

Instantly share code, notes, and snippets.

Jim Kang jimkang

Block or report user

Report or block jimkang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jimkang
jimkang / sort-by-type.mp4
Created Nov 15, 2018
Move files (unsafely) with a file extension that matches the argument into a directory named for that extension.
View sort-by-type.mp4
#!/bin/bash
for file in ./recup_dir*/*.$1
do
mv ${file} $1
done
@jimkang
jimkang / sort-mp4.sh
Created Nov 14, 2018
Moving every mp4 file in subdirectories into a directory named 'mp4'
View sort-mp4.sh
#!/bin/bash
for file in ./recup_dir*/*.mp4
do
mv ${file} mp4
done
@jimkang
jimkang / working-tar-exclude.sh
Created Nov 1, 2018
This is tar exclude command syntax that actually works on OS X. Run from the directory enclosing the project folder.
View working-tar-exclude.sh
tar -zcvf project.tgz --exclude "./project/node_modules" ./project
@jimkang
jimkang / require-all-in-dir.js
Created Sep 18, 2018
Requiring all files in a directory
View require-all-in-dir.js
/* global __dirname */
var fs = require('fs');
var files = fs.readdirSync(__dirname).filter(isAConfigFile);
var configs = files.map(file => require(__dirname + '/' + file));
function isAConfigFile(filename) {
return filename.endsWith('-config.js');
}
@jimkang
jimkang / da-mystery-of-unit-type.scala
Created Jul 6, 2018
Fairly similar lines of code seem to compile differently here.
View da-mystery-of-unit-type.scala
def render(s: String, mode: NameMode): String =
if (s.matches("\\d+")) {
return render(SafeLong(s.toInt), mode);
// The line below seems to compile.
} else if (s.charAt(0) == '-') {
"negative " + render(s.substring(1).toInt, mode)
} else if (s.length < 2) {
val c = s.charAt(0)
if (charIsAlpha(c)) {
onesForChar(c)
@jimkang
jimkang / stddev.js
Created Jun 12, 2018
Simple stddev example
View stddev.js
var curry = require('lodash.curry');
var counts = [9, 4, 4, 5, 49];
var avgCount = mean(counts);
var deviations = counts.map(curry(bMinusA)(avgCount));
var squaredDevs = deviations.map(square);
var variance = mean(squaredDevs);
var populationStdDev = Math.sqrt(variance);
console.log('avgCount', avgCount);
console.log('populationStdDev', populationStdDev);
@jimkang
jimkang / tool.js
Created May 1, 2018
Typical top of a tool script
View tool.js
/* global __dirname, process */
var fs = require('fs');
var ndjson = require('ndjson');
var through2 = require('through2');
var callNextTick = require('call-next-tick');
if (process.argv.length < 3) {
console.log(
'Usage: node tools/toolname.js <export something.ndjson> > new_file.ndjson'
@jimkang
jimkang / tracking-colors.js
Created Mar 8, 2018
In case I ever need it: Color tracker for secret click-detection mirror canvases
View tracking-colors.js
var hash = require('string-hash');
function TrackingColors() {
var idsForColors = {};
return {
getTrackingColorForId,
getIdForTrackingColor
};
function getTrackingColorForId(id) {
@jimkang
jimkang / number-sayer.make
Created Feb 10, 2018
A thing that'll say large numbers like an octillion
View number-sayer.make
# Usage: ZEROES=9 make number-audio
# e.g. A million has six zeroes (3 * (1 + 1)).
# A billion has nine zeroes (3 * (2 + 1)).
# A trillion has 12 zeroes (3 * (3 + 1)).
number-audio:
rm -f output.wav
rm -f test-list.txt
echo "file static/one.wav\n" > test-list.txt
for i in {1..$(ZEROES)}; do printf "file 'static/zero.wav'\n" >> test-list.txt; done
ffmpeg -f concat -safe 0 \
@jimkang
jimkang / size-svg-to-window.js
Created Jan 8, 2018
Set svg size to window size
View size-svg-to-window.js
var width = +window.innerWidth;
var height = +window.innerHeight;
svg.attr('width', width);
svg.attr('height', height);
You can’t perform that action at this time.