Skip to content

Instantly share code, notes, and snippets.

View gazay's full-sized avatar
🌐

Alex Gaziev gazay

🌐
View GitHub Profile
@gazay
gazay / cache_helper.rb
Created December 28, 2011 04:20
Creating Fragment class for controller caching
# rails/actionpack/lib/action_view/cache_helper.rb
private
# TODO: Create an object that has caching read/write on it
def fragment_for(name = {}, options = nil, &block) #:nodoc:
if fragment = controller.find_fragment(name, options)
fragment.read
else
# VIEW TODO: Make #capture usable outside of ERB
# This dance is needed because Builder can't use capture
@gazay
gazay / gist:1520922
Created December 26, 2011 10:47
Marshaling problem
rails 3.1.1:
http://dl.dropbox.com/u/12274059/rails_issue311
rails 4.0.0beta:
http://dl.dropbox.com/u/12274059/rails_issue400beta
@gazay
gazay / ipv4_and_ipv6_regexp.rb
Created October 15, 2011 14:23
IPv4 and IPv6 regexp by jteeuven & Chetan Hanumantha
# IP v4 and v6 (with compression) validation regexp
# http://regexlib.com/REDetails.aspx?regexp_id=1000
# http://regexlib.com/REDetails.aspx?regexp_id=2685
VALID_IP = %r{
(^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$) | # ip v4
(^(
(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}) | # ip v6 not abbreviated
(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4}) | # ip v6 with double colon in the end
(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4}) | # - ip addresses v6