Skip to content

Instantly share code, notes, and snippets.

View damuz91's full-sized avatar
🎯
Focusing

David Muñoz damuz91

🎯
Focusing
View GitHub Profile
@damuz91
damuz91 / mysql_db_backup.sh
Created April 26, 2017 13:22
Script for auto backing up a mysql db, gzip it and upload to Amazon S3
#!/bin/bash
DBNAME=mydb
USER="david"
PASSWORD='mypassword123'
DATE=`date +"%Y%m%d"`
SQLFILE=$DBNAME-${DATE}.sql
BUCKETNAME=my-aws-bucket-name
cd
echo "Starting with the following data:"
t.integer :status, default: User::Statuses[:active]
<%= @user.status_name %>
<%= f.select_tag :status, options_for_select(User.statuses_for_select, @user.status) %>
class User < ActiveRecord::Base
Statuses = {inactive: 0, active: 1, suspended: 2, deleted: 3}
def self.statuses_for_select
{
"Active" => Statuses[:active],
"Inactive" => Statuses[:inactive],
"suspended" => Statuses[:suspended],
"Deleted" => Statuses[:deleted]
}
class User < ActiveRecord::Base
Statuses = {inactive: 0, active: 1, suspended: 2, deleted: 3}
end
class User < ActiveRecord::Base
ACTIVE = 1
INACTIVE = 0
SUSPENDED = 2
DELETED = 3
end
# From
User::ACTIVE # => 1
User::INACTIVE # => 0
User::SUSPENDED # => 2
# To
User::Statuses[:active] # => 1
User::Statuses[:inactive] # => 0
User::Statuses[:suspended] # => 2
data = [{nombre: 'Juan', color: 'azul', edad: '50' }, {nombre: 'Carlos', color: 'verde', edad: '20' } ]
<table>
<thead>
<tr>
<th>Nombre</th>
<th>Color</th>
<th>Edad</th>
</tr>
</thead>
def index
default_order = "created_at"
case current_user.role
when User::Roles[:admin] # 1
default_order = "campo1"
when User::Roles[:other] # 2
default_order = "campo2"
else
default_order = "campon"
end