Skip to content

Instantly share code, notes, and snippets.

View igorb's full-sized avatar

Igor Bilan igorb

View GitHub Profile
@igorb
igorb / search_controller.rb
Created March 23, 2017 17:27
Refactored Search RoR
class SearchesController < ApplicationController
def show
# 1) User model have a 'title' - an alias to full_name to search by title
# 2) scope :like_a, -> (title) { where('lower(title) LIKE ?', "%#{title}%")
# 3) use ActiveModelSerializer: or serialize a specific collection:
# (ActiveModel::ArraySerializer.new(items, each_serializer: ItemSerializer)) should be like [{ id, title, url }]
render json: SearchServices.new(current_user, title).results
end
@igorb
igorb / search.js
Created March 23, 2017 17:26
Refactored Search JS
$('#search').keyup($.throttle(function() {
// Will only execute 300ms after the last keypress.
if ($('#search').val().length > 0) {
sendSearchAjaxRequest();
} else {
$('.search_dropdown').hide()
}
}, 300));
2015-09-27T16:49:32.499Z 20607 TID-oxqcy0uyc Gnip::DownloadWorker JID-a5fe6232f54b78156e1068a4 INFO: done: 5.392 sec
2015-09-27T16:49:32.506Z 20607 TID-oxqdn2bn0 Gnip::DownloadWorker JID-6c6935f07def12d984bb7b82 INFO: start
2015-09-27T16:49:32.515Z 20607 TID-oxqcy0uyc Gnip::DownloadWorker JID-232e8e816a9b956bc7221669 INFO: start
2015-09-27T16:49:32.516Z 20607 TID-oxqdn67x0 Gnip::DownloadWorker JID-376da939d0e1b0c915b59a1c INFO: start
downloading /Users/igorb/work/verifeed-twitter/downloads/7q29mfvq74/2015/08/01/01_40_activities.json...
2015-09-27T16:49:33.225Z 20607 TID-oxqe01c8w Gnip::DownloadWorker JID-1686444e5f46ee87f5ca8db5 INFO: done: 6.133 sec
2015-09-27T16:49:33.232Z 20607 TID-oxqe01c8w Gnip::DownloadWorker JID-10cdf58624f007f44bbb48f3 INFO: start
downloading /Users/igorb/work/verifeed-twitter/downloads/7q29mfvq74/2015/08/01/01_50_activities.json...
2015-09-27T16:49:34.791Z 20607 TID-oxqe01myg Gnip::DownloadWorker JID-c2e53aacf2a8eee9efeac039 INFO: done: 7.645 sec
2015-09-27T16:49:34.805Z 20607 TID-ox
@igorb
igorb / gist:8696fab31ef8e409913e
Created March 5, 2015 10:04
remove branches & temporary files
git checkout master && git branch | grep -v "master" | xargs git branch -D
find . -name \*.swo -type f -delete
find . -name \*.swp -type f -delete
require 'spec/support/grep_matcher'
describe do
disallow_presence_of pattern: "send(.*#",
location: "app/",
description: "Do not use dynamic method invocations",
failure: "Please change dynamic method call to something more sane."
end

In order to demo your feature specs, follow these steps:

  1. Add capybara, poltergeist, launchy and selenium-webdriver to your Gemfile under test and development group.
  2. Add the attached demo helper to your spec/support.
  3. Add the capybara config to your spec_helper file.
  4. Run bundle install.
  5. Write your feature with its scenario specs.
  6. Put a demo filter on each scenario you want to demo. ( refer to the example below )
  7. Run bundle exec rspec spec.
@igorb
igorb / links.textile
Created September 30, 2013 12:00 — forked from ilatif/links.textile
@igorb
igorb / Rename_S3_resources.rb
Created September 4, 2013 09:06
rake task to rename old S3 resources according to new URL encoding
# Maintenance script needed to rename old S3 resources according to new URL encoding
desc "One-time renaming of all the amazon s3 content"
task :rename_s3_files do |t, args|
require 'aws/s3'
require Rails.root.join('app', 'helpers', 'paperclip_sanitization_helper.rb')
cred = YAML.load(File.open("#{Rails.root}/config/s3.yml"))[Rails.env].symbolize_keys!
attr_bucket = cred.delete(:bucket)
AWS::S3::Base.establish_connection! cred
@igorb
igorb / dump_restore_scp.md
Created August 23, 2013 07:55
backup/restore mysql backup/restore redis scp

1. backup/restore mysql

backup: mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore: mysql -u root -p[root_password] [database_name] < dumpfilename.sql

mysqldump -u appzone -pP@rtnerpedia appzone_qa > 1.sql

2. backup/restore redis(http://code.google.com/p/redis-dump/)

def login_as(user)
raise "Was expecting a User. Got a #{user.class} instead. Exiting." if user.class != User
@controller.request.env['warden'] = mock(
Warden,
:authenticate => user,
:authenticate! => user,
:authenticated? => true,
:authenticate? => true
)
user.last_sign_in_at = Time.now