Skip to content

Instantly share code, notes, and snippets.

View Fivell's full-sized avatar
🏠
Working from home

Igor Fedoronchuk Fivell

🏠
Working from home
View GitHub Profile
@Fivell
Fivell / en-GB.yml
Created January 17, 2017 13:11 — forked from scottlowe/en-GB.yml
en-GB locale for Rails 3
en-GB:
date:
formats:
# Use the strftime parameters for formats.
# When no format has been given, it uses default.
# You can provide other formats here if you like!
default: "%d/%m/%Y"
short: "%d %b"
long: "%d %B, %Y"
@Fivell
Fivell / rocky_raccoon.csv
Created January 14, 2017 22:24 — forked from johana-star/rocky_raccoon.csv
Ruby Riddle: Why doesn't to_proc work on a refined Hash?
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 12 columns, instead of 4 in line 1.
Task ID,Type,Name,Status,Project,Context,Start Date,Due Date,Completion Date,Duration,Flagged,Notes
1,Context,Rocky Raccoon,active
1.1,Action,Now somewhere in the black mountain hills of Dakota,,,Rocky Raccoon,,,,,0,
1.2,Action,There lived a young boy named Rocky Raccoon,,,Rocky Raccoon,,,,,0,
1.3,Action,And one day his woman ran off with another guy,,,Rocky Raccoon,,,,,0,
1.4,Action,He hit young Rocky in the eye,,,Rocky Raccoon,,,,,0,
1.5,Action,Rocky didn't like that he said I'm gonna get that boy,,,Rocky Raccoon,,,,,0,
1.6,Action,So one day he walked into town,,,Rocky Raccoon,,,,,0,
1.7,Action,Booked himself a room in the local saloon,,,Rocky Raccoon,,,,,0,
1.8,Action,Rocky Raccoon checked into his room,,,Rocky Raccoon,,,,,0,
@Fivell
Fivell / type_caster.rb
Created January 12, 2017 22:12 — forked from masqita/type_caster.rb
TypeCaster module
class Boolean
def self.from_json(value)
if value.is_a?(TrueClass) || value.is_a?(FalseClass)
return value
elsif value.is_a?(String)
return value == ("true" || "1")
elsif value.is_a?(Integer)
return value == 1
else
nil
@Fivell
Fivell / faraday_typh_default.rb
Created December 13, 2016 19:21 — forked from ezkl/faraday_typh_default.rb
Parallel Requests w/ Faraday + Typhoeus
require "faraday"
require 'typhoeus'
conn = Faraday.new(:url => 'http://httpstat.us') do |builder|
builder.request :url_encoded
builder.response :logger
builder.adapter :typhoeus
end
conn.in_parallel do
@Fivell
Fivell / gemfile_lock2geminabox.rb
Created December 13, 2016 11:08 — forked from flavio/gemfile_lock2geminabox.rb
Parse Gemfile.lock, download all gems from rubygems and then upload them to a local instance of geminabox
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
require 'fileutils'
require 'net/http'
require 'net/https'
require 'uri'
TMP_DIR = "/tmp/gems"
@Fivell
Fivell / rack-notags.rb
Created July 7, 2016 10:04 — forked from shinzui/rack-notags.rb
Rack middleware to clean post and get params
# # # #
# Rack::NoTags removes < and > from all incoming requests
# http://rbjl.net/12-rack-notags
#
# (c) 2009 - 2010 Jan Lelis
# This software is licensed under the MIT license.
# # # #
module Rack
#template for select option, I use it to show regions and draw country flags for each city
cityOptionTpl = (obj)->
_.tpl('CitySelectOption')(obj)
#helper for rendering option
renderCityOption = (entry)->
tplRes = cityOptionTpl({it:
title : entry.title
region : entry.region
country_name : entry.country_name
@Fivell
Fivell / wait_until.rb
Created June 2, 2016 11:45 — forked from metaskills/wait_until.rb
Never sleep() using Capybara!
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
click_link 'My HomeMarks'
within '#login_area' do
fill_in 'email', with: '[email protected]'
fill_in 'password', with: 'test'
@Fivell
Fivell / OUTPUT.md
Last active February 12, 2016 06:57 — forked from rmm5t/OUTPUT.md
How to properly introduce a new counter_cache to an existing Rails project.

Fast/efficient approach:

-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
   -> 1.3197s

Slow/naïve approach:

@Fivell
Fivell / cache_arbre.rb
Created February 12, 2016 06:24 — forked from zorab47/cache_arbre.rb
Arbre content caching for ActiveAdmin
# Caches Arbre elements in the `Rails.cache`.
#
# Yielding the first time adds to the output buffer regardless of the
# returned value. A cache miss must be handled separately from a hit
# to avoid double rendering.
#
# Returns yielded Arbre on cache miss OR an HTML string wrapped in
# an text node on cache hit.
def cache_arbre(context, *args, &block)
if controller.perform_caching