Skip to content

Instantly share code, notes, and snippets.

@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 / README-setup-tunnel-as-systemd-service.md
Created January 22, 2018 18:45 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/secure-tunnel@.service. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
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
@sdrew
sdrew / letsencrypt_2017.md
Created November 28, 2017 07:35 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

@sdrew
sdrew / Procfile
Last active July 27, 2021 15:25
Laravel configs for Heroku/Dokku
web: vendor/bin/heroku-php-apache2 public/

Keybase proof

I hereby claim:

  • I am sdrew on github.
  • I am sdrew (https://keybase.io/sdrew) on keybase.
  • I have a public key ASBMidqo4x6tv-XIM-8GTv5147ze7dcVVcqXt-mxNSncbwo

To claim this, I am signing this object:

var PhoneFormatMX = function (phone, display) {
var prefix = '';
var dash = 0;
var segment = 4;
phone = phone.replace(/\D/g, '');
dash = phone.length;
if (dash > 10) {
if (phone.indexOf('044') === 0 || phone.indexOf('045') === 0) {
// UIImage+Alpha.h
// Created by Trevor Harmon on 9/20/09.
// Free for personal or commercial use, with or without modification.
// No warranty is expressed or implied.
// Helper methods for adding an alpha layer to an image
@interface UIImage (Alpha)
- (BOOL)hasAlpha;
- (UIImage *)imageWithAlpha;
- (UIImage *)transparentBorderImage:(NSUInteger)borderSize;
@sdrew
sdrew / flashflush.sh
Last active August 29, 2015 14:23 — forked from 50kudos/flashflush.sh
#!/bin/bash
cat $(find app/assets/stylesheets/ -type f) |
grep -Eo '\.[a-z]+[a-z0-9_-]*' | sort | uniq | sed s/.// |
while read CSS; do
if ! grep -Erqi "([^(remove|has)]class[(:|=|[:space:]*=>[:space:]*)]*\s*[(\"|')]*[-a-z0-9[:space:]]*$CSS|\\.$CSS\b)" app/views/ vendor/assets/ app/assets/javascripts/; then
echo $CSS >> unused.scss;
fi
done
@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);