Skip to content

Instantly share code, notes, and snippets.

View Lokua's full-sized avatar
🐐
 

Joshua Kleckner Lokua

🐐
 
View GitHub Profile
const originalError = console.error
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation((...args) => {
if (
typeof args[0] === 'string' &&
args[0].includes('inside a test was not wrapped in act')
) {
return
}

convert series of images to gif

fmpeg -f image2 -framerate 2 -i %2d.jpg out.gif

convert series of images to mp4 (suitable for instagram, quicktime)

ffmpeg -f image2 -framerate 2 -i %2d.jpg -pix_fmt yuv420p -crf 17 -vcodec libx264 out.mp4
@Lokua
Lokua / mockLocation.js
Created April 26, 2021 19:05
Mock location in jsdom tests
export const mockLocation = value =>
Object.defineProperties(window, {
location: {
value,
writable: true,
},
})
export const mockPathname = pathname =>
mockLocation({
import { dirname } from 'path'
import { fileURLToPath } from 'url'
export const getDirname = (importMetaUrl) =>
dirname(fileURLToPath(importMetaUrl))
// use as `getDirname(import.meta.url)`
@Lokua
Lokua / package.json
Last active February 13, 2020 01:14
Barebones testing and test-runner for node >= 13
{
"scripts": {
"test": "node ./path-to/test-runner.mjs"
}
}
@Lokua
Lokua / recursively-remove-node-modules.sh
Last active September 3, 2019 03:56
recursively removes node_modules folders
#! /bin/bash
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
@Lokua
Lokua / wav2mp3.sh
Last active July 20, 2019 17:11
converts all wav files in cwd to highest quality lame mp3
#!/bin/bash
function wav2mp3() {
for filename in *.wav; do
echo wav2mp3: converting $filename
mp3_filename="${filename[@]/%wav/mp3}"
lame --preset insane "$filename" "$mp3_filename"
echo wav2mp3: finished converting $filename
echo
done
@Lokua
Lokua / watch.js
Created January 3, 2019 10:15
starter script to restart electron on main process file change
const { spawn } = require('child_process')
const chokidar = require('chokidar')
const chalk = require('chalk')
const paths = ['./src/main.js']
let child
let wait = false
spawnElectron()
@Lokua
Lokua / rotate.js
Created September 30, 2018 03:44
rotate.js
const rotate = (array, n) => [
...array.slice(array.length - n),
...array.slice(0, array.length - n),
]
export function isEventWithin(e, element) {
const rect = element.getBoundingClientRect()
return (
rect.top <= e.clientY &&
e.clientY <= rect.top + rect.height &&
rect.left <= e.clientX &&
e.clientX <= rect.left + rect.width
)
}