Skip to content

Instantly share code, notes, and snippets.

@dmshvetsov
dmshvetsov / worker_and_queue_perfect_pair.rb
Created February 5, 2019 05:33
Example of how we may use queue with threads to make efficient background worker.
class Worker
def self.start(num_threads:, queue_size:)
queue = SizedQueue.new(queue_size)
worker = new(num_threads: num_threads, queue: queue)
worker.spawn_threads
worker
end
def initialize(num_threads:, queue:)
@num_threads = num_threads
[server]
SERVER
[server:vars]
server_name=SERVER
email=noc@gopractice.io
docker_nginx_ssl=true
@hartator
hartator / benchmark-deep-vs-flat-directories.rb
Last active December 28, 2018 10:28
Source code for Benchmark: Deep directory structure vs. flat directory structure to store millions of files on ext4 article (https://medium.com/@hartator/benchmark-deep-directory-structure-vs-flat-directory-structure-to-store-millions-of-files-on-ext4-cac1000ca28)
require 'digest'
require 'benchmark'
hash = {}
10_000_000.times do
key = Digest::MD5.hexdigest(rand.to_s)
value = Digest::MD5.hexdigest(rand.to_s)
hash[key] = value
end
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active May 22, 2024 08:34
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active June 1, 2024 08:46
set -e, -u, -o, -x pipefail explanation
# Usage:
#
# class Mail
# include SimpleStateMachine
#
# self.initial_state = 'unread'
# self.transitions_map = {
# read: {from: 'unread', to: 'read'},
# unread: {from: 'any', to: 'unread'},
# delete: {from: 'any', to: 'deleted'},
module SimpleRailway
class Result
attr_accessor :success, :data
def initialize(success, data)
@success = success
@data = data
end
def success?; !!success; end
def failure?; !success?; end
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'memory_profiler'
gem 'benchmark-ips'
end
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'benchmark-ips'
end
require 'active_record'
@EdwardDiehl
EdwardDiehl / Bracket Terminology.md
Created May 28, 2018 13:16 — forked from Integralist/Bracket Terminology.md
[Bracket Terminology] #bracket #terminology
parentheses:     ( ) 
braces:          { } 
brackets:        < > 
square-brackets: [ ]