Skip to content

Instantly share code, notes, and snippets.

View gazay's full-sized avatar
🌐

Alex Gaziev gazay

🌐
View GitHub Profile
#!/usr/bin/env ruby
require 'epath'
bom = "\xEF\xBB\xBF".force_encoding('binary')
Path.glob('**/*.rb') do |file|
next if file.binread(3) == bom
previous = file.binread
file.write bom + previous
end
@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
@gazay
gazay / THE_PROBLEM.md
Last active August 29, 2015 14:19
Strange behavior of Module#attr_reader

If run this with ruby test.rb with MRI, Jruby, and in MRI irb: true

If run in Jruby irb: false

I think it can be related in following failing rails tests, but I'm not sure:

  3) Error:
AttrInternalTest#test_naming_format:
NoMethodError: private method `foo=' called for #<#<Class:0x64ea9235>:0x6af12899>
___________________1__________________
3:activesupport:[master ✗]$ bundle exec rake test --trace
uri:classloader:/jruby/kernel/kernel.rb:28: warning: unsupported exec option: close_others
** Invoke test (first_time)
** Execute test
/Users/alex/code/opensource/jruby/bin/jruby -w -I"lib:test" --dev -I"/Users/alex/.gem/jruby/2.2.2/gems/rake-10.4.2/lib" "/Users/alex/.gem/jruby/2.2.2/gems/rake-10.4.2/lib/rake/rake_test_loader.rb" "test/**/*_test.rb"
/Users/alex/.gem/jruby/2.2.2/gems/minitest-5.3.3/lib/minitest.rb:46: warning: (...) interpreted as grouped expression
uri:classloader:/jruby/bigdecimal.rb:1: warning: loading in progress, circular require considered harmful - bigdecimal.jar
require at org/jruby/RubyKernel.java:966
0:activesupport:[no_fork_issue]$ jruby -v
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-04-21 891f12e Java HotSpot(TM) 64-Bit Server VM 25.31-b07 on 1.8.0_31-b13 +jit [darwin-x86_64]
0:activesupport:[no_fork_issue]$ irb
irb(main):001:0> IO.popen({'PATH' => 'some'}, 'echo $PATH').read
=> "some\n"
[ERROR] Failed to disable echo
java.io.IOException: Cannot run program "sh": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:485)
0:activesupport:[no_fork_issue]$ jruby -v
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-04-21 891f12e Java HotSpot(TM) 64-Bit Server VM 25.31-b07 on 1.8.0_31-b13 +jit [darwin-x86_64]
0:activesupport:[no_fork_issue]$ jruby -S gem install bundler
RuntimeError:
you might need to reinstall the gem which depends on the missing jar or in case there is Jars.lock then JARS_RESOLVE=true will install the missing jars
no such file to load -- org/yaml/snakeyaml/1.14/snakeyaml-1.14 (LoadError)
do_require at /Users/alex/.rubies/jruby-9.0.0.0-SNAPSHOT/lib/ruby/stdlib/jar_dependencies.rb:261
require_jar at /Users/alex/.rubies/jruby-9.0.0.0-SNAPSHOT/lib/ruby/stdlib/jar_dependencies.rb:207
@gazay
gazay / reproduction_steps.rb
Created March 25, 2015 14:51
nokogiri - libxml segmentation fault
require 'libxml'
require 'nokogiri'
loop do
nodes = Nokogiri::HTML::DocumentFragment.parse 'z<', 'utf-8'
node = nodes.children.first
node.replace node.content
end
@gazay
gazay / build
Created January 31, 2015 06:42
Linker error with android-haskell-activity
androidbuilder@aa3718480a89:~/android-haskell-activity$ arm-linux-androideabi-cabal build --verbose=3
Using internal setup method with build-type Simple and args:
["build","--verbose=3","--builddir=dist","--jobs=8","--with-gcc=/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gcc","--with-ghc=/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-unknown-linux-androideabi-ghc","--with-ghc-pkg=/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-unknown-linux-androideabi-ghc-pkg","--with-hsc2hs=/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-unknown-linux-androideabi-hsc2hs","--with-ld=/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-ld","--with-strip=/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-strip","--hsc2hs-option=--cross-compile"]
("/home/androidbuilder/.ghc/android-14/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gcc",["