Skip to content

Instantly share code, notes, and snippets.

@maierru
maierru / client_example
Created November 8, 2019 23:42 — forked from sandro/client_example
Ruby select socket server. An example of a single-threaded, event-driven (select) server.
$ irb -r ./select_server
>> client.puts "hi"
=> nil
>> client.puts "bye"
=> nil
>> client.close
=> nil
>> exit
@maierru
maierru / clear-sidekiq-jobs.sh
Created April 15, 2019 07:35 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
@maierru
maierru / freebsd.txt
Created January 14, 2019 13:23
mac os x bash last day of each month
$ for i in {1..12}; do date -v1d -v-1d -v-${i}m +%Y-%m-%d; done
2018-11-30
2018-10-31
2018-09-30
2018-08-31
2018-07-31
2018-06-30
2018-05-31
2018-04-30
2018-03-31
@maierru
maierru / gist:c6cffec05574fb2c0ed354348997fdfa
Created December 11, 2018 12:17
mac os background notification in the ssh session
sleep 10 && echo -en "\007"
@maierru
maierru / line_count_benchmark.rb
Created August 17, 2018 14:24 — forked from guilhermesimoes/line_count_benchmark.rb
Ruby Benchmark: Counting the number of lines of a file
# gem install benchmark-ips
require "benchmark/ips"
path = "lib/rubycritic/cli/options.rb"
Benchmark.ips do |x|
x.report("read + each_line") { File.read(path).each_line.count }
x.report("open + each_line") { File.open(path, "r").each_line.count }
@maierru
maierru / table_info.sql
Created August 6, 2018 15:39
postgresql table info sql
SELECT l.what, l.nr AS "bytes/ct"
, CASE WHEN is_size THEN pg_size_pretty(nr) END AS bytes_pretty
, CASE WHEN is_size THEN nr / x.ct END AS bytes_per_row
FROM (
SELECT min(tableoid) AS tbl -- same as 'public.tbl'::regclass::oid
, count(*) AS ct
, sum(length(t::text)) AS txt_len -- length in characters
FROM public.write_a_table_name_instead t -- provide table name *once*
) x
, LATERAL (
@maierru
maierru / accounting.sql
Created February 6, 2018 09:20 — forked from RichardKnop/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@maierru
maierru / signals.go
Created January 19, 2018 15:32
go systems signals handler
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
@maierru
maierru / OTP
Last active December 13, 2019 13:10
Phoenix (elixir) highload optimization
# Move erts IO Polling to dedicated threads
# https://github.com/erlang/otp/pull/1552
@maierru
maierru / ets select is slow.txt
Last active August 27, 2017 11:34
ETS select is slow => O(n)
https://github.com/sat2707/hlcupdocs/blob/master/TECHNICAL_TASK.md
iex(9)> :ets.info(:visits)
[read_concurrency: true, write_concurrency: false, compressed: false,
memory: 110008228, owner: #PID<0.3544.0>, heir: :none, name: :visits,
size: 10000740, node: :nonode@nohost, named_table: true, type: :ordered_set,
keypos: 1, protection: :public]
iex(11)> fun = :ets.fun2ms(fn {id, user, location, visited_at, mark} when user == 475422 -> id end)
[{{:"$1", :"$2", :"$3", :"$4", :"$5"}, [{:==, :"$2", 475422}], [:"$1"]}]