Skip to content

Instantly share code, notes, and snippets.

View olegnikitashin's full-sized avatar

Oleg Nikitashin olegnikitashin

  • Adjust
  • Berlin, Germany
View GitHub Profile
@olegnikitashin
olegnikitashin / example_activejob.rb
Created December 15, 2017 09:20 — forked from ChuckJHardy/example_activejob.rb
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
# from_cte_sql = ::Namespace::From.where_clause
# ..
from_table = Arel::Table.new(:from_lane)
to_table = Arel::Table.new(:to_lane)
rates_table = Arel::Table.new(:rates)
rates_table
.join(from_table).on(rates_table[:from_id].eq(from_table[:id]))
@olegnikitashin
olegnikitashin / support_cyrillic.sh
Created November 8, 2017 19:33 — forked from vladimir-e/support_cyrillic.sh
Support cyrillic / russian input in rails console and IRB
$ brew install openssl readline
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-p353
@olegnikitashin
olegnikitashin / gist:d93791efee42a586f8af7c98dede42b2
Created November 8, 2017 10:10 — forked from brianr/gist:58899467f58b80eee1eb
rollbar.js checkIgnore to ignore all "Script error" uncaught errors
_rollbarConfig = {
accessToken: 'your token',
captureUncaught: true,
payload: {
environment: 'production',
},
checkIgnore: function(isUncaught, args, payload) {
if (isUncaught && args[0] && args[0].indexOf('Script error') === 0) {
// ignore
return true;
@olegnikitashin
olegnikitashin / gist:8827427466c4b38a35539781537c4f4f
Created November 7, 2017 10:01 — forked from peymano/gist:2047968
Restore from a binary Postgres dump file
pg_restore --clean --no-acl --no-owner -d <database> -U <user> <filename.dump>
@olegnikitashin
olegnikitashin / gist:00915130f373e3394696a0579de75a0d
Created October 25, 2017 11:44 — forked from jpinnix/gist:547977
Help nginx+passenger serve static index pages
# Help nginx+passenger serve static index pages
# Site specific config
server {
listen 80;
server_name domain.com;
index index.html;
access_log logs/appname.access.log;
error_log logs/appname.error.log;
# I was encountering this exception
# Net::SMTPServerBusy: 401 4.1.7 Bad sender address syntax
# First I searched to see if there's any documentation around this issue,
# didn't find anything, so I wrote this snippet to find those invalid characters
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 25,
@olegnikitashin
olegnikitashin / unobtrusive_poller.js.coffee
Created October 3, 2017 11:43 — forked from barelyknown/unobtrusive_poller.js.coffee
Unobtrusive JavaScript solution for polling in a Rails application
###
Unobtrusive JavaScript solution for polling in a Rails application
Introduction:
Add a polling-placeholder wrapper div to any partial and add a data attribute
named poll that should be equal to "true" until you want to stop polling.
The default polling frequency will be used unless you provide an "interval" data
attribute which should be the number of milliseconds to use for the interval.
# new method
def exists?(item)
basket_items.exists?(source_id: item.id)
end
# old method
def exists_two?(item)
basket_items.select { |curr_item| curr_item.source_id == item.id }.any?
end
@olegnikitashin
olegnikitashin / arrayhash.rb
Created September 8, 2017 13:35 — forked from colindean/arrayhash.rb
Benchmarking Ruby Array vs Hash vs Set run with `ruby arrayhash.rb n` where n is the number of iterations
require 'benchmark'
require 'set'
ranges = [ "a".."z", "A".."Z", 0..9 ]
n = ARGV[0].to_i || 100
Benchmark.bm do |x|
x.report "array" do
n.times do
array = []