This file contains hidden or 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
# 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" |
This file contains hidden or 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
%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. |
This file contains hidden or 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 'benchmark' | |
GC.disable | |
@array = [] | |
@array_size = 3000000 | |
@iterations = 100 | |
def prepopulate_array(mode) | |
@array = Array.new(@array_size, false) |
This file contains hidden or 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
<select name="name" id="id"> | |
<% %w(one two three).each_with_index do |option, index| %> | |
<option value="<%= index %>"><%= option %></option> | |
<% end %> | |
</select> |
This file contains hidden or 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
class Address < ActiveRecord::Base | |
attr_accessible :country, :city, :street, :building | |
belongs_to :user | |
end |
This file contains hidden or 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
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() |
This file contains hidden or 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
class ActionDispatch::Routing::Mapper | |
def draw(routes_name) | |
instance_eval File.read(Rails.root.join "config/routes#{@scope[:path]}", "#{routes_name}.rb") | |
end | |
end |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
# два игрока бросают кости | |
# первый бросает 20 раз 6-гранный кубик | |
# второй бросает 6 раз 20-гранный кубик | |
# следовательно, у первого при наименее благоприятном исходе сумма очков = 20, при наиболее = 120 | |
# у второго - при наименее благоприятном исходе сумма очков = 6, при наиболее = 120 | |
# код для перебора | |
counter = 0; p1_counter = 0; p2_counter = 0; | |
(20..120).to_a.each do |first_sum| | |
(6..120).to_a.each do |second_sum| | |
counter += 1 |
OlderNewer