Skip to content

Instantly share code, notes, and snippets.

View shkrt's full-sized avatar

Ruslan Gafurov shkrt

View GitHub Profile
@emiliorizzo
emiliorizzo / purge-auth.vcl
Last active August 15, 2022 12:02
Varnish configuration, purge only for basic auth users
# Varnish configuration
# Purge only for basic auth users
## HOW TO PURGE
### with browser
# 1 - Set basic auth on /auth (or change the rule)
# 2 - Authenticate on /auth, and load url to refresh (purge) cache.
### with wget

Пример рефакторинга с использованием транзакций

Опять рассмотрим tasks#create экшен.

В экшене 3 разных логики, которые выполняются последовательно:

  1. валидация данных - необходимый шаг;
  2. сохраниение таска - необходимый шаг, если какая-то ошибка, необходимо возвращать failed значение;
  3. отправка нотификаций - мы не хотим, что бы наша транзакия не выполнялась, если отправка нотификации не выполнится;

Поэтому напишем нашу транзакцию. Так же мы будем использовать Either монаду для возвращения статуса шага транзакции. Right для успешного, Left - не успешного:

@kazimzaidi
kazimzaidi / pre-commit
Created August 28, 2018 02:23
git pre-commit hook to run rubocop on changed files
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@andersevenrud
andersevenrud / alacritty-tmux-vim_truecolor.md
Last active May 19, 2025 20:56
True Color (24-bit) and italics with alacritty + tmux + vim (neovim)

True Color (24-bit) and italics with alacritty + tmux + vim (neovim)

This should make True Color (24-bit) and italics work in your tmux session and vim/neovim when using Alacritty (and should be compatible with any other terminal emulator, including Kitty).

Testing colors

Running this script should look the same in tmux as without.

curl -s https://gist.githubusercontent.com/lifepillar/09a44b8cf0f9397465614e622979107f/raw/24-bit-color.sh >24-bit-color.sh
@komasaru
komasaru / calc_rcc_spearman.rb
Created January 28, 2020 02:49
Ruby script to calculate a Spearman's Rank Correlation Coefficient.
#! /usr/local/bin/ruby
class Array
def rcc_spearman(y)
# 以下の場合は例外スロー
# - 引数の配列が Array クラスでない
# - 自身配列が空
# - 配列サイズが異なる
# - 数値以外のデータが存在する
raise "Argument is not a Array class!" unless y.class == Array
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active May 27, 2025 16:29
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias