Skip to content

Instantly share code, notes, and snippets.

@sdrew
sdrew / upgrade_psql
Created May 5, 2015 11:03
Upgrade PSQL
apt-get install postgresql-9.3 pgadmin3 postgresql-contrib-9.3 # contrib is needed for hstore
su - postgres
psql -p 5432 -c "\l" # check the collation column and note that (for ex. en_US.UTF8)
psql -p 5433 -c "\l" # If the collation is the same, continue. If not, recreate the 9.3 cluster with the following commands
# Recreate 9.3 cluster with collation from old 9.1 cluster
# pg_ctlcluster 9.3 main stop
# pg_dropcluster 9.3 main
# export LC_ALL="<old-clusters-collation>" # For ex. LC_ALL="en_US.UTF8"
@sdrew
sdrew / gist:d6a582709bce16c46b30
Created February 17, 2015 07:23
Ubuntu SFTP CHROOT
https://en.wikibooks.org/wiki/OpenSSH/Cookbook/SFTP
Subsystem sftp internal-sftp
Match Group sftp-users
ChrootDirectory /home
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp -d %u
groupadd --system sftp-users
@sdrew
sdrew / signals.sh
Created May 24, 2014 22:38
Terminal Signals
1 HUP (hang up)
2 INT (interrupt)
3 QUIT (quit)
6 ABRT (abort)
9 KILL (non-catchable, non-ignorable kill)
14 ALRM (alarm clock)
15 TERM (software termination signal)
PID -1 sends signal to all processes if superuser, just those belonging to the user otherwise.
@sdrew
sdrew / golang-upstart.conf
Created May 20, 2014 23:18
Upstart script for Go service
description "Description goes here"
author "Your Name"
start on (local-filesystems and net-device-up)
stop on runlevel [!2345]
respawn
exec /path/to/compiled/binary -flag value -flag2 value2
@sdrew
sdrew / dhparam.sh
Last active February 19, 2018 22:16
NGINX Config
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
#!/bin/bash
#Alright, so this should automatically convert a given video into a gif called optimized_output.gif
# See here for explanation: https://github.com/lelandbatey/configDebDev/blob/master/helpFiles.txt#L113
ffmpeg -i $1 out%04d.gif # Extracts each frame of the video as a single gif
convert -delay 4 out*.gif anim.gif # Combines all the frames into one very nicely animated gif.
convert -layers Optimize anim.gif optimized_output.gif # Optimizes the gif using imagemagick
# vvvvv Cleans up the leftovers

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

Results

@sdrew
sdrew / base-setup.sh
Last active February 19, 2018 22:17
DigitalOcean Setup - Basic server with swap, fail2ban, ufw and ntp. Install git, rbenv / ruby, postgresql, nginx.
apt-get update
apt-get upgrade
apt-get dist-upgrade
# /var/run/reboot-required ?
adduser $USER
# usermod -a -G www-data $USER
# Setup ~/.ssh/authorized_keys
# /usr/sbin/visudo
@sdrew
sdrew / gist:5230424
Last active July 8, 2018 21:19
HH:MM:SS Formatting for UITextField
- (void)viewDidLoad:(BOOL)animated {
[super viewDidLoad:animated];
self.numberFormatter = [[NSNumberFormatter alloc] init];
[self.numberFormatter setNumberStyle:NSNumberFormatterNoStyle];
[self.numberFormatter setGroupingSize:2];
[self.numberFormatter setGroupingSeparator:@":"];
[self.numberFormatter setUsesGroupingSeparator:YES];
[self.numberFormatter setMaximumFractionDigits:0];
[self.numberFormatter setMinimumIntegerDigits:6];
@sdrew
sdrew / HTTP-Status-Codes.md
Last active May 19, 2017 13:30
Mapping of HTTP Status Codes to Symbols in Rails, as found here: http://www.codyfauser.com/2008/7/4/rails-http-status-code-to-symbol-mapping

1xx Informational

Status Code Status Message Symbol
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing

2xx Success