Skip to content

Instantly share code, notes, and snippets.

@ohammersmith
ohammersmith / gist:48788
Created January 18, 2009 22:14
Ruby script in a Windows batch script
@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.
# 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,
#!/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)
@mystix
mystix / passenger-nginx-setup.sh
Created March 21, 2011 14:00
Rackspace Ubuntu -- RVM + PostgreSQL + Passenger + NGiNX setup script
# 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
@codypo
codypo / monitex
Created April 6, 2011 14:21
Monit example for restarting a service on excessive memory consumption
# 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
@rdj
rdj / active_admin.rb
Created July 1, 2011 06:39
active_admin custom filter
# config/initializers/active_admin.rb
require 'active_admin_custom_filter'
ActiveAdmin.setup do |config|
# ...
end
@mcjim
mcjim / .bashrc
Last active July 21, 2023 22:16 — forked from henrik/.bashrc
Git branch, dirty and stash state in Bash prompt.
# 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 "*"
@bbonamin
bbonamin / Gemfile
Created October 3, 2011 01:52
rails3-jquery-autocomplete in ActiveAdmin?
source 'http://rubygems.org'
gem 'rails3-jquery-autocomplete'
@DAddYE
DAddYE / image_uploader.rb
Created December 30, 2011 22:57
CarrierWave on the fly resizer (work as dragonfly)
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]
@ringe
ringe / newapp.rb
Created February 7, 2012 09:41
Rails Template with Cucumber, RSpec, FactoryGirl, Capybara, Spork, Watchr, Devise on MySQL in a Vagrant environment
# 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