Skip to content

Instantly share code, notes, and snippets.

View benlesh's full-sized avatar
🐶
☕ 🔥 🔥 this is fine

Ben Lesh benlesh

🐶
☕ 🔥 🔥 this is fine
View GitHub Profile
@benlesh
benlesh / convert-wav-to-mp3.bat
Created June 20, 2023 14:15
Convert all WAV files in a directory to MP3 files.
REM NOTE that this does NOT uninstall ffmpeg when done
@echo off
setlocal enabledelayedexpansion
echo Current directory: %cd%
REM Set the download URL for FFmpeg
set "ffmpeg_url=https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
@benlesh
benlesh / README.md
Last active May 8, 2019 18:49
Valid JS Identifiers JSON

All Valid JS Identifiers As JSON

Created by fiddling with code written by Mathias Bynens for https://mothereff.in/js-variables

MIT License from his project should be honored.

const source$ = Observable.interval(1000).take(3); // 0, 1, 2
// waits 3 seconds, then logs "2".
// because the observable takes 3 seconds to complete, and
// the interval emits incremented numbers starting at 0
async function test() {
console.log(await source$.toPromise());
}
const click$ = Observable.fromEvent(button, 'clicks');
/**
* Waits for 10 clicks of the button
* then posts a timestamp of the tenth click to an endpoint
* using fetch
*/
async function doWork() {
await click$.take(10)
.forEach((_, i) => console.log(`click ${i + 1}`));
return await fetch(
Observable.defer(async function() {
const a = await promiseDelay(1000).then(() => 1);
const b = a + await promiseDelay(1000).then(() => 2);
return a + b + await promiseDelay(1000).then(() => 3);
})
.subscribe(x => console.log(x)) // logs 7
function getErroringPromise() {
console.log('getErroringPromise called');
return Promise.reject(new Error('sad'));
}
Observable.defer(getErroringPromise)
.retry(3)
.subscribe(x => console.log);
// logs "getErroringPromise called" 4 times (once + 3 retries), then errors
// An observable that emits 10 multiples of 100 every 1 second
const source$ = Observable.interval(1000)
.take(10)
.map(x => x * 100);
/**
* returns a promise that waits `ms` milliseconds and emits "done"
*/
function promiseDelay(ms) {
return new Promise(resolve => {
setTimeout(() => resolve('done'), ms);
// An observable that emits 10 multiples of 100 every 1 second
const source$ = Observable.interval(1000)
.take(10)
.map(x => x * 100);
/**
* returns a promise that waits `ms` milliseconds and emits "done"
*/
function promiseDelay(ms) {
return new Promise(resolve => {
setTimeout(() => resolve('done'), ms);
@benlesh
benlesh / path-evaluation.js
Last active November 3, 2016 20:25
Primitive path evaluation implementation with refs
console.clear();
const path = ["list", 0];
const path0 = ["list", 20, 'name']; // ref ref
const path1 = ["list", [0, 1], "name"];
const path2 = ["list", [0, 1, { from: 3, length: 2 }], "name"];
const path3 = ["list", [0, 1, { from: 3, length: 2 }, { from: 7, to: 9 }], "name"];
const path4 = ["list", { to: 5 }, ["name", "rating"]];
const jsonGraph = {
@benlesh
benlesh / esnextbin.md
Created May 19, 2016 18:44
esnextbin sketch