Alexey Gaziev gazay

View raw
1
"require 'spec_helper'\n\ndescribe 't34' do\n let(:target) {\n\"class X\n def test_method(arg1)\n end\nend # X\"\n }\n\n let(:target2) {\n\"class X\n def test_method(xxx, arg2)\n end\nend # X\"\n }\n\n let(:source) {\n\"class X\n def test_method(arg1, arg2)\n end\nend\"\n }\n\n let(:rewriter) {\n T34::Rewriter.new source\n }\n\n it 'finds methods' do\n expect(rewriter.methods(:test_method)).to be_kind_of Array\n end\n\n it 'finds method nodes' do\n expect(rewriter.methods(:test_method).map(&:class).compact).to eq [T34::Rewriter::API::MethodNode]\n end\n\n it 'manipulates methods' do\n res = rewriter.methods(:test_method) do |method_node|\n method_node.args = method_node.args[0...-1]\n end\n expect(res[0].args.size).to eq 1\n end\n\n it 'manipulates arguments by name' do\n res = rewriter.methods(:test_method) do |method_node|\n method_node.args = method_node.args.select { |it| it.name != 'arg2' }\n end\n expect(res[0].args.size).to eq 1\n expect(rewr
View helper.rb
1 2 3 4 5 6 7 8 9 10
require 'fileutils'
 
class Helper
 
attr_accessor :dir, :temp_dir
attr_reader :template_path, :original_dir
 
def initialize(dir = nil)
@template_path = File.expand_path('../../app_template', __FILE__)
@original_dir = FileUtils.pwd
View client
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env ruby
 
client_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'proxy'))
$LOAD_PATH.unshift(client_dir) unless $LOAD_PATH.include?(client_dir)
require 'client'
 
# Get parameters and start the server
if ARGV.size == 2
port, proxy = ARGV
port = port.to_i
View proxy.rb
1 2 3 4 5 6 7 8 9 10
# Based on https://gist.github.com/74107 by # Copyright (C) 2009 Torsten Becker <torsten.becker@gmail.com>
#
# Rewrited by gazay
 
require 'socket'
require 'uri'
 
class Proxy
 
attr_accessor :socket
View gist:2629683
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# implementation of Range#=== in 1.8.7 - it was the same method as Range#include?:
<<-EOS
static VALUE
range_include(range, val)
VALUE range, val;
{
VALUE beg, end;
 
beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end);
static VALUE
range_include(range, val)
VALUE range, val;
{
VALUE beg, end;
 
beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end);
View gist:2215244
1 2 3 4 5 6 7 8 9
#!/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
View cache_helper.rb
1 2 3 4 5 6 7 8 9 10
# 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
View gist:1520922
1 2 3 4 5
rails 3.1.1:
http://dl.dropbox.com/u/12274059/rails_issue311
 
rails 4.0.0beta:
http://dl.dropbox.com/u/12274059/rails_issue400beta
View ipv4_and_ipv6_regexp.rb
1 2 3 4 5 6 7 8 9 10
# 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
Something went wrong with that request. Please try again.