Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ostinelli's full-sized avatar

Roberto Ostinelli ostinelli

View GitHub Profile
@ostinelli
ostinelli / Preferences.Sublime-settings
Created April 10, 2017 13:04
Sublime Preferences.
{
"ensure_newline_at_eof_on_save": true,
"font_size": 12.0,
"trim_trailing_white_space_on_save": true
}
@ostinelli
ostinelli / aws_acl_updater.rb
Last active January 11, 2017 15:33
Batch update ACL permissions on AWS.
# add AWS credentials to ENV variables or modify the script to pass in credentials
require 'thread'
require 'aws-sdk'
# settings
region = 'my-region'
bucket = 'my-bucket'
prefix = 'my-prefix'
acl = "private"
parallel = 25
@ostinelli
ostinelli / reloader.rb
Last active July 1, 2018 08:18
Reload an initializer file on every request in Rails.
# add this into application.rb
initializer_file = Rails.root.join('config', 'initializers', 'my_initializer.rb')
reloader = ActiveSupport::FileUpdateChecker.new([initializer_file]) do
load initializer_file
end
ActiveSupport::Reloader.to_prepare do
reloader.execute
end
@ostinelli
ostinelli / activerecord_callback.md
Last active July 6, 2018 01:57
ActiveRecord callback when connection is made

The ConnectionAdapter defines two callbacks :checkout (connect) and :checkin (disconnect).

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.set_callback :checkout, :after do
  raw_connection
end

Source.

@ostinelli
ostinelli / simulator.sh
Created March 22, 2016 10:11
Open iOS simulator directly from console
alias simulator='open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'
@ostinelli
ostinelli / logentries_manual_setup.md
Last active August 11, 2022 21:37
How to use a single Logentries account on Heroku.

If you have multiple applications on Heroku and would like to use a single Logentries account for all of them, this is how you do it. Basically, do not use add-ons, and send all drains to your account.

  • In your Logentries account, click on Add Log
  • Select Manual
  • In the form that appears, input the following:
    • Log Name: access.log
    • Select Set: new set named myapp-{environment}, for instance myapp-staging (at least, this is how I like to name my entries)
    • Select the Plain TCP, UDP - logs are sent via syslog option
  • Click on Create Log Token
@ostinelli
ostinelli / import.sh
Created November 10, 2015 17:24
Heroku Import database
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d {database} sql.dump
@ostinelli
ostinelli / stub_environment.rb
Created September 10, 2015 14:10
Stub Rails environment
def stub_rails_env_as(env)
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new(env.to_s))
end
@ostinelli
ostinelli / erlang-release-init.d.md
Last active September 15, 2019 12:18
Erlang Release init.d script

Erlang Release init.d script

If you have packaged your application into a release generated with Rebar, you might want to have the following:

  • The release started on system boot.
  • The VM monitored and restarted it if it crashes.

Use HEART

HEART is the Heartbeat Monitoring of an Erlang Runtime System. The purpose of the heart port program is to check that the Erlang runtime system it is supervising is still running, so that if the VM crashes or becomes unresponsive, it is restarted.

@ostinelli
ostinelli / openssl_common_operations.md
Last active February 12, 2020 13:54
OpenSSL common operations.

Open SSL common operations

Generate a new Private key and Certificate Signing Request

$ openssl req -out server.csr -new -newkey rsa:2048 -nodes -keyout server.key

Generate a self-signed certificate and private key

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt