Skip to content

Instantly share code, notes, and snippets.

$ docker run --rm -it ubuntu bash
root@b327e1a0640b:/# function file_ends_with_newline() {
> [[ $(tail -c1 "$1" | wc -l) -gt 0 ]]
> }
root@b327e1a0640b:/#
root@b327e1a0640b:/# touch empty.txt
root@b327e1a0640b:/#
root@b327e1a0640b:/#
root@b327e1a0640b:/# file_ends_with_newline empty.txt && echo ends in newline || echo does NOT end in newline
does NOT end in newline
@skehlet
skehlet / c
Last active January 18, 2018 17:22
#!/bin/bash
#
# Wrapper for any AWS-related command using aws that handles the 1 hour MFA token.
#
# Create an aws-role.config.json file in the same directory as this script that looks like:
# {
# "<your-profile-nickname>": {
# "profile": "<your-hub>",
# "region": "<your-default-region>",
# "mfa_arn": "<your-mfa-arn>",
#!/bin/bash
#
# Wrapper for any AWS-related command using aws that handles the 1 hour MFA token.
#
# Create an aws-role.config.json file in the same directory as this script that looks like:
# {
# "spoke-account": {
# "profile": "hub",
# "region": "us-west-2",
# "mfa_arn": "<your-mfa-arn>",
#!/bin/bash
set -e
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
unset AWS_DEFAULT_REGION
unset AWS_DEFAULT_OUTPUT
unset AWS_PROFILE
unset AWS_CA_BUNDLE
postgres=# SELECT version();
version
---------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.4 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44), 64-bit
(1 row)
postgres=# SELECT name, current_setting(name), SOURCE
postgres-# FROM pg_settings
postgres-# WHERE SOURCE NOT IN ('default', 'override');
name | current_setting | source
@skehlet
skehlet / gist:08aeed3d06f1c35bc780
Created March 17, 2016 18:58
my custom postgres settings
postgres=# SELECT version();
version
---------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.5 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44), 64-bit
(1 row)
postgres=# SELECT name, current_setting(name), SOURCE
postgres-# FROM pg_settings
postgres-# WHERE SOURCE NOT IN ('default', 'override');
name | current_setting | source
SELECT
COALESCE(blockingl.relation::regclass::text,blockingl.locktype) as locked_item,
blockeda.procpid AS blocked_pid,
blockeda.current_query as blocked_query,
blockedl.mode as blocked_mode,
blockinga.procpid AS blocking_pid,
blockinga.current_query as blocking_query,
blockingl.mode as blocking_mode
FROM pg_catalog.pg_locks blockedl
JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.procpid
@skehlet
skehlet / gist:fd4945f9c9ce6ed075f1
Created August 28, 2015 16:53
my non-default postgres config
psql (9.4.4)
Type "help" for help.
postgres=#
postgres=# SELECT name, current_setting(name), source
postgres-# FROM pg_settings
postgres-# WHERE source NOT IN ('default', 'override');
name | current_setting | source
---------------------------------+----------------------------------+--------------------
application_name | psql | client
listen_addresses = '*'
port = 5432
max_connections = 300
shared_buffers = 2GB
work_mem = 10MB
maintenance_work_mem = 256MB
max_stack_depth = 8MB
wal_buffers = 16MB
checkpoint_segments = 32
checkpoint_completion_target = .9
mydb=> SELECT name, current_setting(name), source
mydb-> FROM pg_settings
mydb-> WHERE source NOT IN ('default', 'override');
name | current_setting | source
---------------------------------+------------------+--------------------
application_name | psql | client
archive_command | exit 0 | configuration file
archive_mode | on | configuration file
autovacuum | on | configuration file
autovacuum_analyze_scale_factor | 0.1 | configuration file