Skip to content

Instantly share code, notes, and snippets.

View hernan's full-sized avatar

Hernan Fernandez hernan

  • Argentina
View GitHub Profile
@hernan
hernan / list_indexes_in_rails_console.rb
Created October 20, 2023 19:06 — forked from davygora/list_indexes_in_rails_console.rb
Get list of all indexes in rails console.
# rails console
ActiveRecord::Base.connection.tables.each do |table|
indexes = ActiveRecord::Base.connection.indexes(table)
if indexes.length > 0
puts "====> #{table} <===="
indexes.each do |index|
puts "----> #{index.name}"
end
puts "====> #{table} <===="
@hernan
hernan / sqlite_test_db_loader.rb
Created February 24, 2022 02:39 — forked from axehomeyg/sqlite_test_db_loader.rb
Rails 6 parallel minitest with sqlite3 :memory: databases.
#### evals the schema into the current process
class SqliteTestDbLoader
# assumes your schema is generated for MySQL
# tweak for Postgres!
MYSQL_REPLACEMENTS = {
/ENGINE=InnoDB DEFAULT CHARSET=[a-z0-9]*/ => '',
/, collation: "[^"]*"/ => ''
}
@hernan
hernan / active_admin.rb
Created November 26, 2020 02:39 — forked from francois-ferrandis/active_admin.rb
Customize the active admin layout
# config/initializers/active_admin.rb
# ...rest of the initializer here...
module AdminPageLayoutOverride
def build(*args)
# you can move the call to super at the end, if you wish
# to insert things at the begining of the page
super
@hernan
hernan / DefaultKeyBinding.dict
Created November 8, 2020 15:04 — forked from trusktr/DefaultKeyBinding.dict
My DefaultKeyBinding.dict for Mac OS X
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
or replace @ with ^ in this file.
Here is a rough cheatsheet for syntax.
Key Modifiers
@hernan
hernan / camelize.js
Created March 16, 2018 23:10 — forked from jpetitcolas/camelize.js
Camelize a string in Javascript. Example: camelize("hello_world") --> "HelloWorld"
/**
* Camelize a string, cutting the string by separator character.
* @param string Text to camelize
* @param string Word separator (underscore by default)
* @return string Camelized text
*/
function camelize(text, separator) {
// Assume separator is _ if no one has been provided.
if(typeof(separator) == "undefined") {
@hernan
hernan / carrier_wave.rb
Created April 19, 2016 22:57 — forked from gshaw/carrier_wave.rb
CarrierWave initialization file for testing with fixtures and support S3 in staging and production.
# NullStorage provider for CarrierWave for use in tests. Doesn't actually
# upload or store files but allows test to pass as if files were stored and
# the use of fixtures.
class NullStorage
attr_reader :uploader
def initialize(uploader)
@uploader = uploader
end
@hernan
hernan / Rakefile
Created March 17, 2016 15:23 — forked from schickling/Rakefile
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@hernan
hernan / yaml_to_json.rb
Created February 24, 2016 15:36 — forked from xiaohanyu/yaml_to_json.rb
convert yaml to json in ruby
require 'json'
require 'yaml'
input_filename = ARGV[0]
output_filename = input_filename.sub(/(yml|yaml)$/, 'json')
input_file = File.open(input_filename, 'r')
input_yml = input_file.read
input_file.close
@hernan
hernan / change_utf8_signature.rake
Created December 2, 2015 00:11
add utf8 signature to old ruby files
desc "Set the magic encoding comment everywhere to UTF-8"
task :source_encoding do
shebang = '\s*#!.*?(\n|\r\n)'
magic_regex = /\A(#{shebang})?\s*(#\W*(en)?coding:.*?$)/mi
magic_comment = '#-- encoding: UTF-8'
(Dir['script/**/**'] + Dir['**/**{.rb,.rake}']).each do |file_name|
next unless File.file?(file_name)
@hernan
hernan / isempty.js
Created November 14, 2015 15:14
Check for empty object
// http://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
//ecma 5+
Object.keys({}).length; // 0
// pre ecma 5
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;