This file contains 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
@echo off | |
goto endofruby | |
#!/bin/ruby | |
git_repo = "git://github.com/rails/rails.git" | |
help = %Q{ | |
Rails Info: | |
-v, --version Show the Rails version number and quit. | |
-h, --help Show this help message and quit. | |
This file contains 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
# Potential solution to "Using accepts_nested_attributes_for with a belongs_to association, and using find_or_create_by_attr behaviour" | |
# http://stackoverflow.com/questions/2970255/using-accepts-nested-attributes-for-with-a-belongs-to-association-and-using-find | |
class Upload < AR:B | |
belongs_to :user | |
belongs_to :observed_property | |
belongs_to :sensor | |
attr_accessor :observed_property_attributes, | |
:sensor_attributes | |
attr_accessible :observed_property_attributes, |
This file contains 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 | |
require 'rubygems' | |
require 'roo' | |
pwd = File.dirname(__FILE__) | |
Dir.glob("#{pwd}/*.xls") do |file| | |
file_path = "#{pwd}/#{file}" | |
file_basename = File.basename(file, ".xls") | |
xls = Excel.new(file_path) |
This file contains 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
# install rvm | |
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm) | |
# install ruby 1.9.2 + some global gems | |
rvm install 1.9.2 | |
rvm use 1.9.2@global | |
gem install awesome_print map_by_method wirble bundler builder pg cheat | |
gem install -v2.1.2 builder |
This file contains 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
# Relevant example from our monitrc file. | |
check process couchdb with pidfile /usr/local/var/run/couchdb/couchdb.pid | |
start program = "/etc/init.d/couchdb start" | |
stop program = "/etc/init.d/couchdb stop" | |
if cpu > 60% for 2 cycles then alert | |
if cpu > 80% for 5 cycles then restart | |
if memory usage > 70% MB for 5 cycles then restart |
This file contains 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
# config/initializers/active_admin.rb | |
require 'active_admin_custom_filter' | |
ActiveAdmin.setup do |config| | |
# ... | |
end |
This file contains 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
# Quick fork by @mcjim to add stash status and tweak to suit his style. | |
# http://henrik.nyh.se/2008/12/git-dirty-prompt | |
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ | |
# host dir master $ # clean working directory | |
# host dir master* $ # dirty working directory | |
# host dir master*^ $ # dirty working directory with stash | |
# host dir master^ $ # clean working directory with stash | |
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*" |
This file contains 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
source 'http://rubygems.org' | |
gem 'rails3-jquery-autocomplete' |
This file contains 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 ImageUploader < CarrierWave::Uploader::Base | |
include CarrierWave::MiniMagick | |
storage :file | |
def thumb(size) | |
begun_at = Time.now | |
size.gsub!(/#/, '!') | |
uploader = Class.new(self.class) | |
uploader.versions.clear | |
uploader.version_names = [size] |
This file contains 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
# Add to the given file the given lines, after the line with the given text, or replace the content | |
def add_to_file(path, text, after=nil, replace=false) | |
lines = [] | |
if replace | |
lines = text | |
else | |
File.readlines(path).each do |line| | |
if after != nil and line.include?(after) | |
lines << line | |
lines << text |
OlderNewer