Skip to content

Instantly share code, notes, and snippets.

View Kukunin's full-sized avatar

Sergiy Kukunin Kukunin

View GitHub Profile
@Kukunin
Kukunin / ractors.rb
Last active December 28, 2023 12:53
Ruby Ractors vs Threads benchmark
require 'benchmark'
require 'etc'
Ractor.new { :warmup } if defined?(Ractor)
def fibonacci(n)
return n if (0..1).include? n
fibonacci(n - 1) + fibonacci(n - 2)
end
@Kukunin
Kukunin / hierarchy_spec.rb
Last active April 9, 2020 10:49
A test to create a tree of elements
require 'rails_helper'
RSpec.describe 'hierarchy' do
subject(:hierarchy) { create_hierarchy(per_level: 3, levels: 5) }
def create_element(type, children)
{ type: type, children: children }
end
# Take a pen and piece of paper
@Kukunin
Kukunin / myTransformation.js
Last active May 28, 2022 21:48
A template for a typical transformation for gulp
const through = require('through2'),
PluginError = require('gulp-util').PluginError;
module.exports = function myTransformation(options) {
if(!options) {
options = {};
}
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
@Kukunin
Kukunin / websocket.js
Created December 9, 2017 19:49
Simulate a TCP socket with `ws` in NOMP based pools
var events = require('events');
var ws = require('ws');
function simulateTcpSocketFromWS(ws) {
var socket = {};
socket.remoteAddress = ws._socket.remoteAddress;
socket.localPort = ws._socket.localPort;
@Kukunin
Kukunin / Dockerfile
Created November 3, 2017 10:47
Dockerfile along with docker-compose.yml for a typical phoenix 1.3 elixir application
FROM elixir:1.5
MAINTAINER Sergiy Kukunin <sergey.kukunin@gmail.com>
RUN wget -qO- https://deb.nodesource.com/setup_8.x | bash - && \
apt-get install -y nodejs
RUN mix local.rebar
RUN mix local.hex --force
WORKDIR /app
ENV MIX_ENV prod
@Kukunin
Kukunin / push_git_to_server.sh
Created November 3, 2017 09:02
How to upload git repo to the server directly without a intermediate repository
# We are in a folder with local git repository
pwd
# We need to create an empty repo on the server
# We want to checkout another branch because
# git prevents you from pushing to the current checked branch, which is master by default
ssh <user>@<host> 'mkdir repo && cd repo && git init && git checkout -b local'
# Add remote repo
git remote add server <user>@<host>:repo
@Kukunin
Kukunin / my_grape_api.rb
Last active November 24, 2022 12:31
Ruby Grape API authorization with Pundit example, without any extra gems
class MyGrapeAPI < Grape::API
helpers Pundit
after { verify_authorized }
helpers do
def current_user
nil # your authentication mechanism
end
end

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@Kukunin
Kukunin / rom_reading_aggregates.rb
Created July 4, 2017 14:33
Example of reading aggregates in rom-rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required.'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rom'
@Kukunin
Kukunin / workers.yml
Created June 16, 2017 20:32
Uniform distribution of servers in ansible
- hosts: workers
gather_facts: no
pre_tasks:
- set_fact: sequence_number="{{ ansible_default_ipv4['macaddress'].split(':')[-1] | int('', 16) }}"
- set_fact: daemons_count="{{ groups['daemons'] | length }}"
- set_fact: daemon_i='{{ (sequence_number|int) % (daemons_count|int)}}'
- set_fact: daemon_host="{{ hostvars[groups['daemons'][daemon_i|int]]['ansible_eth0']['ipv4']['address'] }}"
- debug: var=daemon_i
roles:
- role: worker