Skip to content

Instantly share code, notes, and snippets.

@romiras
romiras / async_queue_consumer.rb
Created May 27, 2022 18:08
Demo async queue consumer with concurrent N workers in Ruby
require 'concurrent'
require 'benchmark'
require 'logger'
module Logging # Credits: https://stackoverflow.com/a/6768164/10118318
# This is the magical bit that gets mixed into your classes
def logger
Logging.logger
end
@romiras
romiras / gpipeview.c
Created May 11, 2015 14:58
GTK+ pipe viewer
/*
Simple GTK+ pipe viewer
Contributors: Romiras
Based on paned.c
LICENSE: GNU GPLv3
*/
#include <stdio.h>
#include <unistd.h>
#include <gtk/gtk.h>
@romiras
romiras / concurrent_workers_batch_test.rb
Last active January 25, 2022 07:40
Concurrently classify items by type and batch them with multiple workers
# Concurrently classify items by type and batch them with multiple workers
require 'logger'
NUM_WORKERS = 10
NUM_ITEMS = 12
NUM_ITERATIONS = 5000
Item = Struct.new(:id, :type)
@romiras
romiras / es_bulk_upload.sh
Last active December 8, 2021 16:43
Script for uploading 30 K dataset into ES
split --verbose -l1000 dataset-bulk-30k.ndjson bulk.
for f in bulk.??; do echo $f; curl -i -X POST localhost:9200/_bulk -H "Content-Type: application/x-ndjson" --data-binary @$f; done
@romiras
romiras / es_ndjson_split.rb
Last active November 11, 2021 10:57
A script for transforming .jsonl file into file ready for bulk import to ES.
# Reads .jsonl file and transforms it into file ready for bulk import to ES.
require 'json'
File.open(ARGV[1], 'wb') {|f|
ARGF.each_line { |line|
a = JSON.parse(line)
out = {
index: {
"_id": a["_id"],
@romiras
romiras / concurrent_workers_demo.rb
Last active November 4, 2021 08:06
Workers with Concurrent::Future in Ruby
require 'concurrent'
require 'benchmark'
max = 20 # number of tasks to process
n_workers = 4 # number of concurrent workers
results = [] #
lambda = -> (iter, i) { results << ('%04d' % i); d = rand(0.005)+0.001; puts("Iteration #{iter}. sleep %.3f" % d); sleep(d) }
workers = Array.new(n_workers, lambda)
iter = 0
@romiras
romiras / Readme.md
Last active June 9, 2020 21:05
EBK backup extraction scripts

How to use

Assumed you have files with extension .ebk stored by Kies.

Prerequisites

Install Ruby 2.3 or later

Example for running in Bash terminal. Linux is not mandatory for running Ruby program.

@romiras
romiras / dictionary-gnu-sort-bd.txt
Last active January 1, 2020 10:56 — forked from klauspost/dictionary-sorted.txt
Brotli dictionary - printed escaped - sorted with "sort -bd" (with dictionary order, ignoring blanks), a tool from GNU coreutils
"<!--"
"><!--"
"||[];"
"--><!--"
"--></"
"----"
"!--<"
"//--></"
"//-->"
"...</"
@romiras
romiras / Gemfile
Created May 8, 2019 07:31
EventMachine async URL fetcher
source "https://rubygems.org"
gem 'eventmachine'
gem 'em-http-request'
@romiras
romiras / simple_fuzzy_match.rb
Created December 30, 2016 12:54
Simple function for fuzzy string match
require 'active_support/all' # mb_chars
def simple_fuzzy_match(s1, s2)
levenshtein_distance( normalize_str(s1), normalize_str(s2) ) < 2
end
def normalize_str(s)
s.
mb_chars. # convert to multibyte string (ActiveSupport::Multibyte::Chars) - required in Ruby version below 2.4
downcase. # lower case for all characters