Skip to content

Instantly share code, notes, and snippets.

View supairish's full-sized avatar
🏂
Shreddin

Chris Irish supairish

🏂
Shreddin
View GitHub Profile
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
require 'right_aws'
namespace :utils do
namespace :attachments do
task :initialize_s3 => :environment do
s3_config = YAML.load_file(File.join(File.dirname(__FILE__), '/../../config/amazon_s3.yml'))
s3_config = s3_config[RAILS_ENV].to_options
@s3 = RightAws::S3.new(s3_config[:access_key_id], s3_config[:secret_access_key])
end
module PaperclipMigrations
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def add_paperclip_fields(table, prefix)
add_column table, "#{prefix}_file_name", :string
add_column table, "#{prefix}_content_type", :string
@langalex
langalex / upstream_rails_application_template.rb
Created March 6, 2009 19:49
upstream rails application template
# rails application template for generating customized rails apps
#
# == requires ==
#
# * rails 2.3+, rspec, cucumber, culerity (langalex-culerity gem), machinist
#
# == a newly generated app using this template comes with ==
#
# * working user registration/login via authlogic, cucumber features to verify that it works
# * rspec/cucumber/culerity for testing
//The jQuery validate plugin validates on the name attribute,
//which is problematic in Rails because every checkbox
//gets a hidden input with the same name.
//Here's how to validate the checkbox, not the hidden input:
var validate = function(){
$(':input:hidden').attr('name', 'new_name');
$('form').validate({
rules: {"checkbox": "required"},
messages: {"checkbox": "CHECK ME"},
# Include this in your RAILS_ROOT/test/test_helper.rb
class ActionController::TestCase
def better_cookies
cookies = {}
Array(@response.headers['Set-Cookie']).each do |cookie|
key = nil
details = cookie.split(';').inject({}) do |fields, cookie_field|
pair = cookie_field.split('=').map {|val| Rack::Utils.unescape(val.strip)}
key = pair.first unless key
#Tasks have been added to fully maintain nginx, unicorn, redis, memcached, start resque workers and run any command on any server in the farm.
#<pre>
#cap nginx:restart # Restart Nginx.
#cap nginx:start # Start Nginx.
#cap nginx:status # Status of Nginx.
#cap nginx:stop # Stop Nginx.
#cap nginx:tail_error # Tail the Nginx error logs.
#cap unicorn:reload # reload your unicorn servers.
#cap unicorn:restart # restart your unicorn servers.
#cap unicorn:start # start your unicorn servers.
@serek
serek / migration.rb
Created April 22, 2010 13:15 — forked from firebelly/paperclip_migrations.rb
Migration from attachment_fu to paperclip.
class ConvertImagesToPaperclip < ActiveRecord::Migration
include PaperclipMigrations
def self.up
# Paperclip
add_column :images, :data_file_name, :string
add_column :images, :data_content_type, :string
add_column :images, :data_file_size, :integer
add_column :images, :data_updated_at, :datetime
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
module LastRequestResponse
def last_request
page.driver.last_request
end
def last_response
page.driver.last_response
end
end