Skip to content

Instantly share code, notes, and snippets.

import Darwin
extension Array {
func shuffle() -> Array {
// this will sometimes crash (submitted bug #17127524)
self.sort { _,_ in arc4random_uniform(2) == 1 }
return self
}
mutating func removeAtIndexes( indexes:Int... ) {
indexes.sort(>)
# Throttled Input event
#
#= provides throttled:input
#
#= require jquery
#
# Delays firing `input` event until user is done typing.
#
# ### Events
#
@rfunduk
rfunduk / setup-WxH.applescript
Created August 22, 2013 21:27
Example AppleScript for re-arranging commonly used windows for a screen resolution. Eg. switching between laptop at 1440x900 and external monitor at 2560x1440 is a big pain, requiring a lot of moving around and resizing of windows. So instead you adapt this script, make a setup-1440x900.applescript and a setup-2560x1440.applescript, and run them…
tell application "Flint" to activate -- needs to be in front
tell application "System Events" to tell application process "Flint"
try
get properties of window 1
set size of window 1 to {700, 800}
set position of window 1 to {1700, 300}
end try
end tell
tell application "Adium" to activate -- needs to be in front
@rfunduk
rfunduk / int_to_roman_numerals.rb
Created August 18, 2013 19:07
Using only single numerals (eg, no definition in `map` for `40 => 'XL'`), convert an integer to it's equivalent roman numeral string. Run with `ruby int_to_roman_numerals.rb test` or `ruby int_to_roman_numerals.rb 1`
#!/usr/bin/env ruby
class Integer
def to_roman_numerals
num = self
map = {
1 => 'I',
5 => 'V',
10 => 'X',
;;; DECK
(ns card-game.deck)
(defn create []
(shuffle [:h2 :h3 :h4 :h5 :h6 :h7 :h8 :h9 :h0 :hj :hq :hk :ha
:d2 :d3 :d4 :d5 :d6 :d7 :d8 :d9 :d0 :dj :dq :dk :da
:s2 :s3 :s4 :s5 :s6 :s7 :s8 :s9 :s0 :sj :sq :sk :sa
:c2 :c3 :c4 :c5 :c6 :c7 :c8 :c9 :c0 :cj :cq :ck :ca])
)
(ns fizzbuzz.core (:gen-class))
(use '[clojure.string :only [blank? capitalize]])
; a macro which expands (fbfn name M) to a function of one
; argument N which outputs "Name" if N % M == 0, otherwise ""
(defmacro fbfn [name test]
`(fn [arg#] (if (zero? (mod arg# ~test))
~(capitalize (str name)) ""))
)
@rfunduk
rfunduk / autoshot.rb
Created December 4, 2012 21:30
Auto-scp screenshots to a webserver and copy the url to your clipboard (on OSX)
#!/usr/bin/env ruby
# autoshot.rb
#
# Ryan Funduk (ryanfunduk.com)
# Licensed under WTFPL (http://sam.zoy.org/wtfpl)
#
# Watch a directory and scp new files to a host that
# is running a webserver. Only works on OSX, could be
# made to work on other platforms with alternatives
@rfunduk
rfunduk / gist:3206815
Created July 30, 2012 13:18 — forked from avibryant/gist:3200554
The Regex Game
The Regex Game
Avi Bryant
This is a game for two programmers, although it's easy to imagine variations for more.
It can be played over email, twitter, or IM, but it's easy to imagine a custom web app for it, and I encourage someone to build one.
Each player starts by thinking of a regular expression. The players should decide beforehand on dialect and length restrictions (eg, has to be JavaScript-compatible and under 20 characters).
They don't reveal the Regex, but if playing over email etc, should send each other a difficult to brute force hash (eg bcrypt) of the Regex for later verification.
They do reveal two strings: one which the Regex will match, and one which it will not.
@rfunduk
rfunduk / an_initializer.rb
Created June 8, 2012 13:29
Rails 3.2.x log usefulness *= 1_000_000_000
# SHUT UP with the "GET /assets/whatever..." in the log. Do not want.
if Rails.env.development?
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
@rfunduk
rfunduk / resque.god
Created May 26, 2012 12:24
Sample god config
rails_env = ENV['RAILS_ENV'] || "development"
rails_root = ENV['RAILS_ROOT'] || Dir.pwd
num_workers = rails_env == 'production' ? 5 : 1
num_workers.times do |num|
God.watch do |w|
w.dir = "#{rails_root}"
w.name = "resque-#{num}"
w.group = 'resque'
w.interval = 30.seconds