Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
bogdanRada / or_scopes.rb
Created February 14, 2018 14:54 — forked from craigweston/or_scopes.rb
OR'ing scopes
module ActiveRecord
module Querying
delegate :or, :to => :all
end
end
module ActiveRecord
module QueryMethods
# OrChain objects act as placeholder for queries in which #or does not have any parameter.
# In this case, #or must be chained with any other relation method to return a new relation.
@bogdanRada
bogdanRada / ActiveRecordUnionScope.rb
Last active February 7, 2018 17:56 — forked from lsiden/gist:260167a4d3574a580d97
module ActiveRecord::UnionScope
#https://gist.github.com/tlowrimore/5162327
#http://stackoverflow.com/a/15413611/270511
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
@bogdanRada
bogdanRada / postgres-cheatsheet.md
Created February 2, 2018 07:18 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@bogdanRada
bogdanRada / backup.md
Created February 2, 2018 07:16 — forked from ouyangzhiping/backup.md
Backing Up PostgreSQL With Backup and Whatever Gems with Drobpbox api

create backup project

bundle exec backup generate:model --trigger my_backup --archives --storages='dropbox' --compressors='gzip' --notifiers='mail' --databases="postgresql"

dropbox api

https://www.dropbox.com/developers/apps

@bogdanRada
bogdanRada / compress_assets_7z.rake
Last active February 2, 2018 07:14 — forked from fxn/gist:427dca61ec44adf8253b
gzip assets with Capistrano
task :compress_assets_7z do
on roles(:app) do
assets_path = release_path.join('public', fetch(:assets_prefix))
execute "find -L #{assets_path} \\( -name *.js -o -name *.css -o -name *.ico \\) -exec bash -c '[ ! -f {}.gz ] && 7z a -tgzip -mx=9 {}.gz {}' \\; "
end
end
after 'deploy:normalize_assets', 'compress_assets_7z'
@bogdanRada
bogdanRada / generate_and_deploy_assets.rb
Created January 31, 2018 07:16 — forked from micahbrich/generate_and_deploy_assets.rb
capistrano recipe for moving public files to s3
desc "Generate and deploy assets"
task :deploy_assets, :roles => :app do
# get the previous timestamp
old_timestamp = File.read("config/deploy_timestamp").to_i rescue 0
# generate timestamp into config/deploy_timestamp
timestamp = Time.now.to_i
File.open("config/deploy_timestamp", 'w') do |f|
f.write(timestamp)
end
@bogdanRada
bogdanRada / better-nodejs-require-paths.md
Created January 9, 2018 07:51 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@bogdanRada
bogdanRada / hash_deep_diff.rb
Created January 4, 2018 13:44 — forked from henrik/hash_deep_diff.rb
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@bogdanRada
bogdanRada / darkify_slack.sh
Created December 11, 2017 07:49 — forked from jkremser/darkify_slack.sh
dark slack
#! /bin/bash
#since slack 2.6.3 there is some hack in that file, so make sure this piece of code goes before the:
#start(assignIn({}, require('electron').remote.getGlobal('loadSettings'), { windowType: 'WEBAPP' }));
#..line
cat << 'EOF' >> /usr/lib/slack/resources/app.asar.unpacked/src/static/ssb-interop.js
document.addEventListener('DOMContentLoaded', function() {
$.ajax({
url: 'https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css',
@bogdanRada
bogdanRada / delegate_matcher.rb
Created September 5, 2017 12:04 — forked from purp/delegate_matcher.rb
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:day).to(:created_at) }
# it { should delegate(:month, :year).to(:created_at) }
# end
#