Skip to content

Instantly share code, notes, and snippets.

View johnnaegle's full-sized avatar
🐈
I'm here live, I'm not a cat

John Naegle johnnaegle

🐈
I'm here live, I'm not a cat
View GitHub Profile
@johnnaegle
johnnaegle / issue.rb
Last active August 29, 2015 14:15
rails enums
class Issue < ActiveRecord::Base
enum :status => {:open => 1, :closed => 2, :reopened => 3, :inprogress => 4}
end
for (var item in payload) {
result.push(payload[item]);
}
@johnnaegle
johnnaegle / bug.js
Created November 11, 2014 19:43
IE9 JS bug
var data = [2013,10,12,60];
var date = data.slice(0,3);
var payload = data.slice(3);
var result = [new Date(date[0], date[1], date[2])];
if (payload.length > 0) {
for (item in payload) {
result.push(payload[item]);
}
@johnnaegle
johnnaegle / monkey_patch_time_with_zone.rb
Created April 8, 2014 03:30
Monkey Patches ActiveSupport::TimeWithZone for Rails 4.0 to be backwards compatible with Rails 3.2
module ActiveSupport
class TimeWithZone
def as_json(options = nil)
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
xmlschema
else
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
end
end
end
@johnnaegle
johnnaegle / Time In Zone Bug.txt
Last active August 29, 2015 13:58
Really simple demonstration that Rails 4.0 has milliseconds in ActiveSupport::TimeInZone json output
> bundle exec rails c
[1] pry(main)> Time.now.in_time_zone.as_json
=> "2014-04-08T03:22:34.472Z"
@johnnaegle
johnnaegle / bug.rb
Created April 8, 2014 03:15
Demonstrates that ActiveSupport::TimeWithZone has milliseconds in Rails 4.0
gem 'activesupport', '4.0.4'
require 'active_support/time'
require 'active_support/time_with_zone'
require 'active_support/core_ext/date_time/zones.rb'
require 'minitest/autorun'
class UserTest < MiniTest::Unit::TestCase
def test_no_milliseconds
time = ActiveSupport::TimeWithZone.new(Time.now, Time.find_zone!('UTC'))
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.4'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
puts Post.new.comments.model
> Comment
class Comment < ActiveRecord::Base
belongs_to :post, :inverse_of=>:comments
scope :not_index, -> {where(:index => false)}
end
first = Post.create!(:name => "First")
first.comments.create!(:index => true)
first.comments.create!(:index => false)
first = Post.create!(:name => "First")
first.comments.create!(:index => true)
first.comments.create!(:index => false)
puts "first.comments.count: #{first.comments.count}"
puts "first.comments.model.count: #{first.comments.model.count}"
puts "first.comments.where(:index => false).count: #{first.comments.where(:index => false).count}"