Skip to content

Instantly share code, notes, and snippets.

View Irostovsky's full-sized avatar

Ivan Rostovsky Irostovsky

View GitHub Profile
@Irostovsky
Irostovsky / Problem
Created October 7, 2011 08:08 — forked from clemens/Problem
When the constraints block is active, I get RoutingError: No route matches "/" when going to localhost:3000. If I comment the block out, it works just fine. But I need both:
http://example.com should render PagesController#show with params[:permalink] being 'index'
http://clemensk.example.com should render ProfilesController#show
Hints anyone?
Thanks!
@Irostovsky
Irostovsky / gist:30508f8e1d189034535a
Last active August 29, 2015 14:10
Sublime 3 + PhantomJS path not found
After upgrading OSX, the cucumber features down with *phantomJS not found* error.
In terminal was all ok.
Soltion:
Just install https://github.com/int3h/SublimeFixMacPath plugin for ST3.
Dear Candidate
Thank you for applying for the Ruby on Rails Developer position at Product Madness. In order to take you through to the next stage interview we would like you to complete a short skill text.
With reference to the below red text please add your code instead of the '# Put your code here’ line. You need to implement developer class so DataBase#find_developer method does not fail. Try to add as few lines of code as possible.
class Developer
# Put your code here
end
class Developer
def initialize
@chain = []
end
def are
@chain << "I"
self
end
def flattify(array)
array.each_with_object([]) do |element, flattened|
flattened.push *(element.is_a?(Array) ? flattify(element) : element)
end
end
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04
How To Install and Configure Redis on Ubuntu 16.04
PostedMay 11, 2016 51.6k views NOSQL REDIS UBUNTU UBUNTU 16.04
Introduction
Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. In this guide, we will demonstrate how to install and configure Redis on an Ubuntu 16.04 server.
Prerequisites
To complete this guide, you will need access to an Ubuntu 16.04 server. You will need a non-root user with sudo privileges to perform the administrative functions required for this process. You can learn how to set up an account with these privileges by following our Ubuntu 16.04 initial server setup guide.
@Irostovsky
Irostovsky / gist:895705a15e11f04f3032538a241446c3
Created February 10, 2017 12:36
Equi: Find an index in an array such that its prefix sum equals its suffix sum.
This is a demo task.
A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.
A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
For example, consider the following array A consisting of N = 8 elements:
A[0] = -1
A[1] = 3
module AuthenticityTokenCatcher
extend ActiveSupport::Concern
included do
rescue_from ActionController::InvalidAuthenticityToken do |exception|
if request.referrer
flash[:error] = I18n.t :authenticit_token_error
redirect_to request.referrer
else
raise exception
end
Dir["app/assets/images/*"].each do |image|
name = File.basename(image)
if Dir.glob("**/*").reject {|fn| File.directory?(fn) }.
map{|fn| File.read(fn).include?(name) ? fn : nil }.any?
p image
else
p "To delete: #{image}"
File.delete image
end
end
@Irostovsky
Irostovsky / tasks_1.rb
Created July 31, 2017 09:12
Let we have Post(title, body) -> Comments(body). Write the active record query to get all posts, where "query" is into title or body or comment.
# Let we have Post(title, body) -> Comments(body).
# Write the active record query to get all posts, where "query" is into title or body or comment.
class Post < ActiveRecord::Base
#title, body
has_many :comments
scope :search, ->(text) {
wildcard_search = "%#{text}%"
joins(:comments).where("title ILIKE :search OR body ILIKE :search OR comments.body ILIKE :search", search: wildcard_search)