This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails 3.1.1: | |
http://dl.dropbox.com/u/12274059/rails_issue311 | |
rails 4.0.0beta: | |
http://dl.dropbox.com/u/12274059/rails_issue400beta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random (newStdGen, randomR) | |
import Gimlh | |
import Data.List.Split (splitOn) | |
import Data.List (intercalate) | |
import Control.Monad.State | |
main = putStrLn $ runFaker $ do | |
n <- name | |
return $ unwords ["Hello", "my", "name", "is", n] |
OlderNewer