Skip to content

Instantly share code, notes, and snippets.

0x00e74CB7504cAf13C163A5BEa941A1C8fbe7afd7
Hotspot::Page.where(page_type: 'Advertising').find_each do |row|
button_type = case row.redirect_text
when nil, '' then 'full_screen'
when 'верх' then 'top_screen'
when 'центр' then 'middle_screen'
when 'низ' then 'bottom_screen'
else 'button_screen'
end
row.update_columns(redirect_text: '', button_type: button_type)
@sigra
sigra / ruby.rb
Created September 29, 2015 10:34
def clean_whitespaces
%i(tag router_id mac_address access_code).each do |field|
unless self.send(field).nil?
self.send("#{field}=", self.send(field).squish.strip)
end
end
end
[*'A'..'Z', *'a'..'z', *0..9].shuffle.sample(8).join
@sigra
sigra / application_controller.rb
Created June 29, 2015 07:33
Rails. Access to flash messages from lib classes
class ApplicationController < ActionController::Base
before_filter :globalize_session, :error_to_flash
protected
def globalize_session
Thread.current[:session] = session
end
def error_to_flash
@sigra
sigra / Gemfile
Created January 2, 2015 15:10
Rails multiple currency support
gem 'eu_central_bank'
gem 'geocoder'
gem 'money-rails'
# for rate worker
gem 'sidekiq'
gem 'sidetiq'
gem 'sinatra', require: false
@sigra
sigra / deploy.rb
Last active May 1, 2017 12:54 — forked from trushkevich/deploy.rb
private_pub Capistrano 3 with Thin on Unix socket
set :private_pub_pid, -> { "#{current_path}/tmp/pids/private_pub.pid" }
set :private_pub_socket, -> { "#{current_path}/tmp/sockets/private_pub.sock" }
set :private_pub_rackup, -> { "#{current_path}/private_pub.ru" }
namespace :private_pub do
desc "Start private_pub server"
task :start do
on roles(:app) do
within release_path do
with rails_env: fetch(:stage) do
@sigra
sigra / nginx.conf
Created December 25, 2014 11:41
Nginx configuration for websockets using Thin
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream thin_websocket {
server unix:/path/to/thin/socket/file.sock fail_timeout=0;
}
server {