Skip to content

Instantly share code, notes, and snippets.

class Post < ActiveRecord::Base
after_commit :notify_editors, on: :create
after_commit :generate_feed_item, on: :create
private
def notify_editors
EditorMailer.send_notification(self).deliver_later
end
def generate_feed_item
@nburkley
nburkley / vefify_ssl_documents.sh
Created April 23, 2018 11:06
Verifying SSL Cert, Key and CSR match
# Get CSR MD5
openssl req -noout -modulus -in my_csr.csr | openssl md5
# Get cert MD5
openssl x509 -noout -modulus -in my_cert.crt | openssl md5
# Get Key MD5
openssl rsa -noout -modulus -in my_key.key | openssl md5
@nburkley
nburkley / multilpe_when_case.ex
Created March 9, 2018 16:56
Multiple matches for when
case testvalue do
n when n in [200, 400] ->
true
_ ->
false
end
@nburkley
nburkley / prevent_test_timeout.ex
Created February 15, 2018 09:46
Prevent Timeout in ExUnit tests
# in test/test_helper.exs
ExUnit.configure(timeout: :infinity)
ExUnit.start
# ...
# when using ecto change/add ownership timeout in config.exs
config :myapp, MyApp.Repo,
adapter: Ecto.Adapters.Postgres, # not important
username: "mydatabaseuser", # not important
database: "myapp_test", # not important
defmodule Tester do
defstruct [:first, :second]
def foo_to_bar(struct = %{__struct__: struct_module}) do
updated_list =
struct
|> Map.from_struct
|> Enum.map(&transform_value/1)
struct(struct_module, updated_list)
end
@nburkley
nburkley / Neovim&iTerm_Ctrl+h_fix.md
Created April 10, 2017 14:36
Enables Ctrl+h shortcut when using Neovim with iTerm2

neovim/neovim#2048 (comment)

  • Edit -> Preferences -> Keys
  • Press +
  • Press Ctrl+h as Keyboard Shortcut
  • Choose "Send Escape Sequence as Action"
  • Type [104;5u for Esc+
@nburkley
nburkley / start_rails_server.sh
Created September 5, 2016 12:38
Start puma rails server binding to a host and port
# binding to localhost
rails s -b 127.0.0.1 -p 3000
# bind to lvh.me
rails s -b lvh.me -p 3000
@nburkley
nburkley / tables_with_rowcount.sql
Created August 25, 2016 09:56
Get all tables with their number of rows in PostgreSQL
SELECT
pgClass.relname AS tableName,
pgClass.reltuples AS rowCount
FROM
pg_class pgClass
LEFT JOIN
pg_namespace pgNamespace ON (pgNamespace.oid = pgClass.relnamespace)
WHERE
pgNamespace.nspname NOT IN ('pg_catalog', 'information_schema') AND
pgClass.relkind='r';
@nburkley
nburkley / BulkUserEmailByLocale.rb
Last active December 30, 2019 11:14
Use `bbc` instead of `to` to hide list of recipienta
users_by_locale.each do |locale, locale_users|
I18n.with_locale(locale) do
mail(
bcc: locale_users.map(&:email),
subject: I18n.t('user_mailer.new_follower.subject')
)
end
end
private
@nburkley
nburkley / gist:b23cd061c3565f4965e4
Created June 19, 2015 12:22
Importing database dump into docker application

In your compose file, map volum to a local folder that contains the database dump file

db:
  image: postgres:9.4.1
  volumes:
    - tmp:/tmp/dumps

Run the application using docker-compose up