Skip to content

Instantly share code, notes, and snippets.

@jimkang
jimkang / unzip-bandcamp.sh
Created February 19, 2021 03:03
When you download from Bandcamp, the zip file comes with no directory structure, so this gives it one. Explanation: https://jimkang.com/weblog/articles/bandcamp-unzip/
#!/bin/bash
for file in *.zip
do
filename="${file%.*}"
# Filenames can't contain /. So, I wonder
# what Bandcamp would do if they had AC/DC?
unzippath=$(echo "$filename" |sed -e 's/ - /\//')
mkdir -p "$unzippath"
unzip "$filename" -d "$unzippath"
@jimkang
jimkang / get-entries-in-date-range.sh
Last active April 5, 2020 19:26
Simple script for getting markdown files in a certain date range (assuming the files use a common Zettelkasten naming convention in which every file starts with YYYY-MM-DD).
#!/bin/bash
src=.
start=$1
end=$2
if [[ ! $start ]] && [[ ! $end ]]; then
printf "Usage: ./tools/get-entries-in-date-range.sh [start string] [end string]\nEnd string is optional.\n\nExample: To get filenames that come after 2020-03 (anywhere in March) but before 2020-03-29 (assuming files follow this naming convention):\n./tools/get-entries-in-date-range.sh 2020-03 2020-03-29\n";
exit 1;
fi
@jimkang
jimkang / pickle-to-json.py
Created December 2, 2019 14:53
Because I always forget
import pickle
import json
data = pickle.load(open('file.pkl', 'rb'))
out_file = open("out.json", "w")
out_file.write(json.dumps(data))
@jimkang
jimkang / static-ease-values.js
Created November 13, 2019 23:16
Get static cubic easing values. I just ran these in the Node REPL to get the numbers.
var { easeCubic } = require('d3-ease')
var { range } = require('d3-array')
range(0, 1, 0.05).map(easeCubic).map(n => n.toFixed(2)).join(';')
@jimkang
jimkang / noise.html
Last active September 4, 2019 02:11
Perlin noise SVG filter
<svg width="40" height="40" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg">
<filter id="displacementFilter">
<feTurbulence type="fractalNoise" baseFrequency="0.75"
numOctaves="2" result="turbulence" stitchTiles="stitch"/>
</filter>
<rect id="noise-square" width="40" height="40"
style="filter: url(#displacementFilter)"/>
</svg>
@jimkang
jimkang / faux-wood-grain-border.css
Created September 4, 2019 01:41
Kinda crappy but amusing faux wood grain border with `border-image`
.box {
border-image: repeating-linear-gradient(40deg, hsl(30, 50%, 15%), hsl(20, 50%, 30%), hsl(25, 40%, 20%) 8px) 60;
}
@jimkang
jimkang / floor-to-beginning-of-day.js
Created August 15, 2019 13:24
Function that floors a date to the beginning of that day (12:00 AM or 00:00).
function floorToBeginningOfDay(date) {
return new Date(date.toLocaleDateString());
}
@jimkang
jimkang / eventlistener.js
Created July 11, 2019 19:57
Basic addEventListener and removeEventListener, in case I need it later
var eventListeners = {
eventName: []
};
function addEventListener(type, listener) {
var listeners = eventListeners[type];
if (listeners) {
listeners.push(listener);
}
}
@jimkang
jimkang / extract-from-a-wikipedia-table.js
Last active June 21, 2019 01:05
Extracting content from a Wikipedia table
// Run this in the console when you have a Wikipedia page open.
// First, get the wikitable element you want and add an id of `main-table` to it.
// Then:
var rows = document.querySelectorAll('#main-table tr');
var extracted = [];
function extractFromRow(row) {
if (row.children.length > 2) {
let event = {
yearsFromNow: row.children[1].textContent.replace(/\n/g, '').replace(/\[note \d+\]/g, ''),
@jimkang
jimkang / trouble-free-rsync.sh
Created December 18, 2018 21:13
rsync flags that allow you to not have to ask for privileges
rsync -a $(HOMEDIR) $(USER)@$(SERVER):$(SERVERDIR) --exclude node_modules/ --omit-dir-times --no-perms