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 / Gemfile
Created August 17, 2012 10:13
Sinatra streaming + Redis PubSub
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib', require: 'sinatra/streaming'
group :development do
gem 'thin'
gem 'pry-rails'
end
@pirj
pirj / ability.rb
Created July 17, 2011 20:23
Padrino and CanCan
# include this in app file
# this is for Role Based Access Controle, can be much shorter
class Ability
include CanCan::Ability
def initialize account
@abilities ||= {}
allow [:any, :manager, :manufacturer, :admin] do
@pirj
pirj / ruby-block-sugar.asciidoc
Last active July 29, 2022 14:19
Ruby block sugar

You won’t find rants on how functional programming improves you, your sanity and your life overall here. There are some examples in the very beginning to save you some time on reading the whole post, just come along if you don’t like how they look like.

By the way, this is not even a blog, so formally this is not even a blog post. This is not a library or a new paradigm. It’s just a few pieces of code that might come handy for your daily job.

Example:

[1, 3.14, -4].map &_.safe{ magnitude odd? } # => [true, nil, false]
@pirj
pirj / locate.rb
Last active December 15, 2020 09:21
Locate those annoying MESSages during tests
# Put this in your test helper
# Use `caller` to locate where in code that BUGGER is
class IO
BUGGER = /annoying/
def print *args
binding.pry if args.any? { |arg| arg =~ BUGGER }
super *args
end
def puts *args
@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 / 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 / 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 / CV.md
Last active August 22, 2019 23:34
Curriculum vitae

Personal summary

Name: Filipp Pirozhkov

Age: 40

Located in: Somewhere traveling

Top engineer with proven ability to develop efficient solutions to complex problems. Extensive experience and skills with all levels of software and architecture.