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
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
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}"
@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 / meme.rb
Created May 17, 2011 10:02
Meme generator using local images
#!/usr/bin/env ruby
#
# OMG THIS CODE IS SO UGLY
# but...
# IT WORKS!!
#
# Hacked together by http://github.com/marcinbunsch
#
# This assumes the following:
# - That you're on a Mac
@marcinbunsch
marcinbunsch / gist:1044437
Created June 24, 2011 08:30
Rails production prompt change as a Rails initializer
# Put this file in config/initializers/irb.rb
# Works in Rails 3.0+, should also work in 2.3
# Override the IRB, to provide the Rails environment in the prompt
module IRB
class << self
def setup_with_prompt_override(ap_path)
setup_without_prompt_override(ap_path)
env = (Rails.env.to_sym == :production ? "\033[00;31mPRODUCTION\033[00m" : Rails.env)
@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 / profiling_tool.rb
Created December 29, 2011 14:22 — forked from ksarna/profiling_tool.rb
Profiling rails requests with ruby-prof
# You can use this class in your console. For example
# p = ProfilingTools.new
# p.profiled_request(:controller => :welcome, :action => :index)
# this will profile whole application stack and save file in your tmp/profiler folder
# You can also use +request+ method just to see the output for example:
#
# p.request(:controller => :offers, :action => :index)
#
# p.response.body
# p.response.cookies # and so on