Skip to content

Instantly share code, notes, and snippets.

View theraccoonbear's full-sized avatar
💭
oh bother

Don Smith theraccoonbear

💭
oh bother
View GitHub Profile
@theraccoonbear
theraccoonbear / Cacheable.java
Last active June 17, 2022 18:15
Cache Key Interface
// Things used as keys must implement this
public interface Cacheable {
public abstract String cacheKey();
}
// This is the cache wrapper (it would get an injected CacheManager to use internally)
public abstract class GenericCacheableCache<K extends Cacheable, V> {
private CacheManager cache;
public Optional<V> get(K key) {
const scalarTypes = ['string', 'number', 'boolean', 'date'];
const isScalar = thing => scalarTypes.indexOf(typeof thing) >= 0;
const detSerConvert = (inp) => {
if (inp instanceof Date) { return inp.toISOString(); }
if (isScalar(inp)) { return inp; }
if (Array.isArray(inp)) { return inp.map(detSerConvert); }

Convert the giant blob of invalid JSON Robo3T gives you into something consumable.

  • First:
    • Find... (?:ISODate|ObjectId)\(("[^"]+")\) (BSON types)
    • And replace with... $1 (the non-ignored capture group)
  • Second:
    • Find... (/\*\s+\d+\s+\*/) (index comments)
    • And replace with... , (comma to separate array elements)
  • Finally
  • Remove the stray comma where /* 1 */ used to be
(() => {
const DLs = [];
$('a[href*="download/"]').each((i, a) => {
const $a = $(a);
DLs.push('bcdl \'' + $a.attr('href') + '\'');
});
console.log(DLs.join("\n"));
})();
@theraccoonbear
theraccoonbear / findbig.sh
Created September 12, 2020 02:00
Find a few big ol' directories for cleaning and moving media around
du -hs * | sort -h | tail -n 25 | sort -h -r
dsmith@pop-os ~/code/other/sandbox/sieve (master) $ yarn start --check 10
yarn run v1.21.1
$ node index.js --check 10
Primes between 1 and 10 WITH sieve:
3 primes!
0.00 second(s) elapsed
-----------------------------------------------------------------
Counting primes between 1 and 10 WITHOUT sieve:
3 primes!
0.00 second(s) elapsed
const argv = require('yargs').argv;
let sieve = {};
let timeAtStart;
// like a boss
Object.prototype.commafy = function () {
return this.toString().replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,");
});
@theraccoonbear
theraccoonbear / slideshow.sh
Created September 15, 2019 15:27
Generate a slideshow of images for cover art trivia
#!/bin/bash
# Generate a slideshow of images for cover art trivia.
# Files should be named like {SORT-NUMBER} blah blah blah.jpg
for f in *.jpg; do
num=$(echo $f | sed -En "s/^([0-9]+).+?/\1/p")
formatNum="$((10#$num + 1 - 1))"
output=final_$num.jpg
echo "Processing $f file...";
@theraccoonbear
theraccoonbear / gist:e8a2c127b306745bf7e4
Created October 21, 2015 14:45
Composer Installation on HostMonster
/usr/bin/php56s -d register_argc_argv=1 "./composer.phar" install
@theraccoonbear
theraccoonbear / make_db_ssh_tunnel.sh
Last active August 29, 2015 14:26 — forked from camsaul/make_db_ssh_tunnel.sh
Make a SSH Tunnel to a Postgres DB hosted in Vagrant VM
#! /bin/bash
ssh -L 5555:localhost:5432 vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key -fNg # local port 5555 <-> Vagrant port 5432