Skip to content

Instantly share code, notes, and snippets.

View pirj's full-sized avatar
🚜
Relentless

Phil Pirozhkov pirj

🚜
Relentless
View GitHub Profile
@pirj
pirj / with_zones_spec.rb
Created December 2, 2020 21:22
RSpec self-generating example groups
RSpec.shared_examples 'with different zones', :within_time_zones do
block = metadata[:block] # the block passed to `context 'some test'`
parent_example_group = superclass # the `describe 'root'` one
# around { } # skip running examples in `context 'some test'`
# or
# metadata[:skip] = true # skip the whole `context 'some test'`
# or
parent_example_group.children.delete(self)
# Calculating -------------------------------------
# if 6.053 (± 0.0%) i/s - 31.000 in 5.121795s
# case 0.908 (± 0.0%) i/s - 5.000 in 5.505769s
# case no range 2.967k (± 0.7%) i/s - 14.900k in 5.022385s
# odd? 3.085k (± 0.8%) i/s - 15.450k in 5.009226s
# SCROLL TO THE BOTTOM
def odd_if(a)
if a == 1 then false
@pirj
pirj / config-environments-test.rb
Created August 18, 2020 19:22
Create unlogged PostgreSQL tables - faster, but not crash-proof
config.to_prepare do
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
end
end
@pirj
pirj / a_spec.rb
Last active August 8, 2019 22:55
RSpec/ExampleGroupArgument cop draft
RSpec.describe do
# good
describe MyClass do
end
describe 'sdfsd' do
end
describe "sfa #{dfsdf}" do
end
# questionable
@pirj
pirj / f_hjkl_movements.json
Last active September 16, 2019 18:07
Karabiner complex modiications: Vi'ish mode
{
"title": "F + HJKL",
"rules": [
{
"description": "Vi'ish Mode [F as Trigger Key]",
"manipulators": [
{
"type": "basic",
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 150,
@pirj
pirj / subject_stub.rb
Last active May 20, 2019 23:12
Modified version of the `lib/rubocop/cop/rspec/subject_stub.rb` cop to detect `expect(subject).to all receive(...)` syntax only
def_node_matcher :message_expectation?, <<-PATTERN
(send
{
(send nil? { :expect :allow } (send nil? %))
(send nil? :is_expected)
}
#{Runners::ALL.node_pattern_union}
#all_matcher?
)
PATTERN
@pirj
pirj / match.rb
Last active May 22, 2019 13:48
NodePattern debug boilerplate
def match(pattern, source)
ruby_version = RUBY_VERSION.to_f
node_pattern = RuboCop::NodePattern.new(pattern)
ast = RuboCop::ProcessedSource.new(source, ruby_version).ast
node_pattern.match(ast)
end
match('(send nil? :sum $...)', 'sum(1,2,3,n)')
# => [s(:int, 1), s(:int, 2), s(:int, 3), s(:send, nil, :n)]
@pirj
pirj / repl.rb
Created February 23, 2019 10:31
Ruby REPL when `pry` is not there
while(true) do
begin
print '> '
input = STDIN.readline.chop
output = eval(input)
puts "=> #{output}"
rescue StandardError => e
puts "Error: #{e.message}"
end
end
@pirj
pirj / Outro slide #1
Created August 27, 2018 09:32
Productivity tips
RECAP
- don't blindly follow the hints
- figure out what slows you down and takes away your focus
- move forward one confident step at a time
- be confident with the changes you make
- identify the inconveniences that slow you down or distract you, and eliminate them
- rest assured that what slows you down has a solution, you just need to find it
@pirj
pirj / pr.md
Created February 1, 2017 13:16 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: