Skip to content

Instantly share code, notes, and snippets.

# Andres
def get_combinations(chars)
return [[]] if chars.empty?
(1..chars.length).map do |n|
get_combinations(chars.drop(n)).map{|ys| [chars.first(n).join] + ys}
end.flatten(1)
end
def get_polindromes(str)
combinations = get_combinations(str.chars)
class Crypto
attr_accessor :data, :salted_data, :key, :iv, :iv_key, :cryptor, :secret
def initialize(data)
@cryptior = FooCryptor.new
@key = ENV[:cryptokey]
@iv = ENV[:cryptoiv]
#!/usr/bin/env ruby
# Нужно сделать калькулятор
# функциям, кроме факториала можно передавать в виде аргументов Float, например 3.0 (числа с плавающей запятой пишутся через точку)
# все функции должны принимать два аргумента, кроме факториала - у него только один
class Calculator
@volonterx
volonterx / gist:dbd2ae6c3501fd5132c62f484463034e
Last active November 3, 2017 01:30
Unicorn vs Puma performance comparison (via ab)
ab -kl -n 100 -c 10 https:...
Server: 2 CPU, 4Gb RAM, SSD, Ubuntu 12.04 LTS, Ruby 2.2.4
################################################# unicorn 4.7 (Ruby 1.9.3-p362), 2 workers, pool 25
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 31 93.6 0 332
Processing: 1521 5008 956.9 4806 6889
@volonterx
volonterx / jquery_ujs.prompt.js.coffee
Last active March 14, 2016 11:02 — forked from korny/jquery_ujs.prompt.js.coffee
Simple prompt functionality for Rails / jQuery UJS, modelled after "confirm". Tested with Rails 4 (edge).
# Usage: link_to …, prompt: { message: 'Some message', default: 'default value', param: 'name of parameter' }
# The prompt will ask for "message" and use "default" as the default value.
# Unless user selects cancel, "param"=<new value> will be sent to the given path.
# Optionally, you can just use `prompt: "message"`.
$.rails.prompt = (message, defaultValue) ->
window.prompt message, defaultValue
$.rails.handlePrompt = (element) ->
config = element.data 'prompt'
@volonterx
volonterx / digital_ocean_setup.md
Created March 11, 2016 23:13 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

@volonterx
volonterx / devise_invitable.ru.yml
Last active September 16, 2021 21:55
Russian translations for devise_invitable. Completely adheres to the format of the generated devise_invitable.en.yml as of 2.0.5.
# Additional translations at https://github.com/scambra/devise_invitable/wiki/I18n
ru:
devise:
failure:
invited: 'У вас есть непринятое приглашение, подтвердите его чтобы продолжить создание аккаунта.'
invitations:
send_instructions: 'Письмо с приглашением было отправлено на %{email}.'
invitation_token_invalid: 'Неверный токен приглашения.'
updated: 'Ваш пароль успешно сохранен. Вы вошли в систему.'
#http://www.codewars.com/dojo/katas/5235c913397cbf2508000048/discuss/ruby
class Calculator
def evaluate(string)
groups_of_operators = [["/", "*"], ["-", "+"]]
arr = string.split
groups_of_operators.each do |group|
(0..arr.size).each do |i|
if group.include?(arr[i+1])
arr[i+1] = arr[i].to_i.send(arr[i+1], arr[i+2].to_i)
arr.delete_at(i+2)