Instantly share code, notes, and snippets.

@kch
kch / wgt.rb
Created May 12, 2016
sort wgt bands by time, append location
View wgt.rb
#!/usr/bin/env ruby
s = ARGF.read =~ /Freitag, 13. Mai 2016.*?(?=\n\n)/m && $&
s.gsub! /^(\d\d)\.(\d\d)\u00A0Uhr\n/, "\\1:\\2h -- "
days = []
s.lines.each do |l|
case l
when /^\d\d:\d\dh -- Einlaß/ then :pass
when /Mai 2016$/ then days << [l, []]
when /^\d\d:\d\dh -- / then days.last[1] << l.sub(/\Z/, " -- @ #{$x}")
@kch
kch / infix-functions.swift
Last active Jul 17, 2016
Use any binary function as infix operator in Swift
View infix-functions.swift
infix operator « { precedence 131 associativity left }
func «<A,B,C>(a:A, f:(A,B) -> C) -> B -> C { return { f(a,$0) } }
infix operator » { precedence 131 associativity left }
func »<B,C>(f:(B) -> C, b:B) -> C { return f(b) }
infix operator < { precedence 131 associativity left }
func <<A,B,C>(a:A, f:(A,B) -> C) -> B -> C { return { f(a,$0) } }
infix operator > { precedence 131 associativity left }
@kch
kch / partial.swift
Created Apr 2, 2015
Irregular/arbitrary/out-of-order partial application in Swift
View partial.swift
struct Placeholder {}
let __ = Placeholder()
func partial<A,B,Z>(f:(A,B) -> Z, a:Placeholder, b:B) -> (A) -> Z { return { f($0,b) } }
func partial<A,B,Z>(f:(A,B) -> Z, a:A, b:Placeholder) -> (B) -> Z { return { f(a,$0) } }
func partial<A,B,C,Z>(f:(A,B,C) -> Z, a:Placeholder, b:B, c:C) -> (A) -> Z { return { f($0,b,c) } }
func partial<A,B,C,Z>(f:(A,B,C) -> Z, a:A, b:Placeholder, c:C) -> (B) -> Z { return { f(a,$0,c) } }
func partial<A,B,C,Z>(f:(A,B,C) -> Z, a:A, b:B, c:Placeholder) -> (C) -> Z { return { f(a,b,$0) } }
@kch
kch / itunes-radio-silence-ads.applescript
Last active Aug 29, 2015
mute iTunes Radio during ads
View itunes-radio-silence-ads.applescript
tell application "iTunes"
-- this script only makes sense for iTunes radio, so bail if not it
if container of current playlist is not equal to source "iTunes Radio" then return
-- mute first because ads are so fucking annoying
set mute to true
-- tracks shorter than this number of seconds should be muted as they're likely ads
set _k_mute_threshold to 32
View keybase.md

Keybase proof

I hereby claim:

  • I am kch on github.
  • I am kch (https://keybase.io/kch) on keybase.
  • I have a public key whose fingerprint is 896A A376 3566 F68D 066B 5BEF EAF6 44A0 0B63 A2DE

To claim this, I am signing this object:

View rooftop.md

Pedro's Amazing Guide To Rooftop Bars

Very few people respect the art of rooftop drinking these days.

The problem faced by Rooftop bars is that their customers often believe they're being respectful because they're wearing a suit or a fancy dress.

Niclekback wears suits

Nevermind all the people that COMPLETELY FUCKED UP MUSIC AS WE KNOW IT while dressing well. We're still associating fancy dressing with respect.

@kch
kch / safari.rb
Created May 31, 2013
Enable private browsing mode, open a new page in Safari for the given URL.
View safari.rb
#!/usr/bin/env ruby
($stderr.puts(DATA.read.gsub("$0", File.basename($0))); exit 1) if ARGV.length != 1
require 'appscript'
safari_app = Appscript.app("Safari")
safari_process = Appscript.app('System Events').processes['Safari']
safari_app.activate
View pdfpen-merge-documents.rb
#!/usr/bin/env ruby
# encoding: UTF-8
# merge pages from two pdf documents (same as Merge Every Other)
# only the two documents to be merged must be opened, the first must be the front window.
# this assumes a feed scanner, hence expects the second document's pages to be reversed.
require 'appscript'
include Appscript
View Play Selected Track Next.rb
#!/usr/bin/env ruby
# encoding: UTF-8
pid = fork and (Process.detach(pid); exit) # Go to background.
require 'appscript'
SRC_MACRUBY_WAIT_FOR_PLAYER_NOTIFICATION = <<-RUBY
framework "Cocoa"
def playerInfo(notification); exit; end
View itunes-mk-playlist.rb
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
require 'pathname'
include Appscript
### Usage:
# ./itunes-mk-playlist.rb \
# ~/"Music/iTunes/iTunes Media/Music/Atomine Elektrine/Zektor X/09 ...and Ever.mp3" \