Skip to content

Instantly share code, notes, and snippets.

@nburkley
nburkley / gist:93b88b0732c6c8fbe78b
Last active August 29, 2015 14:04
Find 10 largest tables in DB
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 10;
@nburkley
nburkley / designer.html
Created September 4, 2014 14:45
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu-button/core-menu-button.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-pages/core-pages.html">
<polymer-element name="my-element">
@nburkley
nburkley / gist:2059c70686f2823e8566
Created March 18, 2015 10:33
Restore data only form heroku database dump
pg_restore --verbose --data-only --no-acl --no-owner -h localhost -U db_user -d db_name filename.dump
@nburkley
nburkley / gist:d00fc3fc4d8445da0988
Created June 17, 2015 13:38
Adding Multi-domain SSL certs to Herkou

When adding a multi-domain certificat to Herkou, the standard certficate update/add command results in

$> herkou certs:update cert_bundle.pem server.crt server.key

Resolving trust chain... failed
 !    No certificate given is a domain name certificate.

To get this to work you need to add the --bypass parameter

@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

@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 / 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 / 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 / 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+
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