Skip to content

Instantly share code, notes, and snippets.

View dabit's full-sized avatar

David Padilla dabit

View GitHub Profile
@dabit
dabit / ruby.rb
Created April 15, 2015 20:29
private protected
class Klass
def public_method
end
private
def private_method1
end
def private_method2
@dabit
dabit / alias.sh
Last active August 29, 2015 14:17
Elasticsearch quick reindex post
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "add" : { "index" : "articles-1", "alias" : "articles" } }
]
}'
@dabit
dabit / script.rb
Last active August 29, 2015 14:16
.last sort conundrum
# Activate the gem you are reporting the issue against.
# gem install activerecord -v '3.2.19'
gem 'activerecord', '3.2.19'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
@dabit
dabit / gist:b640b8f5d0bcdd039265
Last active August 29, 2015 14:06
Create Brazilian States for Spree
brazil = Spree::Country.where(name: "Brazil").last
Spree::State.create!(
[{name: "Acre", abbr: "AC", country: brazil},
{name: "Alagoas", abbr: "AL", country: brazil},
{name: "Amapá", abbr: "AP", country: brazil},
{name: "Amazonas", abbr: "AM", country: brazil},
{name: "Bahia", abbr: "BA", country: brazil},
{name: "Ceará", abbr: "CE", country: brazil},
{name: "Espírito Santo", abbr: "ES", country: brazil},
@dabit
dabit / sort.rb
Created March 21, 2014 03:11
Hermosillo.rb
#
# Vayan a MagmaConf http://www.magmaconf.com
#
require 'minitest/autorun'
require 'minitest/pride'
class Animal
attr_accessor :clase
@dabit
dabit / optimistic.rb
Last active August 29, 2015 13:56
ActiveRecord Optimistic Locking
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :orders do |t|
t.integer :total
t.string :lock_version
end
@dabit
dabit / script.sh
Created August 14, 2013 22:26
Global ignore .DS_Store files
echo ".DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile '~/.gitignore_global'
@dabit
dabit / inflector.rb
Last active December 18, 2015 16:59
class Inflector
def self.pluralize(singular)
(singular == "country") ? "countries" : "#{singular}s"
end
end
@dabit
dabit / Gemfile
Last active December 17, 2015 21:39
AASC Example
source "https://rubygems.org"
gem "acts_as_shopping_cart"
gem "sqlite3"
@dabit
dabit / hash_table.rb
Last active May 16, 2023 16:57
Code example for my blogpost Hash lookup in Ruby, why is it so fast?
require 'benchmark'
#
# Code example for my blogpost
#
# Hash lookup in Ruby, why is it so fast?
#
#
# Struct used to store Hash Entries