Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@Techcable
Techcable / heapsort.janet
Last active April 9, 2022 00:48
A port of my heap sort code from Python -> Janet
# Ported from this Python code: https://gist.github.com/Techcable/c411b3a550e252b1fd681e1fc1734174
#
# Based on R. Sedgewick's Algorithms, Chapter 2.4
(defn swap [l a b]
(let [aval (get l a) bval (get l b)]
(put l a bval)
(put l b aval)))
(defn heap-sort [l]
@Techcable
Techcable / heapsort.py
Last active April 8, 2022 22:47
A simplistic implementation of heapsort (in Python)
import operator
def swap(l: list, i: int, j: int):
assert i < len(l), i
assert j < len(l), j
l[i], l[j] = l[j], l[i]
def heap_sort(l: list) -> list:
@Techcable
Techcable / number_names.py
Last active March 15, 2022 03:51
Simple script for naming the integers <10,000 (used in my math/proofs class)
from math import floor, log10
import sys
WORDS = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
@Techcable
Techcable / recursive_sizeof.py
Created November 15, 2021 03:40
A version of sys.sizeof that functions recursively
from __future__ import print_function
from sys import getsizeof, stderr
from itertools import chain
from collections import deque
try:
from reprlib import repr
except ImportError:
pass
def total_size(o, handlers={}, verbose=False):
@Techcable
Techcable / Permutations.java
Created November 12, 2021 00:14
Java Integer Permutations (Used for HW #6 in CSC 245) - Very fast, in-place, no duplicates allowed
/**
* This class has one method: nextPermutation
*
* It finds the next permutation of the specified integer values
*
* Credit to Rosen's discrete structures book for the algorithm.
*/
public class Permutations {
/**
* Returns the next permutation of the specified values, in lexographic order
@Techcable
Techcable / bench_bytecode_compilation.cc
Last active June 14, 2021 09:04
Benchmarks bytecode compilaiton in various langauges
/*
* See github gist:
* https://gist.github.com/Techcable/47ddd3750adc5b9df824b6b3986eb251
*/
#include <string>
#include <cstdlib>
#include <optional>
#include <vector>
#include <fstream>
#include <sstream>
@Techcable
Techcable / keys-pub.txt
Created March 5, 2021 19:08
Signature for keys.pub
BEGIN MESSAGE.
EAfLPl3xKameGpN Vmhi4ObNWYpkd5N QfiQsMMYG0KW1UK sEERbXJe8AM4BcQ
ksZbUKC4rZnfVZ8 ikEAjYL02ReTCKq 6Xr2MZHgg6epqBl xRzC4RYtZr5n3NM
baM9xX9kTCbyq4k mBiAsRm2o1koNn0 VDNWKYed09jJ5Rh zbK8pAVSYFOvR0b
7S5hXYJGXUVU0md riqrfDQFntLzGGG F0quO29HFxl.
END MESSAGE.
@Techcable
Techcable / ignore.txt
Created January 14, 2021 23:15
Utilities to print files that would be good to backup (in /etc /var /opt) - Automatically ignores files owned by pacman. Remember to check modification with `pacman -Qii | grep -P '^(?:UN)?MODIFIED'` and `paccheck --sha256sum`
/etc/.pwd.lock
/etc/.updated
/etc/adjtime
/etc/ca-certificates/
/etc/dhcpcd.duid
/etc/group
/etc/group.pacnew
/etc/gshadow-
/etc/ld.so.cache
/etc/locale.gen.pacnew
@Techcable
Techcable / README.md
Last active January 6, 2024 21:27
Backup a set of SMS backup files from Android's "SMS Backup and Restore"

SMS Backups

Sms Backups (for the paranoid) using Andorid's "SMS Backup and Restore"

  1. Install "SMS Backup and Restore" to backup periodically
    • Configure backups to a cloud provider like "Google Drive"
    • Ideally backup phone clals as well
  2. Wait until the Cloud Provider runs low on storage
    • This should happen relatively quickly, since my SMS files take 300+ MB each (they include photo/videos)
  3. Download the backup folder
@Techcable
Techcable / opt.rs
Created July 11, 2020 16:00
Safety of nbody power optimization (f**-1.5) == 1/(sqrt(f) * f) [Always within 1 ULP?]
extern crate rand; // 0.7.3
use rand::prelude::*;
use rand::distributions::Uniform;
fn clear(f: f64) -> f64 {
f.powf(-1.5)
}
fn fast(f: f64) -> f64 {