Skip to content

Instantly share code, notes, and snippets.

@jimkang
jimkang / make-link-index.js
Last active March 28, 2024 23:19
Make links to files with specific extensions
@jimkang
jimkang / download-soundcloud-playlist.js
Last active January 1, 2024 22:44
Download everything from a SoundCloud playlist
// Paste this into the console and get ready to click "Save" in response to the save dialog a bunch of times. Or better yet, disable asking where to save in your browser.
var buttons = document.querySelectorAll('.sc-button-more')
var index = 0;
function moreNext() { var more = buttons[index]; more.click(); ++index; setTimeout(dl, 500); }
function dl() { var dlButton = document.querySelector('.sc-button-download'); dlButton.click(); if (index < buttons.length) { setTimeout(moreNext, 100);}}
moreNext();
@jimkang
jimkang / mediasource-mime-codecs.md
Last active October 16, 2023 13:00
How to get the video codec the MIME types that MediaSource SourceBuffers require

When you call addSourceBuffer on a MediaSource, you need to pass in a string that is the MIME type for the codec. If this isn't correct, the video won't play. (You can also pass this to the MediaSource's isTypeSupported function, though there seems to be a gap between what it thinks it can play and what it will play.)

The string looks like this:

video/mp4; codecs="avc1.42E01E, mp4a.40.2"

The values required in that string can be obtained by running the mp4file tool from mp4v2 on a video file, like so:

 mp4file --dump movie.mp4
@jimkang
jimkang / make-indexes.js
Last active August 16, 2023 03:20
Create html indexes for images in a folder. Classic! Puts the index files in a directory named `indexes`; you may want to change that.
#!/usr/bin/env node
/* global process */
var fs = require('fs');
var imgFileExts = ['png', 'jpg'];
if (process.argv.length < 3) {
console.error(
'Usage: node make-index.js <directory with images>'
@jimkang
jimkang / obsidian.desktop
Created May 23, 2023 23:14
Obsidian AppImage desktop shortcut that goes in /usr/share/applications/obsidian.desktop.
[Desktop Entry]
Name=Obsidian
GenericName=Notes organizer
Comment=Organize notes
Exec=/home/jimkang/apps/Obsidian-1.0.3.AppImage
Terminal=false
Type=Application
Keywords=notes;organizer;
Keywords[fr]=Texte;éditeur;
Keywords[ru]=текст;текстовый редактор;
@jimkang
jimkang / roll-until-you-get-it.js
Last active February 16, 2023 02:38
Console automation for roll-a-guy
function getYourClass(targetClass) { document.getElementById('roll-button').click(); setTimeout(() => { if (document.getElementById('class').textContent !== targetClass) { window.requestAnimationFrame(() => getYourClass(targetClass)); }}, 0) }
getYourClass('Ranger')
// Edit selector to check things other than strength.
function getYourScore(minScore) { document.getElementById('roll-button').click(); setTimeout(() => { if (+document.querySelector('.row:first-child .ability-score-column').textContent < minScore) { window.requestAnimationFrame(() => getYourScore(minScore)); }}, 0) }
getYourScore(16)
@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).
//
// OGKeyPath.h
//
// Created by Jim on 3/11/10.
//
// Copyright (c) 2010 Jim Kang/Phalange Software.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@jimkang
jimkang / Contract Killer 3.md
Last active October 27, 2021 23:18 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@jimkang
jimkang / flattenTreeDepthFirst.js
Created December 17, 2013 04:10
A function to flatten a tree, depth-first. It's an implementation of this algorithm: http://cl.ly/image/1X1i0b1v1H2d Assumes the tree is built via nodes that have a property named 'children' which is an array of other nodes.
function flattenTreeDepthFirst(rootNode) {
var nodes = [rootNode];
var childArraysQueue = [];
if (rootNode.children) {
childArraysQueue.push(rootNode.children);
}
while (childArraysQueue.length > 0) {
var children = childArraysQueue[0];