Skip to content

Instantly share code, notes, and snippets.

View drymar's full-sized avatar

Dmytro Rymar drymar

  • Ukraine, Kyiv
View GitHub Profile
# .pryrc
require 'rails/application/route_inspector'
def display_routes
Rails.application.reload_routes!
routes = Rails.application.routes.routes
inspector = Rails::Application::RouteInspector.new
puts inspector.format(routes, ENV['CONTROLLER']).join("\n")
end
@drymar
drymar / rbenv-howto.md
Created February 21, 2018 12:21 — forked from MicahElliott/rbenv-howto.md
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
@drymar
drymar / install-pdf2htmlEX-ubuntu-14.04.sh
Created September 22, 2017 13:53 — forked from giordanocardillo/install-pdf2htmlEX-ubuntu-14.04.sh
Installing pdf2htmlEX on Ubuntu Server 14.04
#!/bin/sh
RESTORE=$(echo '\033[0m')
BOLD=$(echo '\033[1m')
GREEN=$(echo '\033[1;32m')
echo
echo ${GREEN}
echo "------------------------------"
echo " Installing prerequisites "
echo "------------------------------"
echo
@drymar
drymar / R.rb
Last active May 22, 2017 15:20
def tickets
case
when filters.excel
range_tickets
when filters.avia_offset.present? == false
range_tickets[0..24]
when filters.from_postsale
range_tickets[0...filters.avia_offset]
else
range_tickets[filters.avia_offset..filters.avia_offset + 9] || []
@drymar
drymar / migration.rb
Created April 11, 2017 08:59 — forked from matfiz/migration.rb
Reversible change_column Rails migration
reversible do |dir|
dir.up { change_column :posts, :name, :text }
dir.down { change_column :posts, :name, :string }
end
require 'open-uri'
require 'nokogiri'
def words
uri = 'http://www.languagedaily.com/learn-german/vocabulary/common-german-words'
html = open(uri)
doc = Nokogiri::HTML(html)
germans = doc.css('td.bigLetter')
{
"request": {
"airline": {
"requestedCode": "PS",
"fsCode": "PS"
},
"flight": {
"requested": "777",
"interpreted": "777"
},
class TicketsController < ApplicationController
respond_to? :js
def index
form = TicketFormValidator.new(form_params)
if form.valid?
@ticket = ticket_service(form.pnr_number)
@pnr = form.pnr_number
if @ticket.is_a? String
flash.now[:error] = @ticket