Skip to content

Instantly share code, notes, and snippets.

# mv prefix_filename.txt filename.txt
find -type f | sed 's/prefix_\(.\+\)/mv \0 \1/' | sh
count = 1
сount = 2
count # => 1
local_variables # => [:o_0, :сount, :count, :_]
...
private
def use_dsl(&block)
proxy = Proxy.new(self, @api)
proxy.call(&block)
end
end
class Proxy < BasicObject
Date.current.beginning_of_year + 0xFF.days # => Sun, 13 Sep 2015
# 0001011000101110001011100000111011001110010111001111010011110100
# 1010011001110110011101001110111010010110110101101001011000001110
# 1010011000100110100101101000011001110100111101100100111011100110
# 1111010011101110100101101101011010010110111101000000101001001110
# 1111011011100110010011101000011010110110101101101010011001001110
# 110011101110010011111010001000101000011010011110
@scaint
scaint / source.rb
Created August 14, 2015 14:54
wtf Rails?
hash1 = {"x" => 1}
xml = hash1.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <x type=\"integer\">1</x>\n</hash>\n"
hash2 = Hash.from_xml(xml) # => {"hash"=>{"x"=>1}}
hash1 == hash2 # => false
Date.today # => Mon, 10 Aug 2015
Date.current # => Sun, 09 Aug 2015
# File activesupport/lib/active_support/core_ext/date_and_time/calculations.rb, line 24
# def today?
# to_date == ::Date.current
# end
Date.today.today? # => false
Object.class_eval { def self.private; Object; end }
def MyClass
private
def some_method
end
end
MyClass.private_instance_methods.include? :some_method # => false
public.class_eval { def say_hello; 'Hello!'; end }
:ruby.say_hello # => "Hello!"
input_array = [1, 2, 1, 4, 1.0, 1r]
require 'set'
Set.new(input_array).to_a
# => [1, 2, 4, 1.0, (1/1)]
unique_elements = []
input_array.each { |el| unique_elements << el unless unique_elements.include?(el) }
unique_elements
# => [1, 2, 4]
@scaint
scaint / gist:005c44ae7e06705de1b2
Created March 29, 2015 16:36
How to install specified Rust build
# List of available dates you can see at https://static.rust-lang.org/dist/
curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --date="2015-03-25"