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
@entity1991
entity1991 / figma-toggle-sidebars.js
Last active July 7, 2021 11:43
Tampermonkey - toggle sidebars on Figma
// ==UserScript==
// @name Figma / toggle sidebars
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Ability to toggle sidebars on figma for better usability
// @author Ruslan Kuzma
// @match https://www.figma.com/file*
// @icon https://www.google.com/s2/favicons?domain=figma.com
// @grant none
// ==/UserScript==
@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
}
@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 / 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'
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 / 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'
# 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 / 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
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
# 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] ? '&#x2714;'.html_safe : '&#x2717;'.html_safe }
end