Skip to content

Instantly share code, notes, and snippets.

Avatar
🚜
Relentless

Phil Pirozhkov pirj

🚜
Relentless
View GitHub Profile
@pirj
pirj / with_zones_spec.rb
Created Dec 2, 2020
RSpec self-generating example groups
View with_zones_spec.rb
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)
View case_or_odd.rb
# 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 Aug 18, 2020
Create unlogged PostgreSQL tables - faster, but not crash-proof
View config-environments-test.rb
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 Aug 8, 2019
RSpec/ExampleGroupArgument cop draft
View a_spec.rb
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 Sep 16, 2019
Karabiner complex modiications: Vi'ish mode
View f_hjkl_movements.json
{
"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
Modified version of the `lib/rubocop/cop/rspec/subject_stub.rb` cop to detect `expect(subject).to all receive(...)` syntax only
View subject_stub.rb
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
NodePattern debug boilerplate
View match.rb
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 Feb 23, 2019
Ruby REPL when `pry` is not there
View repl.rb
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 Aug 27, 2018
Productivity tips
View Outro slide #1
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 Feb 1, 2017 — forked from piscisaureus/pr.md
Checkout github pull requests locally
View pr.md

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 = git@github.com: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: