Skip to content

Instantly share code, notes, and snippets.

@scooby
scooby / linkfileHandler.js
Created April 30, 2020 05:13
JXA is nuts
// Use this with https://onflapp.wordpress.com/lincastor/
// Lets you create double-clickable relative links in MacOS that sync over google drive and such.
// A "link" is just a text file with a relative path.
var app = Application.currentApplication();
app.includeStandardAdditions = true;
function readUrl(url) {
var urlObj = $.NSURL.alloc.initWithString(url);
return $.NSString.alloc.initWithContentsOfURL(urlObj).UTF8String.trim();
@scooby
scooby / missing_keys.py
Created March 11, 2020 22:39
A straightforward way to handle missing keys.
try:
val = my_dict[key]
except KeyError:
handle_missing_value(key)
else:
normal_logic(key, val)
@scooby
scooby / keybase.md
Created February 16, 2019 20:14
Keybase proof

Keybase proof

I hereby claim:

  • I am scooby on github.
  • I am ben509 (https://keybase.io/ben509) on keybase.
  • I have a public key ASCim-9mpu3uZAkD5_v29qJM1uFw6oDPEHp6vOXZdbpN4go

To claim this, I am signing this object:

@scooby
scooby / ByConcat.java
Created February 20, 2017 05:18
An algorithm to create a balanced binary tree from an iterator.
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.function.BinaryOperator;
import static java.util.Arrays.asList;
public class ByConcat {
/**
* Given a collection of objects, collapse by evenly weighted binary reduction.
#!/usr/bin/env python
# vim: shiftwidth=4 expandtab ft=python
# Written by Ben Samuel, 2010. Released into public domain.
# Use at your own risk.
import os, sys, stat
import os.path as path
def statOrNone(ent):
try:
@scooby
scooby / Make Playlist from Genius Mix.scpt
Created October 17, 2009 00:02
Purpose: to generate a playlist from a Genius mix for use with an older iPod or to burn to CD. A genius mix, incidentally, is *not* the same as a Genius playlist.
(*****************************************************
Make a Genius mix into playlist
by Ben Samuel
This script is released into the public domain.
Purpose: to generate a playlist from a Genius mix for use with an
older iPod or to burn to CD. A genius mix, incidentally, is *not*
the same as a Genius playlist.
Requires: iTunes 9. Older versions don't have Genius Mixes, and
@scooby
scooby / test_bags.pl
Created February 21, 2009 02:14
Simple algorithms for bag operations
use Data::Dumper;
use strict;
sub randlists {
sort { @$a <=> @$b } map([sort { $a <=> $b } map(int(rand() * 20), 0.. (15 + int(30 * rand())))], 0..2);
}
my(@bb) = randlists();
#$bb[1] = [-2];
my @b = map([@$_], @bb);
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 0;
@scooby
scooby / register classes.cpp
Created February 13, 2009 23:37
tried different ways of registering classes, but the simple and stupid is the only reliable way
#include <iostream>
using namespace std;
class x {
public:
virtual const char* symbol(void) { return "x"; }
virtual void speak() { cout << "'x' says 'your mom'" << endl; }
private:
static char* sym;
};
@scooby
scooby / boolorder.cpp
Created February 13, 2009 23:36
turns out false < true
#include <iostream>
using namespace std;
int main(void) {
if(false < true)
cout << "False is less than true." << endl;
if(false > true)
cout << "False is greater than true." << endl;
if(true < false)
@scooby
scooby / multimap_test.cpp
Created February 13, 2009 23:35
multimap test insert and iterating
#include <iostream>
#include <map>
using namespace std;
int main(void) {
multimap<int, int> mm;
for(int i = 20; i; i--)
mm.insert(make_pair((i * 3) & 7 + i, (i * 5) & 7));
multimap<int, int>::iterator it = mm.begin();