Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@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 {
@Techcable
Techcable / ulps.rs
Created July 11, 2020 15:30
Floating Point Raw ULP comparison
//! Taken from Stack overflow: ttps://stackoverflow.com/a/17871376/5713037
fn diff_ulps(a: f64, b: f64) -> u64 {
(raw_ulps(a) as i64).wrapping_sub(raw_ulps(b) as i64).abs() as u64
}
fn raw_ulps(f: f64) -> u64 {
assert!(!f.is_nan());
let b: u64 = f.to_bits();
const TOP: u64 = 0x8000_0000_0000_0000;
@Techcable
Techcable / eulers_method.py
Created September 13, 2018 17:42
Euler's Method for solving Differential Equations
def parse_location(s: str):
if s.startswith("(") and s.endswith(")"):
parts = s[1:-1].split(',')
if len(parts) == 2:
try:
return tuple(map(int, parts))
except ValueError:
pass
raise ValueError(f"Invalid location: {s!r}")
@Techcable
Techcable / strsim.js
Last active May 7, 2019 22:58
Javascript Damerau Levenshtein Similarity metrics
function damerau_levenshtein(first, second) {
"use strict";
// TODO: Support non-BMP characters (like that's ever going to happen)
if (first == second) return 0;
var firstLen = first.length;
var secondLen = second.length;
if (firstLen == 0) return secondLen;
if (secondLen == 0) return firstLen;
note: trace_macro
--> src/tests.rs:251:5
|
251 | error!(log, "at {name:?} {sym:#}", name = ip, sym = demangled);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expanding `error! { log , "at {name:?} {sym:#}" , name = ip , sym = demangled }`
= note: to `log ! (
log , $crate :: Level :: Error , "" , "at {name:?} {sym:#}" , name = ip , sym
= demangled )`