Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile

Faster Rails tests

Feedback loop speed in one of the biggest contributing factors to overall development time. The faster you get results, the faster you can move on to other things. A fast enough test suite is therefore critical to teams' success, and is worth investing some time at the beginning to save in the long run.

Below is a list of techniques for speeding up a Rails test suite. It is not comprehensive, but should definitely provide some quick wins. This list of techniques assumes you're using minitest, but most everything should translate over to rspec by simply replacing test/test_helper.rb with spec/spec_helper.rb.

Benchmarks for GC Compactor

GC benchmarks for trunk vs gc-compact seem to be about the same:

$ make benchmark ITEM=gc
./revision.h unchanged
/Users/aaron/.rbenv/shims/ruby --disable=gems -rrubygems -I./benchmark/lib ./benchmark/benchmark-driver/exe/benchmark-driver \
	            --executables="compare-ruby::/Users/aaron/.rbenv/shims/ruby --disable=gems -I.ext/common --disable-gem" \
	            --executables="built-ruby::./miniruby -I./lib -I. -I.ext/common  -r./prelude --disable-gem" \
@avlazarov
avlazarov / grpc.conf
Last active August 23, 2019 14:51
AnyCable gRPC connection issue
upstream grpcservers {
server 0.0.0.0:50051;
server 0.0.0.0:50052;
}
server {
listen 50050 http2;
server_name localhost;
access_log /var/log/nginx/grpc_log.json;
@palkan
palkan / 00_Readme.md
Last active July 16, 2022 06:50
graphql-ruby fragment caching

PoC: GraphQL Ruby fragment caching

This example demonstrates how we can cache the response fragments in graphql-ruby.

Existing solutions only allow caching resolved values but not all the GraphQL machinery (validation, coercion, whatever).

Caching response parts (in case of Ruby, sub-Hashes) is much more efficient.

Benchmarks

--- Setup
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DROP TABLE IF EXISTS planner_checksums CASCADE;
CREATE TABLE IF NOT EXISTS planner_checksums (
identifiers_checksum uuid,
attributes_checksum uuid,
version INT
);
CREATE INDEX planner_checksums_idx ON planner_checksums(identifiers_checksum);
@palkan
palkan / README.md
Created January 24, 2022 13:29
Rails boot time profiling

Add the following to application.rb:

$icallbacks = []
$icallbacks.define_singleton_method(:print) do
  puts sort_by { |(a, b)| -b }.map { |(a, b)| "#{b}\t\t#{a}" }.join("\n")
end

ActiveSupport::Notifications.subscribe("load_config_initializer.railties") do |event|
 $icallbacks << [event.payload[:initializer], event.duration]

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@bibendi
bibendi / Get started with local and remote LLM GPT.md
Last active June 7, 2024 12:41
Get started with local and remote LLM GPT.md

[[GPT]] Гайд для тех, кто не хочет делиться своими данными при общении с AI чатами или сэкономить 20 баксов на подписку, а тратить не больше 5 в крипте. То есть с LLM моделя можно работать как полностью локально (важна оперативка), либо через провайдера OpenRouter.

Local

Для работа offline с [[LLM]] модели вам нужно следующее:

  • Сначала немного теории. Что такое [[LLM]] модели https://www.youtube.com/watch?v=zjkBMFhNj_g
  • Устанавливаем Ollama сервер. Это как Docker, только для моделей
    • Скачиваем сервере с https://ollama.com/
    • Выбираем модель https://ollama.com/library и скачиваем ее. Если у вас не более 16Gb RAM, то я рекомендую wizardlm2:7b. Это супер новая модель, примерно сопоставимая с chatGPT 3.5.
    • Команда следующая: ollama run wizardlm2:7b-q5_K_M. После скачивания запуститься промт, в котором можно проверить модель, ну либо сразу закрыть. На верхней панели должна появиться иконка с запущенной ламой.
  • Чтобы взаимодействовать с моделью далее нужно установить клиент. Их есть два вида: webU