Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
Ship it!

Ricardo Shiota Yasuda shadowmaru

:shipit:
Ship it!
View GitHub Profile
@shadowmaru
shadowmaru / db-open
Created Mar 6, 2017 — forked from helderco/db-open
Script to open a mysql database in Sequel Pro from a service in docker-compose.
View db-open
#!/bin/bash
set -e
show_help() {
cat << EOF
Usage: ${0##*/} [-u USER] [-p PASS] [-P PORT] [-H HOST] [DATABASE]
${0##*/} -h
Open a standard connection in Sequel PRO.
View devise.pt-BR.yml
pt-BR:
errors:
messages:
expired: "expirou, por favor solicite uma nova"
not_found: "não encontrado"
already_confirmed: "já foi confirmado, por favor tente fazer login"
not_locked: "não foi bloqueado"
not_saved:
one: "1 erro evitou que este %{resource} fosse gravado:"
other: "%{count} erros evitaram que este %{resource} fosse gravado:"
View migrate_products_to_paperclip.rb
class MigrateProductsToPaperclip < ActiveRecord::Migration
def self.up
# Rename the old "image" column to "old_file_name", since Product.image will now try to do Paperclip stuff
rename_column :products, :image, :old_file_name
# Rename asset directories to pluralize
File.rename("public/system/product","public/system/products")
File.rename("public/system/products/image","public/system/products/images")
View local-backup.rb
DIRECTORIES = %w(Users/username)
TO = '/path/for/backup'
OPTIONS = { :rsync => '--progress -varRu', :remote => false }
rsync DIRECTORIES, nil, TO, OPTIONS
View backup.rb
require 'rubygems'
require 'activesupport'
def rsync(directories, from, to, options = {})
options.reverse_merge!(:rsync => "-varRu",
:remote => true)
directories.each do |dir|
destination = options[:remote] ? "#{from}:/#{dir}" : "/#{dir}"
command = "rsync #{options[:rsync]} #{destination} #{to}"
View tm-migration.sh
#
# Generates the migration and opens it in TextMate
#
# ex.:
# mig AddNewColumnToModel new_column:integer
#
function mig {
mate `script/generate migration $@ | tail -n1 | sed 's/.*create //'`
}
View controller_for_image_model.rb
class ImageModelsController < ApplicationController
before_filter :find_image_model, :only => [:update]
def update
if @image_model.update_attributes(params[:image_model])
@image_model.image.reprocess!
end
end
protected