Skip to content

Instantly share code, notes, and snippets.

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
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 / strip_html.rb
Created Apr 21, 2009
my super duper html stripper regexp
View strip_html.rb
class String
def strip_html!
\/? # optional end tag
([\w:-]+) # tag name (capturing)
(?: # optional attribute set (allowing even for end tags)
(?: # group for attribute repetition
\s+ # mandatory space before first attribute
[\w:-]+ # attribute name
kch / tracy.rb
Created Apr 25, 2009
dynamically define a method that takes a block in ruby 1.8; inspired by the pragprog metaprogramming screencasts
View tracy.rb
module Tracy
def self.included k
k.extend ClassMethods
module ClassMethods
def method_added m
kch / cas-sql-authenticator-original.rb
Created May 14, 2009
UR DOIN' IT WRONG (untested)
View cas-sql-authenticator-original.rb
class CASServer::Authenticators::SQL < CASServer::Authenticators::Base
def validate(credentials)
raise CASServer::AuthenticatorError, "Cannot validate credentials because the authenticator hasn't yet been configured" unless @options
raise CASServer::AuthenticatorError, "Invalid authenticator configuration!" unless @options[:database]
CASUser.establish_connection @options[:database]
CASUser.set_table_name @options[:user_table] || "users"
kch / think before you
Created May 14, 2009
How to not waste lines and save kittens
View think before you

So I ran into a bit of code that looked like this:

def my_method
  list.each do |item|
    return_value = item.some_property
    return return_value if return_value
kch / modsux.rb
Created Nov 3, 2009
Assimilates git submodules' files, gets properly rid of the submodule metadata.
View modsux.rb
#!/usr/bin/env ruby
require 'yaml'
require 'pathname'
require 'shellwords'
module_url_by_path = Dir['**/.gitmodules'].inject({}) do |h, path|^\[submodule .*\].*\n((?:\s+.*\n)+)/).flatten.each do |s_attrs|
h_attrs = s_attrs.strip.split(/\n/).inject({}) do |h_attrs, s_attr_line|
k, v = s_attr_line.strip.split(/\s+=\s+/, 2)
h_attrs[k.to_sym] = v
View gruber-url-regex.rb
require 'yaml'
urls = YAML::load <<-STR : :
(Something like : : :
kch / format number with separators.rb
Created Nov 29, 2009
format numbers with separators using a single regex substitution operation
View format number with separators.rb
require 'yaml'
RX = /(\d)(?=\d{3}+(?!\d))/
# Long version
(\d) # One digit
(?= # That is followed by
\d{3}+ # One or more triples of digits
(?!\d) # That are not followed by a digit
kch / 0-tm-align-assignments.rb
Created Dec 19, 2009
fancier align assignments command for textmate
View 0-tm-align-assignments.rb
#!/usr/bin/env ruby1.9
# encoding: UTF-8
# Copyright © 2009 Caio Chassot
# Licensed under the WTFPL
def alternation(*s);"|") end
# All input is read here.
LINES = $stdin.readlines
You can’t perform that action at this time.