Skip to content

Instantly share code, notes, and snippets.

View nbulaj's full-sized avatar

Nikita Bulai nbulaj

View GitHub Profile
@hopsoft
hopsoft / db.rake
Last active July 5, 2024 14:52
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@cecilemuller
cecilemuller / letsencrypt_2020.md
Last active July 14, 2024 19:55
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@MarkMurphy
MarkMurphy / README.md
Last active February 5, 2024 19:59
Cursor based pagination for Rails models.

Example Usage

Users

id name
1 Jane
2 Max
3 John
4 Scott
@nbulaj
nbulaj / be_success_matcher.rb
Last active March 11, 2018 11:37
More informative RSpec #be_success matcher with negotiation
# spec/rails_helper.rb or spec/spec_helper.rb
# ...
# require custom matchers from the "support" directory:
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# -----
# support/matchers/be_success.rb
RSpec::Matchers.define :be_success do
match do |actual|

Давай представим ситуацию, когда тебе, в зависимости от какой-то логики нужно вернуть данные разного типа, например есть такая функция:

def function(foo, bar)
  result = if foo > bar
    10
  else
    "wrong"
  end
end
@cheeaun
cheeaun / rdrc2017.md
Last active October 11, 2017 06:56
RedDotRubyConf 2017 links & resources 😘
@vojtad
vojtad / benchmarks.md
Created November 21, 2018 00:00
Rails JSON rendering benchmarks

Rendered JSON is ~250 KB in size.

Runtime benchmarks

Warming up --------------------------------------
   render json: data    20.000  i/100ms
render json: data.to_json
                        27.000  i/100ms
render json: ActiveSupport::JSON.encode(data)
                        26.000  i/100ms

Output on Ruby 2.6, MacBook Pro (13-inch, 2017, 3.5 GHz Intel Core i7)

Note: I manually removed some BigDecimal deprecation warnings

Rehearsal ------------------------------------------------
as_json        0.122644   0.000508   0.123152 (  0.123823)
fast_jsonapi   0.184139   0.000829   0.184968 (  0.186195)
grape_entity   0.709880   0.003083   0.712963 (  0.714929)
blueprinter    0.220149   0.004481   0.224630 (  0.225596)
@khalilgharbaoui
khalilgharbaoui / db.rake
Created February 3, 2019 21:29 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# Original source: https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# Merged with: https://gist.github.com/kofronpi/37130f5ed670465b1fe2d170f754f8c6
# Benefits of: https://gist.github.com/e12e/e0c7d2cc1d30d18c8050b309a43450ac
# And fixes of: https://gist.github.com/joelvh/f50b8462611573cf9015e17d491a8a92
namespace :db do
desc 'Dumps the database to backups'
task dump: :environment do
dump_fmt = ensure_format(ENV['format'])
dump_sfx = suffix_for_format(dump_fmt)
backup_dir = backup_directory(Rails.env, create: true)
@Goloburda
Goloburda / javascriptClosure.js
Created November 26, 2019 08:07
JavaScript call function n-times.
// Function calls n-times before get '()';
const closureFn = firstArgument => {
let sum = firstArgument;
return function callMe(nextArgument) {
if (nextArgument) {
sum += nextArgument;
return callMe;
}
return sum;