Skip to content

Instantly share code, notes, and snippets.

@simpl1g
simpl1g / patch.rb
Created March 28, 2024 18:38
Profile comparison
# frozen_string_literal: true
require 'benchmark/ips'
require 'redis'
$redis = Redis.new
class MethodProfiler
def self.patch_using_alias_method(klass, methods, name)
patch_source_line = __LINE__ + 3
@simpl1g
simpl1g / docker-compose.yml
Created November 18, 2023 22:11
Clickhouse docker compose with volume limit
services:
ch_server:
image: clickhouse/clickhouse-server:latest
ports:
- "8123:8123"
- "9000:9000"
volumes:
- ch_data:/var/lib/clickhouse
- type: bind
source: ./settings/users.xml
@simpl1g
simpl1g / arrow-csv.rb
Last active January 2, 2022 11:11
Arrow CSV bench
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
gem 'red-arrow'
end
require 'arrow'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'curb'
gem 'benchmark-ips'
gem 'oj'
gem 'red-parquet'
gem 'rover-df'
@simpl1g
simpl1g / prewhere.sql
Last active September 10, 2021 15:15
where/prewhere
ENGINE = ReplicatedSummingMergeTree
PARTITION BY toYYYYMMDD(date)
PRIMARY KEY app_id, date, install_date
SELECT install_date, SUM(install_count)
FROM analytics_grouped_stats_shard
PREWHERE (attribution_network IN ('Facebook Ads')) AND (date >= toDate('2021-08-01')) AND (date < today())
AND (install_date >= toDate('2021-08-01')) AND (install_date <= toDate('2021-08-31'))
GROUP BY install_date
@simpl1g
simpl1g / kafka
Last active August 6, 2019 06:35
clichouse-kafka
select count(1) from dummy_buf => 0
kafkacat -b kafka_brokers -t dummy -P
{"ad_type":1}
select count(1) from dummy_buf => 1
...
select count(1) from dummy_buf => 200
2019.08.01 13:38:43.908010 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Subscribed to topics: dashboard_stats
2019.08.01 13:38:43.908041 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Assigned to topics: dashboard_stats dashboard_stats dashboard_stats dashboard_stats dashboard_stats dashboard_stats dashboard_stats dashboard_stats
2019.08.01 13:38:44.190842 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Polled batch of 65536 messages
2019.08.01 13:38:44.367789 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Polled batch of 65536 messages
2019.08.01 13:38:44.530755 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Polled batch of 65536 messages
2019.08.01 13:38:44.745517 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Polled batch of 65536 messages
2019.08.01 13:38:45.043154 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Polled batch of 65536 messages
2019.08.01 13:38:45.652610 [ 37 ] {} <Trace> StorageKafka (dashboard_stats_queue): Polled batch of 655
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '4.2.4'
@simpl1g
simpl1g / dice_sum_probability_calc.rb
Created July 31, 2015 20:49
Dice sum probability calculator
require 'bigdecimal'
require 'benchmark'
class DiceSumProbabilityCalc
DEFAULT_SIDES_COUNT = 6
def initialize(sum, dices_count, dice_sides_count = DEFAULT_SIDES_COUNT)
@sum = sum
@dices_count = dices_count
@dice_sides_count = dice_sides_count
@simpl1g
simpl1g / arel.rb
Last active August 29, 2015 14:05
complex query in arel
def accounts
Account.arel_table
end
def subscriptions
Subscription.arel_table
end
def charges
Charge::Base.arel_table