Skip to content

Instantly share code, notes, and snippets.

View emilpetkov's full-sized avatar

Emil Petkov emilpetkov

View GitHub Profile
cache:
bundler: true
directories:
- reports
before_script:
- bundle clean --force # remove any cached brakeman from when it was in the Gemfile
script:
- script/brakeman
@patshaughnessy
patshaughnessy / gist:70519495343412504686
Last active April 13, 2025 16:58
How to Debug Postgres using LLDB on a Mac
This note explains how to build Postgres from source and setup to debug it using LLDB on a Mac. I used this technique to research this article:
http://patshaughnessy.net/2014/10/13/following-a-select-statement-through-postgres-internals
1. Shut down existing postgres if necessary - you don’t want to mess up your existing DB or work :)
$ ps aux | grep postgres
pat 456 0.0 0.0 2503812 828 ?? Ss Sun10AM 0:11.59 postgres: stats collector process
pat 455 0.0 0.0 2649692 2536 ?? Ss Sun10AM 0:05.00 postgres: autovacuum launcher process
pat 454 0.0 0.0 2640476 304 ?? Ss Sun10AM 0:00.74 postgres: wal writer process
pat 453 0.0 0.0 2640476 336 ?? Ss Sun10AM 0:00.76 postgres: writer process
##Create a migration
### rails g migration make_unicode_friendly
class MakeUnicodeFriendly < ActiveRecord::Migration
def change
alter_database_and_tables_charsets "utf8", "utf8_general_ci"
end
private
def alter_database_and_tables_charsets charset = default_charset, collation = default_collation
@peterhellberg
peterhellberg / gateway_deploy.rb
Created December 17, 2014 16:24
Capistrano deploy via gateway host
set :user, 'username'
set :gateway, 'example.com'
set :ssh_options, {
user: fetch(:user),
forward_agent: false,
proxy: Net::SSH::Proxy::Command.new(
"ssh -l #{fetch(:user)} #{fetch(:gateway)} -W %h:%p"
)
}
@apotonick
apotonick / wishlist.rb
Last active November 21, 2018 07:19
My Ruby Wishlist
# Ruby Wishlist
## Removals
* finalize! method for classes
* Remove constant_finding/loading at runtime, it always breaks.
## Module.freeze
Remove the ability to dynamically change code at runtime
@somebox
somebox / presenters.md
Last active March 26, 2022 02:12
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@skanev
skanev / generate.rb
Last active January 3, 2017 15:26
The peculiarities of Relation#distinct and Relation#count
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :activities do |t|
t.string :day
t.string :name
end
end
@lfbittencourt
lfbittencourt / clear_tags.rb
Last active March 21, 2017 11:03
This Ruby script removes all local and remote tags in a single-line way, so you don't need supply your credentials several times. Optionally, you can remove only tags greater than a specific version.
#!/usr/bin/env ruby
# Only tags >= min_tag will be removed.
min_tag = '0.0.0'
tags = `git tag`.split(/\s+/).select do |t|
Gem::Version.new(t) >= Gem::Version.new(min_tag)
end
`git tag -d #{tags.join ' '}`
`git push origin #{tags.map { |t| ':' + t }.join ' '}`
@afn
afn / gist:c04ccfe71d648763b306
Created June 12, 2014 15:35
Restart phantomjs when it hangs
# Borrowed from https://github.com/y310/rspec-retry/blob/master/lib/rspec/retry.rb
CAPYBARA_TIMEOUT_RETRIES = 3
RSpec.configure do |config|
config.around(:each, type: :feature) do |ex|
example = RSpec.current_example
CAPYBARA_TIMEOUT_RETRIES.times do |i|
example.instance_variable_set('@exception', nil)
self.instance_variable_set('@__memoized', nil) # clear let variables
@kunev
kunev / pre-commit
Last active August 29, 2015 14:00
python pre-commit hook
#!/bin/sh
# Get all the python files staged for committing
py_files=`git diff --name-only HEAD|grep '.py$'`
# If we;re trying to commit a pdb.set_trace() display an error message and exit right away with status 1
grep -n 'pdb.set_trace()' $py_files && echo -e "\033[1;31m Debugger statements!!!\033[0m" && exit 1
# Run pyflakes on all the files beign committed and exit with status 0 if there are no errors, else show error message
pyflakes $py_files && exit || echo -e "\033[1;31m Lint error!\033[0m"
# If we’re here, then pyflakes failed, exit with status 1