Skip to content

Instantly share code, notes, and snippets.

View savonarola's full-sized avatar
🏠
Working from home

Ilia Averianov savonarola

🏠
Working from home
View GitHub Profile
#!/usr/bin/env ruby
#
# Proof-of-Concept exploit for Rails Remote Code Execution (CVE-2013-0156)
#
# ## Advisory
#
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
#
# ## Caveats
#
@savonarola
savonarola / rspec-syntax-cheat-sheet.rb
Created April 9, 2012 18:45 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
module Models
module Connections
extend ActiveSupport::Concern
included do
class_attribute :using_database, :_database_config
end
module ClassMethods
xml_grep --text_only '//original_image' <(scrot -s /tmp/imgur.png && curl --form key=YOUR_IMGUR_KEY --form image=@/tmp/imgur.png 'http://imgur.com/api/upload.xml' -s) | xsel -i -b && notify-send 'Screenshot uploaded'
def inc(s)
pos = s.rindex /[0-8]/
nines = s.length - pos - 1
s[0, pos] + (s[pos].to_i + 1).to_s + "0" * nines
end
ns = gets.chomp
1.upto(ns.to_i) do
s = gets.chomp
len = s.length
def foo
bar
end
module Cart
def add(buyer, catalog, product_id, quantity)
raise ArgumentError unless user.kind_of?(Buyer)
raise ArgumentError unless catalog.kind_of?(Catalog)
# или через #respond_to?
product = catalog.find_product(product_id)
add_cart_items(quantity, CartItem.new(buyer,product))
end
end
1:32 savonarola@thnk:~/dev/ruby-perl>perl test_from_perl.pl
empty:
timethis 10000000: 5 wallclock secs ( 3.67 usr + 0.00 sys = 3.67 CPU) @ 2724795.64/s (n=10000000)
withdb:
timethis 10000: 3 wallclock secs ( 1.41 usr + 0.39 sys = 1.80 CPU) @ 5555.56/s (n=10000)
1:33 savonarola@thnk:~/dev/ruby-perl>ruby test_from_ruby.rb
user system total real
empty: 1.800000 0.000000 1.800000 ( 1.798274)
withdb: 1.620000 0.440000 2.060000 ( 3.355840)
require 'perl'
require 'benchmark'
n1 = 1000000;
n2 = 10000;
perl = Perl.new
perl.eval "use Foo; use Bar;"
Benchmark.bm(20) do |x|
#!/usr/bin/perl -w
use strict;
use Benchmark;
use Foo;
use Bar;
my $n1 = 10000000;
my $n2 = 10000;