Skip to content

Instantly share code, notes, and snippets.

View marcinbunsch's full-sized avatar

Marcin Bunsch marcinbunsch

View GitHub Profile
@marcinbunsch
marcinbunsch / array_invoke.rb
Created October 14, 2009 20:26
Array#invoke
class Array
# invoke a method on each element of the array and return an array of return values
def invoke(method_name, *args, &block)
collect { |item| item.send(method_name, *args, &block) }
end
end
# Benchmark of different solutions to mislav's "Find the longest common starting substring in a set of strings" contest
# http://stackoverflow.com/questions/1916218/find-the-longest-common-starting-substring-in-a-set-of-strings
# Solutions:
# mislav
class String
def &(other)
difference = other.to_str.each_char.with_index.find { |ch, idx|
self[idx].nil? or ch != self[idx].chr
require 'appscript'
require 'open-uri'
require 'json'
require 'youtube_g'
include Appscript
itunes = app('iTunes')
safari = app('Safari')
# Get info on track
current_track = "#{itunes.current_track.name.get}"
Appscript
http://appscript.sourceforge.net/
http://appscript.sourceforge.net/rb-appscript/index.html
Matt Neuburg "Scripting Mac Applications With Ruby: An AppleScript Alternative"
http://www.apeth.com/rbappscript/00intro.html
Things-client
http://github.com/marcinbunsch/things-client
@marcinbunsch
marcinbunsch / domain.rb
Created November 5, 2010 17:26
Simple hostfile manager
#!/usr/bin/env ruby
#
# Simple hostfile manager
#
# Only tested on OSX
#
# Usage:
#
# To list defined entries in the hostfile, call:
#
@marcinbunsch
marcinbunsch / flip_date.rb
Created April 5, 2011 10:38
Simple regex to flip DD/MM/YY to MM/DD/YY and back
str = '4/11/01'
# => "4/11/01"
str.sub!(/(\d+)\/(\d+)\/(\d+)/, '\\2/\\1/\\3')
# => "11/4/01"
str.sub!(/(\d+)\/(\d+)\/(\d+)/, '\\2/\\1/\\3')
# => "4/11/01"
@marcinbunsch
marcinbunsch / things-yammer-checkin
Created July 8, 2011 11:41 — forked from cziko/things-yammer-checkin
Things - Yammer checkin script
#!/usr/bin/ruby
# gem install things-client --source http://gemcutter.org
# gem install broadcast
require 'rubygems'
require 'things'
require 'broadcast'
@marcinbunsch
marcinbunsch / true_dat.rb
Created February 23, 2012 19:08
True#dat
class TrueClass
def dat
self
end
end
true.dat # => true
@marcinbunsch
marcinbunsch / lochness.rb
Created March 7, 2012 17:11
Loch Ness Monster Case implementation in Ruby
class String
def loch_ness_monster_case
self.split('::').collect do |section|
section.gsub(/([^\/])([A-Z])/, '\1_\2').downcase.split(/_/).collect { |part|
chars = part.split('')
half = chars.length/2
chars[half].upcase!
chars[half - 1].upcase!
chars.join('')
@marcinbunsch
marcinbunsch / graceful.rb
Created March 14, 2012 17:36
Gracefult quit
require "singleton"
class GracefulQuit
include Singleton
attr_accessor :breaker
def initialize
self.breaker = false
end