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 / giffify.sh
Last active August 29, 2015 14:24 — forked from rock3r/giffify.py
#!/bin/sh
# License for any modification to the original (linked below):
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Sebastiano Poggi wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
# ----------------------------------------------------------------------------
#
# Based upon http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
// Little background about unknown properties
var myObject = Ember.Object.create({name: 'hi'}); // a plain simple ember object
/*
all the properties defined on the object are known properties
so the property "name" is a known property for myObject,
but any other properties which are not defined on this object are unknown properties
*/
// age is an unknown property as we did not set "age" yet
myObject.get("age"); // => undefined