Skip to content

Instantly share code, notes, and snippets.

View JunkMeal's full-sized avatar
💭
Checkout harelang.org!

JunkMeal

💭
Checkout harelang.org!
View GitHub Profile
static char SEGMENT_BITS = 0x7F; // 1111111
static char CONTINUE_BIT = 0x80; // 1000000
static char SIGN_BIT = 0x40; // 0100000
void sleb128(int32_t x) {
unsigned char buf;
int negative = (x < 0);
while(1) {
buf = x & SEGMENT_BITS; // get the 7 (LSB?)
x >>= 7;
async function anki(action, params) {
return Object.values(await (await fetch("http://127.0.0.1:8765", {
method: "POST",
body: JSON.stringify({
action,
version: 6,
params
})
})).json())
}
@JunkMeal
JunkMeal / forvo.mjs
Created January 30, 2024 15:17
Get audio from Forvo
function selectin(str, startstr, endstr) {
const starti = str.indexOf(startstr) + startstr.length
return str.substring(starti, str.indexOf(endstr, starti))
}
function selectinall(str, startstr, endstr) {
let result = []
let starti = 0
while (starti < str.length) {
@JunkMeal
JunkMeal / selectin.js
Last active January 30, 2024 15:23
A great function for any kind of text extraction. I mainly use it for HTML. I write it a LOT so here it is!
function selectin(str, startstr, endstr) {
const starti = str.indexOf(startstr) + startstr.length
if (starti == -1) return -1
const endi = str.indexOf(endstr, starti)
if (endi == -1) return -1
return str.substring(starti, endi)
}
function selectinall(str, startstr, endstr) {
let result = []
@JunkMeal
JunkMeal / no-ifs.js
Created August 27, 2021 13:35
Do you hate ifs?
// Inline
true && console.log("hello")
// Multiple lines
true && (() => {
console.log("world");
})();