Skip to content

Instantly share code, notes, and snippets.

View dimanyc's full-sized avatar

Dimitry Nazarov dimanyc

View GitHub Profile
@bartoszkopinski
bartoszkopinski / find_vs_where_benchmark.rb
Last active May 8, 2016 23:59
Mongoid benchmark, #find vs. #where, #only vs. no #only
n = 1_000
id = User.first.id
profile = User.only(:profile).find(id).profile
Benchmark.bm(50) do |x|
x.report('User.find(id).profile') do
n.times{ User.find(id).profile }
end
@metaskills
metaskills / gist:4065702
Last active September 2, 2016 22:17
Example Of Other/Legacy DB Connection Management & Query Cache
# Assuming you champioin your other DB connection with a class.
module OtherDb
class Connection < ActiveRecord::Base
establish_connection :other_db
self.abstract_class = true
end
end
# Alway use the connection for other/legacy connections.
@zealot128
zealot128 / crawler.rb
Last active August 15, 2018 12:22
Web Crawler Helper class based upon Poltergeist (PhantomJS).Using Capybara as framework for building webcrawlers is surprisingly convenient
class ExampleCrawler < PoltergeistCrawler
def crawl
visit "https://news.ycombinator.com/"
click_on "More"
page.evaluate_script("window.location = '/'")
end
end
ExampleCrawler.new.crawl
@DannyDelott
DannyDelott / getTimeLeft().js
Last active July 6, 2019 13:22
Show time left until noon using Moment.js
var getTimeLeft = function(){
var now = moment();
var deadline = now.clone().hour(12).minute(0),second(0);
if(now.isAfter(deadline) {
// disable RSVP button here
return ‘Closed’;
}else {
// enable RSVP button here
// returns “in x hours”, “in x minutes”, “in a few seconds”
return deadline.from(now);
@agmcleod
agmcleod / home_spec.rb
Created February 28, 2012 05:07
shopify api integration testing
require 'spec_helper'
describe "home" do
before do
@domain = "myshop.myshopify.com"
@token = SecureRandom.hex(16)
@shopify_session = ShopifyAPI::Session.new(@domain, @token)
end
@eebs
eebs / sql_statement_profiling.rb
Created December 17, 2019 21:29
spec/support/sql_statement_profiling.rb
RSpec.configure do |config|
example_sql_counts = Hash.new(0)
config.around(:example) do |procsy|
sql_count = 0
callback = ->(*args) { sql_count +=1 }
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
procsy.call
end
@PierreMage
PierreMage / PowerShell-profile.ps1
Last active October 1, 2022 00:33
Make your Windows command line better with doskey
# http://technet.microsoft.com/en-us/library/ee692685.aspx
# F7 = history
# Alt+F7 = history -c
# F8 = Ctrl+R
Set-Location C:
# Easier navigation
Set-Alias o start
function oo {start .}
@delameko
delameko / upgrade-postgres-9.5-to-9.6.md
Last active August 22, 2023 08:22 — forked from johanndt/upgrade-postgres-9.3-to-9.5.md
Upgrading PostgreSQL from 9.5 to 9.6 on Ubuntu 16.04

TL;DR

Install Postgres 9.6, and then:

sudo pg_dropcluster 9.6 main --stop
sudo pg_upgradecluster 9.5 main
sudo pg_dropcluster 9.5 main
@p1nox
p1nox / postgresql_configuration_on_ubuntu_for_rails.md
Last active November 29, 2023 04:38
PostgreSQL configuration without password on Ubuntu for Rails

Abstract

You could have postgre installed on localhost with password (or without user or password seted after instalation) but if we are developing we really don't need password, so configuring postgre server without password for all your rails project is usefull.

Install Postgre packages

  • postgresql
  • postgresql-client
  • libpq-dev
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')