Skip to content

Instantly share code, notes, and snippets.

View compwron's full-sized avatar
💭
https://github.com/drop-ice/dear-github-2.0

compwron compwron

💭
https://github.com/drop-ice/dear-github-2.0
View GitHub Profile
# How to find out where a method comes from.
# Learned this from Dave Thomas while teaching Advanced Ruby Studio
# Makes the case for separating method definitions into
# modules, especially when enhancing built-in classes.
module Perpetrator
def crime
end
end
class Fixnum
@guenter
guenter / move_to_rds.rb
Created November 11, 2010 02:14
A quick and dirty script to move a database into Amazon RDS (or any other database). Can transfer part of the data beforehand.
require 'fileutils'
start_time = Time.now
SOURCE_DB = {
:name => 'db_name',
:user => 'db_user',
:password => 'db_pass',
:host => 'localhost'
@peter
peter / gist:700194
Created November 15, 2010 09:21
Rails Migration With Tests
class ImportLegacyDevices < ActiveRecord::Migration
def self.up
return unless Rails.env.production?
legacy_devices.each do |device_id, issue|
if device = Device.find_by_hardware_id(device_id)
unless InclusiveIssue.exists?(:issue_id => issue.id, :device_id => device.id)
InclusiveIssue.create!(
:issue => issue,
:device => device,
@medmunds
medmunds / knockout-jquery-ui-widget.js
Created March 27, 2011 17:35
Knockout binding for jQuery.ui.widget
// knockout-jquery-ui-widget.js
// Copyright (c) 2011, Planapple, Inc.
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
//
// Knockout binding for jQuery UI widgets
//
// Examples:
// <input type="submit" value="OK" data-bind='jqueryui: "button"' />
//
// Attaches a jQuery UI button widget to this button, with default options.
@pksunkara
pksunkara / config
Last active April 28, 2024 18:59
Sample of git config file (Example .gitconfig) (Place them in $XDG_CONFIG_HOME/git)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
username = pksunkara
[init]
defaultBranch = master
[core]
editor = nvim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
pager = delta
@wtaysom
wtaysom / where_is.rb
Created September 23, 2011 08:57
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@denmarkin
denmarkin / common_steps.rb
Created November 2, 2011 17:15
Cucumber + Capybara HTML table comparison from http://railscasts.com/episodes/186-pickle-with-cucumber
Then(/^I should see (.+) table$/) do |table_id, expected_table|
html_table = table_at("##{table_id.parameterize.tableize}").to_a
html_table.map! { |r| r.map! { |c| c.gsub(/<.+?>/, '').gsub(/[\n\t\r]/, '') } }
expected_table.diff!(html_table)
end
@steve9001
steve9001 / application.rb
Created December 7, 2011 16:18
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@fnichol
fnichol / README.md
Created February 26, 2012 01:23
A Common .ruby-version File For Ruby Projects

A Common .ruby-version File For Ruby Projects

Background

I've been using this technique in most of my Ruby projects lately where Ruby versions are required:

  • Create .rbenv-version containing the target Ruby using a definition name defined in ruby-build (example below). These strings are a proper subset of RVM Ruby string names so far...
  • Create .rvmrc (with rvm --create --rvmrc "1.9.3@myapp") and edit the environment_id= line to fetch the Ruby version from .rbenv-version (example below).

Today I learned about another Ruby manager, rbfu, where the author is using a similar technique with .rbfu-version.

@vitorbaptista
vitorbaptista / infinite_hangouts.sh
Created May 24, 2012 17:25
Infinite Google Hangouts
#!/bin/sh
# Change this to the button coordinates.
# To discover it, wait for it to appear, open a terminal,
# put the cursor over it and run "xdotool getmouselocation".
BUTTON_COORDINATES="300 800"
while (true)
do
xdotool mousemove $BUTTON_COORDINATES click 1 \