Skip to content

Instantly share code, notes, and snippets.

@sdrew
sdrew / Procfile
Last active July 27, 2021 15:25
Laravel configs for Heroku/Dokku
web: vendor/bin/heroku-php-apache2 public/
@sdrew
sdrew / Application Problem - FogCreek - Support Engineer
Last active October 4, 2020 01:48
FogCreek Application Problem - Support Engineer 2
Sort the characters in the following string:
abcdefghijklmnopqrstuvwxyz_
by the number of times the character appears in data.txt
Now take the sorted string, and drop all the characters after (and including) the _.
The remaining word is the answer.
Download including Swift Playground:
@sdrew
sdrew / phone_format.php
Last active June 12, 2020 21:45
Phone Formats
<?php
function PhoneFormat($phone) {
$prefix = '';
$phone = preg_replace('/\D/', '', $phone);
$dash = strlen($phone);
if ($dash > 10) {
if (strpos($phone, '10') === 0 || strpos($phone, '11') === 0) {
$prefix = substr($phone, 0, 2);
@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 / gist:24a14d0de2778346ff05
Created July 29, 2011 20:19
Admin::ContestsController
class Admin::ContestsController < ApplicationController
def draw
redirect_to(root_url, :alert => 'Unauthorized') and return unless(current_user.present? && current_user.admin?)
contestants = Contestant.select([:id, :points]).elegible.for_contest(params[:id])
entries = []
contestants.each { |c| c.points.times { entries << c.id } }
unless entries.blank?
entries.shuffle!
@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 / 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
@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 / 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
https://unix.stackexchange.com/questions/12985/how-to-check-rx-ring-max-backlog-and-max-syn-backlog-size
Jason Cook - Tuning TCP for the Web - Fastly
https://vimeo.com/70369211
http://cdn.oreillystatic.com/en/assets/1/event/94/Tuning%20TCP%20For%20The%20Web%20Presentation.pdf
https://www.youtube.com/watch?v=gfYYggNkM20
https://wiki.mikejung.biz/Sysctl_tweaks
https://wiki.mikejung.biz/Apache