Skip to content

Instantly share code, notes, and snippets.

@rbrooks
rbrooks / font-awesome-collection.rb
Created March 7, 2013 16:26
Output the entire Font Awesome icon set to the browser, in Decimal-Entity Notation.
%span{ style: "font-family: 'FontAwesome';" }
- (61440..61720).each do |n|
= ('&#' + n.to_s).html_safe;
-- MySQL
-- Search all tables, databse-wide, for a column name.
-- EXACT MATCH
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('col_name')
AND TABLE_SCHEMA='db_name';
-- PARTIAL MATCH
@rbrooks
rbrooks / vagrant_plugin_installation_fail.sh
Last active July 25, 2016 21:24
Vagrant Plugin installation fails due to Gem installation failure by way of Bundler
# Someetimes `vagrant up` fails with a message like:
# Installing the 'vagrant-butcher' plugin. This can take a few minutes...
# Bundler, the underlying system Vagrant uses to install plugins,
# reported an error. The error is shown below. These errors are usually
# caused by misconfigured plugin installations or transient network
# issues. The error from Bundler is:
#
# An error occurred while installing rack (2.0.1), and Bundler cannot continue.
# Make sure that `gem install rack -v '2.0.1'` succeeds before bundling.
@rbrooks
rbrooks / whitelist_dict.py
Created August 19, 2016 17:48
Whitelist Dictionary
def whitelist_dict(dic, keys):
# Filters a Dict by only including certain keys.
key_set = set(keys) & set(dic.keys())
return { key: dic[key] for key in key_set }
@rbrooks
rbrooks / merge_dicts.py
Created August 19, 2016 17:49
Merge Dictionaries
def merge_dicts(x, y):
z = x.copy()
z.update(y)
return z
@rbrooks
rbrooks / jwt.js
Last active September 9, 2016 14:32
// First:
// npm install jsonwebtoken
// https://github.com/auth0/node-jsonwebtoken
//
// Then launch `node` shell.
var jwtLib = require('jsonwebtoken');
var jwtStr = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb250ZXh0Ijoic3N2cHpmYWZoZCIsInN1YiI6InVybjpzd2l0Y2hjb25uZXg6dXNlcjo0MCIsImlzcyI6InVybjpzd2l0Y2hjb25uZXg6c3ZjOmF1dGgiLCJleHAiOjE0NzMzNjMxNTMsImlhdCI6MTQ3MzM2Mjg1MywiYXVkIjoidXJuOnN3aXRjaGNvbm5leDpzdmM6bW9iaWxlIn0.tZj08Vlci3g7SYUm-8MxfH_Ty_1rtBGgUzC311-NSaU';
@rbrooks
rbrooks / create-pem-keypair.sh
Created October 27, 2016 14:45
Create Public/Private keypair in PEM format for JWTs
# ssh-keygen creates Keys that aren't in PEM format, but JWT tokens mandate
# PEM format. So, we have to convert them with OpenSSL.
ssh-keygen -t rsa -b 4096 -f jwtRS256.key
# Press Enter when prompted for passphrase.
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@rbrooks
rbrooks / custom_log_level.py
Last active January 17, 2017 22:48
Custom Log Level in Python
logging.addLevelName(51, 'AUTH')
log = logging.getLogger()
# log.setLevel(10)
print log.level
print log.getEffectiveLevel()
log.log(10, '********** 10 ************')
log.log(20, '********** 20 ************')
log.log(30, '********** 30 ************')
@rbrooks
rbrooks / Postgres-Table-and-Index-Size-Metrics.sql
Created December 8, 2020 00:40
Postgres Table and Index Size Metrics
WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS
(select inhrelid, inhparent
FROM pg_inherits
UNION
SELECT child.inhrelid, parent.inhparent
FROM pg_inherit child, pg_inherits parent
WHERE child.inhparent = parent.inhrelid),
pg_inherit_short AS (SELECT * FROM pg_inherit WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit))
SELECT table_schema
, TABLE_NAME
@rbrooks
rbrooks / pg-index-usage.sql
Created December 8, 2020 01:32
Postgres Index Usage Metrics
-- Index Size and Usage
SELECT
t.schemaname,
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(indexrelname)::text)) AS index_size,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'