Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
T=${1:-qa2}
git branch -D $T
git checkout -b $T && git push --set-upstream origin $T --force
git checkout -
@piotrze
piotrze / debug.liquid
Created February 14, 2020 10:30
Debug liquid
---
slug: debug
layout_name:
---
{% graphql partials %}
query partials{
partials: admin_liquid_partials(filter:{ path: { contains: "debug_content" }}){
results{
id
physical_file_path
@piotrze
piotrze / log.rb
Created April 29, 2019 13:40
log message with time and memory
def log(message)
memory = `ps -o rss -p #{$$}`.chomp.split("\n").last.to_i/1024
puts "#{Time.now} #{memory}M #{message}"
end
@piotrze
piotrze / styled_input.html
Created July 1, 2018 14:41
Input that will show matched query
<!DOCTYPE html>
<html lang="en">
<head>
<style>
div{
position:relative;
}
input, span{
top:0;
position:absolute;
@piotrze
piotrze / case_vs_public_send.rb
Created February 14, 2018 14:11
Benchmark case over public_send
require 'benchmark'
class A
def call_case(var = 'a')
case var
when 'a'
a
end
end
@piotrze
piotrze / puts_to_file.rb
Created March 20, 2017 10:31
Save puts into file
some_method_or_expression
File.open('/tmp/puts.txt','a') { |s| s.puts _ }
@piotrze
piotrze / named_params_benchmark.rb
Created September 20, 2016 06:58
Ruby named params benchmark
require 'benchmark'
def normal_param(a, b)
return [a, b]
end
def named_param(a:, b:)
return [a, b]
end
@piotrze
piotrze / report.rb
Last active August 24, 2016 13:55
Extract method with block
def generate
prefetch_volunteers do |volunteer|
csv << VolunteerPresenter.new(volunteer).to_csv
end
end
private
def prefetch_volunteers
@volunteers.includes(
@piotrze
piotrze / report.rb
Last active August 24, 2016 13:57
Extract method
############################# first version
def generate
@volunteers.includes(
[:user, { taggings: :tag }]
).find_each(batch_size: 1000) do |volunteer|
csv << VolunteerPresenter.new(volunteer).to_csv
end
end
############################ second version not working
@piotrze
piotrze / test_helper.rb
Last active February 24, 2016 08:09
Save screenshot on failed integration tests with capybara.
# test/test_helper.rb
class ActionDispatch::IntegrationTest
def after_teardown
if !passed?
timestamp = "#{Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')}"
screenshot_name = "screenshot-#{timestamp}.png"
# Handle CircleCi too
screenshot_path = "#{ENV.fetch('CIRCLE_ARTIFACTS', Rails.root.join('tmp/capybara'))}/#{screenshot_name}"
page.save_screenshot(screenshot_path)