Skip to content

Instantly share code, notes, and snippets.

View EdgarOrtegaRamirez's full-sized avatar
📝
​Learning!

Edgar Ortega EdgarOrtegaRamirez

📝
​Learning!
View GitHub Profile
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / import_sql_from_console
Last active December 18, 2015 13:49
Import SQL file from MySQL Command Line
use database_name;
source path/to/file.sql;
1. Install and update upstream
//Add remote upstream
git remote add upstream SSH_REMOTE_URI
//Update the new remote that was added
git fetch upstream
//Update your current master with remote upstream/master (the --rebase flag MUST be with the pull action)
git pull --rebase upstream master
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / gist:5835943
Created June 22, 2013 05:06
[Sublime Text] trim trailing spaces on save
"trim_trailing_white_space_on_save": true
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / gist:6141156
Created August 2, 2013 16:13
[Rails] fields_for inside fields_for
<%= fields_for @tour do |tour_fields| %>
<%= tour_fields.fields_for :dispatches, @dispatches do |dispatch_fields| %>
<tr>
<td><%= if dispatch_fields.object.published? then "Published"; elsif dispatch_fields.object.new_record? then "undefined"; else "Draft"; end%></td>
<td><%= dispatch_fields.object.dispatch_date %></td>
<td><%= dispatch_fields.object.venue %></td>
<td><%= dispatch_fields.object.address%></td>
<div class="dispatchFields">
<%= dispatch_fields.hidden_field :id, value: dispatch_fields.object.id unless dispatch_fields.object.id.nil? %>
<%= dispatch_fields.hidden_field :artist_id, value: current_artist.id %>
class Photo < ActiveRecord::Base
module Statues
QUEUED = 'queued'
NEW = 'new'
def self.values
constants.map(&method(:const_get))
end
# you can define more special methods as you wanted for Statues
end
# config/routes.rb
resources :documents do
resources :versions, controller: "documents/versions" do
post :restore, on: :member
end
resource :lock, controller: "documents/locks"
end
# Hides Draper decorator inside the model and lazily decorates resources
#
# https://gist.github.com/firedev/7a82059b30a2157d4c56
#
# model.rb:
# include Decorated
#
# Just make sure there are no overlapping method names in ModelDecorator
module Decorated
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / migration.rb
Created May 23, 2015 18:27
Users - Followers - Following
class CreateRelations < ActiveRecord::Migration
def change
create_table :relations do |t|
t.references :user, index: true, foreign_key: true
t.integer :friend_id, index: true
t.timestamps null: false
end
end
end
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / brew.sh
Last active March 8, 2016 14:16
Update and Clean Up Brew
brew update && brew upgrade --all && brew cleanup && brew prune
def gen(nums, digit)
result = []
nums.each_with_index do |num, i|
slice = nums[i, digit]
tmp = slice.concat(nums[i + digit])
result.push(tmp)
end
result
end
gen([0,1,2],1)