Skip to content

Instantly share code, notes, and snippets.

@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 / replace-with-sed.sh
Last active August 18, 2022 05:29
Example of replacing placeholders in multiple files with sed
#!/bin/bash
# Assuming $title and $name are read from input.
# ...
# Escaping space characters is only necessary within the shell script.
# If you're running the find...sed command directly in the shell, you don't need to escape spaces.
cleanedtitle="${title// /\\ }"
# Replace the placeholders with the title (with escape characters inserted).
@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
@jimkang
jimkang / sort-by-type.mp4
Created November 15, 2018 00:07
Move files (unsafely) with a file extension that matches the argument into a directory named for that extension.
#!/bin/bash
for file in ./recup_dir*/*.$1
do
mv ${file} $1
done
@jimkang
jimkang / sort-mp4.sh
Created November 14, 2018 23:51
Moving every mp4 file in subdirectories into a directory named 'mp4'
#!/bin/bash
for file in ./recup_dir*/*.mp4
do
mv ${file} mp4
done
@jimkang
jimkang / working-tar-exclude.sh
Created November 1, 2018 16:54
This is tar exclude command syntax that actually works on OS X. Run from the directory enclosing the project folder.
tar -zcvf project.tgz --exclude "./project/node_modules" ./project