Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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
#!/bin/bash
T=${1:-qa2}
git branch -D $T
git checkout -b $T && git push --set-upstream origin $T --force
git checkout -