Skip to content

Instantly share code, notes, and snippets.

Tilo tilo

  • Earth
Block or report user

Report or block tilo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tilo
tilo / schema_dumper_2_of_2.rb
Last active Feb 7, 2018
ActiveRecord Monkey Patch to make Rails 5 dump DB agnostic format (2 of 2)
View schema_dumper_2_of_2.rb
# config/initializers/active_record/connection_adapters/abstract/schema_dumper.rb
# DANGER, Will Robinson!!!
#
# This is a monkey patch for Rails 5.0 ONLY
#
if Rails.version !~ /^5.0/ # code taken from 5.0.6
puts "\n
--------------------------------------------------------------------------------
@tilo
tilo / schema_dumper_1_of_2.rb
Last active Feb 7, 2018
ActiveRecord Monkey Patch to make Rails 5 dump DB agnostic format (1 of 2)
View schema_dumper_1_of_2.rb
# config/initializers/active_record/schema_dumper.rb
#
# DANGER, Will Robinson!!!
#
# This is a monkey patch for Rails 5.0 ONLY
#
if Rails.version !~ /^5.0/ # code taken from 5.0.6
puts "\n
--------------------------------------------------------------------------------
View convert.rake
namespace :db do
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
@tilo
tilo / gist:85ce8bd382027d830ed1
Created May 12, 2014
Argument Error when using acts-as-taggable-on with Rails 4.1ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin13.0.2]
View gist:85ce8bd382027d830ed1
Rails 4.1.0
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin13.0.2]
acts-as-taggable-on versions 3.1.1 and
DB: PostgreSQL / PostGIS
```
t = MyModel.first
@tilo
tilo / hash_extensions.rb
Created Sep 24, 2012
Hash mix-in to add IndifferentAccess behavior without duplicating a given hash instance
View hash_extensions.rb
module Hash::Extensions
# Author: Tilo Sloboda , 2012-09-24
# Gist: https://gist.github.com/3778285
#
# Mix-In Module Hash::Extensions::IndifferentAccess
#
# Adds "Hash with Indifferent Access" behavior to an existing Hash
# without creating a copy of that Hash.
#
@tilo
tilo / prettify_json.rb
Created Sep 17, 2012
Ruby script to pretty print JSON on the command line (comes with Ruby's json Gem)
View prettify_json.rb
#!/usr/bin/env ruby
require 'json'
require 'fileutils'
include FileUtils
# Parses the argument array _args_, according to the pattern _s_, to
# retrieve the single character command line options from it. If _s_ is
# 'xy:' an option '-x' without an option argument is searched, and an
# option '-y foo' with an option argument ('foo').
@tilo
tilo / awesome_print.rb
Created Sep 12, 2012
awesome_print giving NameError: uninitialized constant BSON
View awesome_print.rb
# work-around a bug in awesome_print gem, after Mongoid is no longer using BSON, but Moped::BSON
# put this in your Rails project as: ./config/initializers/awesome_print.rb
BSON=Moped::BSON if defined?(AwesomePrint) # conditional, in case you don't add awesome_print in production
@tilo
tilo / process_csv_file.rb
Created Jul 13, 2012
Process CSV-like files as Arrays of Hashes; allow key-remapping, chunking, processing via optionally given block
View process_csv_file.rb
# NOTE:
# This was an initial proof-of-concept!
#
# Please use the Gem "smarter_csv" instead of using this no longer maintained code below.
#
# See also:
# * https://github.com/tilo/smarter_csv
# * http://www.unixgods.org/~tilo/Ruby/process_csv_as_hashes.html
#
# ---------------------------------------------------------------------------
@tilo
tilo / daily_collection.rb
Created Jun 16, 2012
Daily Collections with Mongoid 2.4
View daily_collection.rb
# Daily Collections With Mongoid 2.4
#
# Author: Tilo Sloboda, 2012-06-16
# Twitter: https://twitter.com/#!/tilosloboda
# GitHub: https://gist.github.com/tilo
# Gist: https://gist.github.com/2942627
#
# This can be useful if you need to re-import certain data every day
# and need to make sure that the latest daily collection is used in production
#
@tilo
tilo / rails_issue_5057.rb
Created Feb 16, 2012
Script for Rails Issue #5057
View rails_issue_5057.rb
gem 'rails', '3.2.1'
require 'active_record'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
You can’t perform that action at this time.