Skip to content

Instantly share code, notes, and snippets.

View dimanyc's full-sized avatar

Dimitry Nazarov dimanyc

View GitHub Profile
@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
@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
@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);
@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
@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 .}
@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
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active March 7, 2024 03:56
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@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
@jareware
jareware / SCSS.md
Last active April 23, 2024 22:13
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@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.