This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
-------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
-------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# | |
# --------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'rails', '3.2.1' | |
require 'active_record' | |
puts "Active Record #{ActiveRecord::VERSION::STRING}" | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlite3', | |
:database => ':memory:' | |
) |