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
# /etc/init/sidekiq.conf - Sidekiq config | |
# This example config should work with Ubuntu 12.04+. It | |
# allows you to manage multiple Sidekiq instances with | |
# Upstart, Ubuntu's native service management tool. | |
# | |
# See workers.conf for how to manage all Sidekiq instances at once. | |
# | |
# Save this config as /etc/init/sidekiq.conf then mange sidekiq with: | |
# sudo start sidekiq index=0 | |
# sudo stop sidekiq index=0 |
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
print "Enter an integer number to be calculated as factorial: " | |
Integer(gets) rescue print "Hey, that's not an integer! Enter an integer, please: " | |
n = gets.to_i | |
def factorial n | |
n > 1 ? n * factorial(n - 1) : 1 | |
end | |
puts "Factorial of number #{n} is #{factorial(n)}" |
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
def str_in_lines(str, x) | |
word_break_indices = [] | |
str.to_enum(:scan,/\b/).map do |m,| | |
word_break_indices << $`.size | |
end | |
perfect_split_indices = (0..str.length).step(str.length/x).to_a | |
actual_split_indices = perfect_split_indices.map{ |si| word_break_indices.min_by{ |wbi| (wbi - si).abs } } | |
actual_split_indices.push(str.length) unless actual_split_indices.last == str.length | |
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
u = User.new | |
u.valid? == false | |
u.save(validate: false) | |
params = { dont_validate_user_ids: true, user_ids: [1] } | |
UserGroup.create(params) | |
User.first | |
=> #<User id: 1, name: nil, user_group_id: 1, created_at: "2015-04-15 12:37:58", updated_at: "2015-04-15 12:37:58"> |
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
def act(&block) | |
timeout = Time.now + 10 | |
work = Thread.new { block.call } | |
while Time.now < timeout && work.alive? do | |
sleep(0.1) | |
end | |
if work.alive? | |
puts "hit timeout" |
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
irb(main):006:0> Benchmark.measure { 100_000.times { [1, 2, 2, 3, 3, 3].each_with_object(Hash.new{ |x,k| x[k] = 0 }){ |x,s| s[x] += 1 }.max_by{ |k,v| v }[0] } } | |
=> #<Benchmark::Tms:0x007fc3e180b108 @label="", @real=0.899188, @cstime=0.0, @cutime=0.0, @stime=0.010000000000000009, @utime=0.8799999999999999, @total=0.8899999999999999> | |
irb(main):007:0> Benchmark.measure { 100_000.times { [1, 2, 2, 3, 3, 3].group_by{|e| e}.values.max_by(&:size).first } } | |
=> #<Benchmark::Tms:0x007fc3dffbe7d0 @label="", @real=0.523452, @cstime=0.0, @cutime=0.0, @stime=0.010000000000000009, @utime=0.5099999999999998, @total=0.5199999999999998> |
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 | |
# encoding: utf-8 | |
require 'savon' | |
require 'csv' | |
startDate = Date.new(2004, 01, 01) | |
stopDate = Date.today | |
csvHeaders = ['numar', 'numar_vechi', 'data', 'institutie', 'departament', | |
'categorie_caz', 'stadiu_procesual', 'obiect', 'data_modificare','nume','calitate_parte','solutie'] |
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
================================================================================ | |
Chepstow (soft) - 13:50 (stake: [0.02, 1, 0.4981700000000018]) | |
Horse Adj Unadj %ile Notes | |
------------------------------------------------------------------------- | |
Cruising Bye 70.60318 51.74106 58.47849 (24.8f), $0$ | |
Always Bold 71.10135 49.85184 76.03137 (24.82f), $0$ | |
Donapollo 73.63729 52.82733 42.64654 (23.35f), $0$ | |
Wayward Frolic 73.91475 52.64498 41.71131 (22.04f), $0$ | |
Cyrien Star 74.9877 49.1907 79.01786 (25.5f), $0$ | |
Paddy The Oscar 75.87846 51.70213 60.39574 (24.67f), $0$ |
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
LEVELS = [:major, :minor, :patch] | |
def version | |
@version ||= begin | |
v = `git describe --always --tags` | |
{}.tap do |h| | |
h[:major], h[:minor], h[:patch], h[:rev], h[:rev_hash] = v[1..-1].split(/[.-]/) | |
end | |
end | |
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
class ApplicationController < ActionController::Base | |
end | |
class SharedController < ApplicationController | |
before_action :foo | |
before_action :bar | |
def foo | |
#stub | |
end |