Skip to content

Instantly share code, notes, and snippets.

@yevgenko
yevgenko / git-jump.sh
Created November 19, 2023 18:52
Git command to jump to interesting elements in an editor
#!/bin/sh
usage() {
cat <<\EOF
usage: git jump <mode> [<args>]
Jump to interesting elements in an editor.
The <mode> parameter is one of:
diff: elements are diff hunks. Arguments are given to diff.
@yevgenko
yevgenko / script-wrapper.rb
Last active September 30, 2022 14:56
Freezing random generator and capturing output of ruby script without changing original file ['jbrains/trivia', 'golden master']
require 'stringio'
def capture_stdout_string
io = StringIO.new
capture_stdout(io) do
yield
end
io.string
@yevgenko
yevgenko / fzp.sh
Created November 29, 2021 09:48
fzp (FuzzyPreview): FuzzyFinder with interactive ripgrep and preview with highlights
#!/bin/sh
INITIAL_QUERY=""
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
--ansi --disabled --query "$INITIAL_QUERY" \
--height=50% --layout=reverse \
-m --delimiter : \
--preview "rg {q} --color always --line-number --passthrough {1}" \
@yevgenko
yevgenko / fzg.sh
Last active November 21, 2021 13:36
fzg (FuzzyGrep): The Silver Searcher + Fuzzy Finder with needle highlighted in preview
#!/bin/sh
usage() {
cat <<\EOF
usage: fzg <needle>
EOF
}
if test $# -lt 1; then
usage >&2

The Problem

bundle install
> Fetching source index from https://rails-assets.org/
> 
> Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rails-assets.org/
> Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rails-assets.org/
> Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rails-assets.org/
> Could not fetch specs from https://rails-assets.org/
@yevgenko
yevgenko / flatfile_io_json2csv.rb
Last active July 16, 2019 11:20
Convert flatfile.io output (key-value map) to CSV string.
require 'csv'
require 'json'
def flatfile_io_json2csv_string(data_as_string = '[{"sku_code": "123"}, {"sku_code": "321"}]')
CSV.generate do |csv|
json_data = JSON.parse(data_as_string)
csv << json_data.first.keys # header
json_data.each do |hash|
csv << hash.values
@yevgenko
yevgenko / single_message_listener.rb
Created May 1, 2019 12:00
GOOS: auction snipper, single message listener
#
# https://github.com/yevgenko/ruby-auction_sniper/blob/master/spec/fake_auction_server.rb
#
# https://www.safaribooksonline.com/library/view/growing-object-oriented-software/9780321574442/ch11.html
#
class SingleMessageListener
include RSpec::Matchers
def initialize
@messages = SizedQueue.new(1)
@yevgenko
yevgenko / self_shunt_spec.rb
Created March 5, 2019 11:49
Self Shunt vs Fake Object in Ruby / RSpec
module Fubarizable
def fubarize
"foobar-#{fubarizable}-foobar"
end
end
class FakeFoobar
include Fubarizable
def fubarizable
@yevgenko
yevgenko / docker-elastic.sh
Created June 1, 2018 15:19
Docker scripts
#!/bin/sh
docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.4.1
title Designing End To End Test
Test->ApplicationRunner: perform_foobar_for(order)
ApplicationRunner->OrderPage: perform_action(Order::ACTION_FOOBAR)
OrderPage->CapybaraPage: visit('/orders/order.id')
OrderPage->CapybaraPage: click(text)
Test->ApplicationRunner: has_shown_foobar_status_for(order)
ApplicationRunner->OrderPage: shows_status(Order::STATUS_FOOBAR)
OrderPage->CapybaraPage: visit('/orders/order.id')
OrderPage->CapybaraPage: assert_text(text)