Skip to content

Instantly share code, notes, and snippets.

View colindean's full-sized avatar
🏆
Helping others find happiness and serenity

Colin Dean colindean

🏆
Helping others find happiness and serenity
View GitHub Profile
@colindean
colindean / AriaDownloadStrategy.rb
Created March 16, 2017 23:24
Slowly working on adding Aria2 support to Homebrew Cask
class AriaDownloadStrategy < CurlDownloadStrategy
def aria_args(options = {})
aria = Pathname.new ENV["HOMEBREW_ARIA"]
aria = Pathname.new "/usr/local/bin/aria2c" unless aria.exist?
raise "#{aria} is not executable" unless aria.exist? && aria.executable?
args = [
aria.to_s,
@colindean
colindean / brew-updates.12h.sh
Created September 2, 2016 00:55
bitbar plugins as of 20160901
#!/bin/bash
####
# List available updates from Homebrew (OS X)
###
exit_with_error() {
echo "err | color=red";
exit 1;
}
@colindean
colindean / contract.rb
Created July 29, 2016 03:34
DSL for building contracts using mixins and inheritance
class AbstractionsContractBase < ContractBase
include AbstractionsContract::Clauses::CodeOfConduct
include AbstractionsContract::Clauses::LiabilityDisclaimer
end
class AbstractionsBronzeContract < AbstractionsContractBase
include AbstractionsContract::Clauses::PaidSponsorship
min_payment 10_000.USD
include AbstractionsContract::Clauses::Perks::WebsiteLogo
include AbstractionsContract::Clauses::Perks::Table
@colindean
colindean / BenchmarkStringAccumulation.scala
Created May 24, 2016 15:43
A simple result of a benchmark of string accumulation in Scala
class BenchmarkStringAccumulation {
def timeSInterpolation(reps: Int) = repeat(reps) {
strings.foldLeft("") { (acc, string) => s"$acc$string" }
}
def timeFInterpolation(reps: Int) = repeat(reps) {
strings.foldLeft("") { (acc, string) => f"$acc%s$string%s" }
}
def timeConcat(reps: Int) = repeat(reps) {
strings.foldLeft("") { (acc, string) => acc + string }
}
@colindean
colindean / eight_letter_words_with_differing_two_letters.sh
Created April 10, 2016 21:36
8-letter word pairs which differ only in the second letter
#!/bin/bash
#
# Todd Kaufman shared this:
# https://codeandsupply.slack.com/archives/chat/p1460305918002336
# > there's a surprisingly large number of 8-letter word pairs which differ only in the second letter (related to npr puzzler)
# > should be `grep '^[a-z].....[a-z].$'` because linux has a bunch of apostrophe-s's which should not be there.
# > OTOH, the OSX version (Webster's 2nd) doesn't even have plurals, though it does generally have "more words" (but fewer lines). Did find the answer on linux though... but downloading a copy of wordnet to have on hand
grep '^[a-z].......$' /usr/share/dict/words | perl -pe '$w=substr($_,0,1) . substr($_,2,6); print "$w\t";' | sort | perl -ne 'chomp; ($k,$w)=split(/\t/); print "$w $wl\n" if ($k eq $kl); ($wl,$kl)=($w,$k);'
@colindean
colindean / QuantityCheck.scala
Created October 13, 2015 20:57
QuantityCheck - a wrapper around Seq#lengthCompare because I like matching words instead of remembering -1/0/1
class QuantityCheck[T](thing: Seq[T])
case class JustRight[T](thing: Seq[T]) extends QuantityCheck(thing)
case class TooFew[T](thing: Seq[T]) extends QuantityCheck(thing)
case class TooMany[T](thing: Seq[T]) extends QuantityCheck(thing)
object QuantityCheck {
def apply[T](number: Int)(seqLike: Seq[T]): QuantityCheck[T] = {
seqLike.lengthCompare(number) match {
case x if x < 0 => TooFew(seqLike)
case x if x == 0 => JustRight(seqLike)
case x if x > 0 => TooMany(seqLike)
@colindean
colindean / gist:c307b5bc693daa24d821
Created June 7, 2015 17:05
Password Establishment Protocol: Password Negotiation for Password Managers (mirrored from http://pastebin.com/tW9yWegZ)
Network Working Group Thomas Brownback
Request for Comments: xxxx Independent Researcher
Category: Experimental Month YYYY
Password Negotiation for Password Managers
Abstract
This document proposes a protocol that would enable a password
manager (PM) to register or change a password with online
@colindean
colindean / NodeId.scala
Last active August 29, 2015 14:21
AnyVal with subclasses
class NodeId(val id: Int)
case class DocumentId(override val id: Int) extends NodeId(id)
case class ContainerId(override val id: Int) extends NodeId(id)
case class UserId(override val id: Int) extends NodeId(id)
// how can I get DocumentId, ContainerId, and UserId to be a NodeId and still extend AnyVal?
// this seems to work:
@colindean
colindean / steam-win32.rb
Created May 1, 2015 22:07
A half-attempt at a Ruby library for getting Steam information from the Windows registry.
# warning: this was never tested.
# license: cc0
require 'win32/registry'
module SteamR; module Registry
STEAM_HKEY_ROOT = 'SOFTWARE\Valve\Steam'
HKEYS = {
@colindean
colindean / afp.conf
Created April 4, 2015 15:59
afp and netatalk config for Time Machine backups
[Global]
uam path = /usr/local/etc/netatalk/uams
max connections = 256
tcprcvbuf = 262144
tcpsndbuf = 262144
server quantum = 262144
zeroconf = yes
guest account = guest
uam list = uams_passwd.so uams_gss.so uams_guest.so uams_dhx2_pam.so
veto files = /.AppleDB/.AppleDouble/.AppleDesktop/:2eDS_Store/Network Trash Folder/Temporary Items/TheVolumeSettingsFolder/.@__thumb/.@__desc/:2e*/.@__qini/.Qsync/.upload_cache/.qsync/.qsync_sn/