This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Simple hostfile manager | |
# | |
# Only tested on OSX | |
# | |
# Usage: | |
# | |
# To list defined entries in the hostfile, call: | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder