Skip to content

Instantly share code, notes, and snippets.

@sgrif
sgrif / patch-Zend-Zend.m4.diff
Created April 27, 2012 02:35
Sevence patch 1
--- Zend/Zend.m4.original 2011-07-12 21:43:51.000000000 -0600
+++ Zend/Zend.m4 2011-07-12 22:57:34.000000000 -0600
@@ -104,6 +104,14 @@
AC_CHECK_FUNCS(finite isfinite isinf isnan)
+dnl sevence...
+dnl
+dnl Floating point environment control
+dnl
@sgrif
sgrif / gist:7574451
Created November 21, 2013 01:23
Z Combinator in elixir
z = fn
f -> fn
x -> f.(fn y -> x.(x).(y) end)
end.(fn
x -> f.(fn y -> x.(x).(y) end)
end)
end
add_squares = z.(fn
f -> fn
class THREE.BoneHelper extends THREE.Object3D
constructor: (@bone, @size) ->
super()
@size ?= 1
cubeGeometry = new THREE.CubeGeometry(@size, @size, @size)
cubeMaterial = new THREE.MeshBasicMaterial()
@cube = new THREE.Mesh(cubeGeometry, cubeMaterial)
@cube.matrixAutoUpdate = false
@sgrif
sgrif / render.hs
Last active August 29, 2015 14:00
class Renderable a where
render :: a -> IO ()
newtype Rectangle = Rectangle { width :: Double, height :: Double }
instance Renderable Rectangle where
render = undefined
newtype Circle = Circle { radius :: Double }
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
index 1877869..57f57b6 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -32,7 +32,7 @@ module ActiveRecord
if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
method_body, line = <<-EOV, __LINE__ + 1
def #{attr_name}=(time)
- time_with_zone = time.respond_to?(:in_time_zone) ? time.in_time_zone : nil
+ time_with_zone = convert_value_to_time_zone(time)
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index f2fbd5a..5e4e00b 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -13,101 +13,36 @@ module ActiveRecord
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
end
- attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale, :default_function
- attr_accessor :primary, :coder
@sgrif
sgrif / perf.rb
Created June 12, 2014 16:07
Benchmark used for HABTM performance comparison
require_relative '../load_paths'
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
class Book < ActiveRecord::Base
has_and_belongs_to_many :genres
has_many :genre_memberships
has_many :genres2, through: :genre_memberships, source: :genre
end
@sgrif
sgrif / serialization.diff
Created June 13, 2014 20:25
Serialized attributes compared to 4-1-stable
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index 53a9c87..cec50f6 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -50,150 +50,21 @@ module ActiveRecord
# serialize :preferences, Hash
# end
def serialize(attr_name, class_name_or_coder = Object)
- include Behavior
-
@sgrif
sgrif / tztest.rb
Created June 14, 2014 13:42
Test Time Zone
require_relative '../load_paths'
require 'active_record'
require 'active_support/all'
Time.zone = ActiveSupport::TimeZone['Central Time (US & Canada)']
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection(adapter: :sqlite3, database: ':memory:')
class MyModel < ActiveRecord::Base
class User < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :user, counter_cache: true
end
user = User.create
user.posts_count # => 0