Skip to content

Instantly share code, notes, and snippets.

View entity1991's full-sized avatar
🏠
Working from home

Ruslan Kuzma entity1991

🏠
Working from home
View GitHub Profile
ActiveAdmin.register Project do
# Don't forget to add the image attribute (here thumbnails) to permitted_params
controller do
def permitted_params
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list]
end
end
form do |f|
# It extends activeadmin to show pretty boolean values
#
# config/initializers/active_admin.rb
module ActiveAdmin
module Views
class TableFor
def bool_column(attribute)
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe }
end
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
@entity1991
entity1991 / gravatar.rb
Last active August 29, 2015 14:05
Fetching gravatar by user email
def gravatar_url(size)
gravatar_id = Digest::MD5.hexdigest(email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}"
end
# Usage
# DJ config
require Rails.root.join('lib', 'dj_plugin.rb')
Delayed::Worker.plugins << Delayed::Plugins::EmailNotify
# lib/dj_plugin.rb
require 'exception_notification'
@entity1991
entity1991 / memory_usage_monitor.rb
Last active April 2, 2018 13:09
Memory usage monitor
# Usage:
#
# peak_memory = track_memory do
# 1000000.times { |i| puts i }
# end
#
# puts peak_memory
# -> 845073
require 'thread'
Plugboard = Hash[*('A'..'Z').to_a.shuffle.first(20)]
Plugboard.merge!(Plugboard.invert)
Plugboard.default_proc = proc { |hash, key| key }
def build_a_rotor
Hash[('A'..'Z').zip(('A'..'Z').to_a.shuffle)]
end
Rotor_1, Rotor_2, Rotor_3 = build_a_rotor, build_a_rotor, build_a_rotor
@entity1991
entity1991 / levenshteins_bm.rb
Last active April 2, 2018 13:07
Levenshtein algorithm libraries benchmark
require 'benchmark'
# Levenshtein algorithm written in pure ruby.
# https://github.com/threedaymonk/text
require 'text'
# Levenshtein algorithm in C++ with ruby wrapper
# https://github.com/dbalatero/levenshtein-ffi
require 'levenshtein'
@entity1991
entity1991 / pre-commit
Created April 3, 2018 15:01 — forked from gmodarelli/pre-commit
RuboCop with git pre-commit
#!/bin/sh
#
# Check for ruby style errors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
if git rev-parse --verify HEAD >/dev/null 2>&1
@entity1991
entity1991 / jsTasks.js
Created February 26, 2020 21:50
JS tasks
function sum(from, to) {
let total = 0
for (let i = from; i <= to; i += 1) {
total += i
}
return total
}