Skip to content

Instantly share code, notes, and snippets.

View anematode's full-sized avatar
🗿

Timothy Herchen anematode

🗿
View GitHub Profile
p.match(/.{1,16000}/gs).join("\"+\"");
static float longToFloat(long input) {
double f = (double)input;
long rounded = (long)f;
double oneUlpDown = f * 1.1113332476497816e-16 - f + f;
if (f - 0.5 * oneUlpDown == f && rounded != input) {
f += (rounded > input != (input < 0)) ? -oneUlpDown : oneUlpDown;
}
return (float)f;
}
@anematode
anematode / shuffle_nibbles.c
Created October 22, 2022 19:50
Shuffle nibbes in 64-bit-element vectors in x86, with an AVX-512 implementation and scalar/fallback implementation
#include <immintrin.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
// Convention: (a & (0xf << (4 * i))) >> (4 * i) is the ith nibble of a
// (i.e., lowest-significant is 0)
uint64_t shuffle_nibbles(uint64_t data, uint64_t indices) {
#if defined(__AVX512VBMI__) && defined(__AVX512VL__)
// If your data is already in vectors, then this method also works in parallel
@anematode
anematode / insn_count.py
Last active October 1, 2022 11:04
Analyze binary instruction count
#!/usr/bin/python3
# This code is hereby released under CC0. Use this code for whatever the fuck you want to, without attribution.
# Count instructions of each type and print them, sorted by count. Requires objdump. Insn counts are
# per executable section type. Buggy and silly, but entertaining.
import collections
import functools
import os.path
@anematode
anematode / gen_regex.py
Created May 16, 2022 15:46
Outputs a regex which can detect multiples of 9
#!/usr/bin/python3
keys = {
"0": "[09]",
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
@anematode
anematode / fp_round.js
Created March 25, 2022 04:20
Fast way of getting consecutive floating-point numbers
/**
Copyright 2022 Timothy Herchen
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 restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
@anematode
anematode / youtube_channel_id
Created November 10, 2021 06:58
Get the underlying ID of a youtube channel; run this command on the channel's home page
let id, href;
if ((id = Array.from(document.querySelectorAll("link[rel=canonical]"))) && (href = id[0].href)) {
console.log("URL:", href);
console.log("id:", href.slice(href.lastIndexOf('/') + 1));
} else {
throw new Error("Couldn't find channel id");
}
@anematode
anematode / analyze_hangouts.js
Last active July 4, 2021 22:25
Analyze hangouts chats from google takeout
const fs = require("fs")
// Folder containing Hangouts.json
const dataFolder = "../timothy_herchen_gmail_hangouts/Hangouts"
// Folder to write chat texts to
const writeFolder = "./chats"
console.log("Reading in Hangouts data")
2-Butanol
Acetal
Acetaldehyde
Acetyl Chloride
Acetyl Nitrate
Acrolein
Acrylic Acid
Acrylonitrile
Alcohols (Allylic, Benzylic)
Alidyy-Substituted Cycloaliphatics
@anematode
anematode / isbn_normalize.py
Created March 1, 2021 17:24
Convert ISBNs in wikitext or list form into hyphenated ISBN 13s, and find any invalid ISBNs.
# Convert ISBNs in wikitext or list form into hyphenated ISBN 13s, and alert of any invalid ISBNs.
import re
import sys
import argparse
import stdnum.isbn
import pyperclip
isbn_as_argument_regex = re.compile(r"[iI]sbn\s*=\s*([0-9\- ]+)")
simple_isbn = re.compile(r"([0-9]\- ]{10,})")