Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@Techcable
Techcable / euler51.py
Created July 24, 2017 20:10
Euler #51 Prime Digit Replacements (Spoiler)
from math import log10, ceil, sqrt
import numpy as np
from itertools import combinations
import operator
import array
def basicNumpySieve(bound):
isPrime = np.ones((bound), dtype=np.bool)
for i in range(2, ceil(sqrt(bound)) + 1):
if isPrime[i]:
@Techcable
Techcable / euler52.rs
Created August 4, 2017 17:15
Euler #52 Permuted multiples Rust
use std::cmp::max;
fn digitsOf(mut value: usize, buffer: &mut Vec<u8>) {
buffer.clear();
if value > 0 {
while value > 0 {
buffer.push((value % 10) as u8);
value /= 10;
}
buffer.reverse();
@Techcable
Techcable / euler53.py
Created August 4, 2017 17:34
Euler #53 Combinatoric selections
from math import factorial
def numCombinations(n, r):
return factorial(n) // (factorial(r) * factorial(n - r))
def numCombinationsBiggerThan(n, target):
amount = 0
for r in range(1, n + 1):
if numCombinations(n, r) > target:
amount += 1
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 )`
@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;
@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 / 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 / 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 / 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 / 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