Skip to content

Instantly share code, notes, and snippets.

View werner's full-sized avatar
🏠
Working from home

Werner Echezuría werner

🏠
Working from home
View GitHub Profile
@werner
werner / macro_borrowing_problem.rs
Created July 26, 2017 13:46
Macro borrowing problem
macro_rules! get_body_as {
($structure:ty, $req:expr, $error_fn:ident) => {
{
let body = get_body!($req, $error_fn);
let raw_structure = borrow_function(&body);
match raw_structure {
Ok(structure) => structure,
Err(error) => "Error"
@werner
werner / shortcuts.rb
Created August 5, 2015 19:54
Ruby on Rails personal shortcuts
#Remove console logs
ActiveRecord::Base.logger.level = 1
#Create a csv file
require "csv"
CSV.open("path/file_to_create.csv", "wb") { |csv|
csv << ["Field 1", "Field 2", "Field 3"]; records.each {|t| csv << [t.field1, t.field2, t.field3.count] }
}
#Remove duplicates
Rails as it has never been before :)
Rails 3 AntiPatterns, Useful snippets and Recommended Refactoring.
Note: Some of them are collected from different online resources/posts/blogs with some tweaks.
@werner
werner / habtm_callbacks.rb
Created July 2, 2014 16:57
Habtm and before create callback
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@werner
werner / habtm_bug.rb
Created July 1, 2014 18:47
Habtm and foreign key Bug
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.2'
#For Heroku
gem 'pg'