Skip to content

Instantly share code, notes, and snippets.

View deivid-rodriguez's full-sized avatar

David Rodríguez deivid-rodriguez

View GitHub Profile
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
@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
@bdjnk
bdjnk / alarm.sh
Last active March 11, 2018 13:42
Bash Suspend Alarm Clock with Gradual Volume and Fallback
#!/bin/bash
__script_version="1.1"
#-----------------------------------------------------------------------
# Default values
#-----------------------------------------------------------------------
human_time="6:20 tomorrow"
@julitrows
julitrows / email.css
Last active March 19, 2018 07:07
HTML Email Boiler Plate in HAML with separated CSS
/* Based on The MailChimp Reset INLINE: Yes. */
/* Client-specific Styles */
#outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */
body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
/* Prevent Webkit and Windows Mobile platforms from changing default font sizes.*/
.ExternalClass {width:100%;} /* Force Hotmail to display emails at full width */
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}
/* Forces Hotmail to display normal line spacing. More on that: http://www.emailonacid.com/forum/viewthread/43/ */
#backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}
/* End reset */
@mirek
mirek / passenger.rake
Last active April 3, 2018 12:05
Passenger restart task in Capistrano 3.x with Rails 4.x
namespace :deploy do
after :restart, :restart_passenger do
on roles(:web), in: :groups, limit: 3, wait: 10 do
within release_path do
execute :touch, 'tmp/restart.txt'
end
end
end
after :finishing, 'deploy:restart_passenger'
end
@marcandre
marcandre / require_changer.rb
Created October 6, 2018 03:19
require -> require_relative
require 'pathname'
Pathname('./lib').children.select(&:directory?).map(&:basename).each do |name|
Dir["./lib/#{name}/**/*.rb"].each do |path|
begin
code = File.read(path)
code.gsub!(%r{^(\s*)require (['"])#{name}/([\w/]*)['"]}) do
relative_path = Pathname("./lib/#{name}/#{$3}.rb").relative_path_from(Pathname(path).dirname)
%Q{#{$1}require_relative #{$2}#{relative_path.to_s[0..-4]}#{$2}}
end
File.write(path, code)
@xaviershay
xaviershay / http_client_spec.rb
Created December 13, 2011 02:19
Running a rack app in a thread for integration tests.
require 'integration_helper'
require 'rack'
require 'rack/handler/webrick'
describe HttpClient do
before :all do
@server = WEBrick::HTTPServer.new(
:Port => 9293,
:Logger => Rails.logger,
:AccessLog => Rails.logger
@tenderlove
tenderlove / mt_complete.rb
Last active December 11, 2020 19:56
tab completion for minitest tests
#!/usr/bin/env ruby --disable-gems
# Tab completion for minitest tests.
#
# INSTALLATION:
#
# 1. Put this file in a directory in your $PATH. Make sure it's executable
# 2. Run this:
#
# $ complete -o bashdefault -f -C /path/to/this/file.rb ruby
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@zentetsukenz
zentetsukenz / ruby_on_rails_deployment.md
Last active September 22, 2023 18:32
Deploy Ruby on Rails application with Docker Compose and Capistrano with ease

Docker

Files and Folders.

|
|\_ app
|...
|\_ docker
| |