Skip to content

Instantly share code, notes, and snippets.

View ndemianc's full-sized avatar
💪
Every day!

Sergii Demianchuk ndemianc

💪
Every day!
View GitHub Profile
@ndemianc
ndemianc / ruby_prof_sidekiq.rb
Created June 29, 2018 21:41
How to use Ruby Prof to profile Sidekiq Worker
# How to use Ruby Prof to profile Sidekiq Worker
require 'ruby-prof'
result = RubyProf.profile do
#Code to analyse in a method
EsIndexWorker.new.perform
end
@ndemianc
ndemianc / dig_vs_fetch.rb
Last active June 25, 2018 21:17
Hash#dig vs Hash#fetch
require "benchmark"
h = { a: { b: { c: { d: { e: "foo" } } } } }
n = 50_000
Benchmark.bmbm(7) do |x|
x.report "Hash#dig" do
n.times do ; h.dig(:a, :b, :c, :d, :e); end
end

Keybase proof

I hereby claim:

  • I am ndemianc on github.
  • I am ndemianc (https://keybase.io/ndemianc) on keybase.
  • I have a public key ASBLihFG_HQlBwIv69F1pQ3HTr3VgnpAtkSuCboGTeAARQo

To claim this, I am signing this object:

@ndemianc
ndemianc / docker_container_stop.sh
Last active March 12, 2018 21:52
Docker: stop and remove all docker containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@ndemianc
ndemianc / benchmark.rb
Last active December 14, 2017 14:10
Benchmark Array#to_h and Enumerable#inject
require 'benchmark'
array = Array.new(1_000_000, { id: 'key' })
values = ['.p12', '.pfx']
Benchmark.bmbm(7) do |bm|
bm.report('to_h') do
array.map do |prop|
[
prop[:id],
@ndemianc
ndemianc / redis.py
Last active January 12, 2017 18:14
import redis
r = redis.StrictRedis(host='localhost', port=6379, decode_responses=True, password='123')
r.hset('candidate:1', 'name', 'Mary Sue')
r.hset('candidate:1', 'position', 'super tester')
r.hget('candidate:1', 'name')
m = r.hgetall('candidate:1')
print(m['name'])
@ndemianc
ndemianc / process.ex
Last active January 5, 2017 22:57
Small linked task, that can run on the multicore processor, and save a state inside Map like key-value store in Elixir
defmodule Project do
@moduledoc """
This module includes example code of the Elixir linked tasks based on the Elixir linked processes.
"""
@doc """
Create new task.
Returns `{:ok, pid}`