Skip to content

Instantly share code, notes, and snippets.

View vessi's full-sized avatar
🔭
watching stars

Mikhail Bortnyk vessi

🔭
watching stars
  • Ukraine, Kyiv
  • 18:17 (UTC +03:00)
View GitHub Profile
class Z
def call_some_method arg
puts arg
end
def yoba
:yobamethod
end
def test
@vessi
vessi / threads_inner_join.rb
Created February 21, 2012 06:49
Threads creation with outer join (working)
# THIS IS WRONG!
start_time = Time.new
10.times do
t = Thread.new do |th|
sec = rand(1..5)
puts "Run for #{sec} s"
sleep(sec)
#th.join #first case
puts "slept"
%p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque id leo commodo libero commodo ornare sed eget libero. Etiam lacinia urna id augue fringilla mollis sed ut odio. Aliquam malesuada
%b tellus
ut velit lobortis condimentum. Vestibulum nec purus ut elit gravida aliquet. In feugiat orci tortor. Suspendisse potenti. Aenean lacinia ornare urna id dictum. Nullam hendrerit cursus nibh eget pharetra. Cras rhoncus imperdiet augue, at porta neque euismod sed. Nam fermentum felis eu tortor sollicitudin hendrerit eget volutpat libero. Proin et nisl vel massa rhoncus semper. Maecenas volutpat sodales odio sit amet tristique.
@vessi
vessi / array_or.rb
Created May 10, 2012 20:39
benchmark for found array "or" sum
require 'benchmark'
GC.disable
@array = []
@array_size = 3000000
@iterations = 100
def prepopulate_array(mode)
@array = Array.new(@array_size, false)
@vessi
vessi / select.html.erb
Created May 15, 2012 12:31
usage of array for select
<select name="name" id="id">
<% %w(one two three).each_with_index do |option, index| %>
<option value="<%= index %>"><%= option %></option>
<% end %>
</select>
@vessi
vessi / address.rb
Created July 18, 2012 12:33
illustration for Law of Demeter for my blog
class Address < ActiveRecord::Base
attr_accessible :country, :city, :street, :building
belongs_to :user
end
@vessi
vessi / widget.coffee.js
Created August 4, 2012 22:29
coffeescript simple widget
window.Widget =
init: ->
$('*[data-widget]:not(*[data-widget-initialized])').each (_, container) ->
element = $(container)
element.attr('data-widget-initialized', 'true')
klass = window[element.data('widget')]
new klass(element)
$ ->
Widget.init()
@vessi
vessi / routes.rb
Created August 16, 2012 13:26
modular routes
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval File.read(Rails.root.join "config/routes#{@scope[:path]}", "#{routes_name}.rb")
end
end
@vessi
vessi / gist:3746132
Created September 18, 2012 21:48
something unuseful
# somewhere in controller
def update
@group = Group.find(params[:id])
if @group.update_with_user(params[:group], params[:user])
redirect_to :index
else
render :edit
end
@vessi
vessi / define_method.rb
Created September 19, 2012 08:31
metaprogramming sample for rubygarage
class A
attr_accessor :method_name
def initialize(method_name = "test")
@method_name = method_name
end
def declare_methods(&block)
self.class.send(:define_method, @method_name, &block)
end