Skip to content

Instantly share code, notes, and snippets.

@adamvduke
adamvduke / keybase.md
Created April 14, 2016 15:22
keybase proof

Keybase proof

I hereby claim:

  • I am adamvduke on github.
  • I am adamvduke (https://keybase.io/adamvduke) on keybase.
  • I have a public key ASAdtHkKYGody9mlJ2r3_QeHa2uCosnLTuc9xRNrv8fdxwo

To claim this, I am signing this object:

@adamvduke
adamvduke / Caddyfile
Created February 26, 2016 16:05
Serve rails with TLS using caddyserver
example.com {
root /srv/example.com/public
tls admin@example.com
proxy / localhost:5000 {
except /assets
}
}
@adamvduke
adamvduke / quick_post.rb
Created August 12, 2011 02:44
curl is great unless you have a bunch of form params to post
require 'restclient'
#flip verbose to get more or less output
verbose = true
if verbose
require 'net-http-spy'
Net::HTTP.http_logger_options = {:verbose => true}
end
# params get form-encoded
@adamvduke
adamvduke / gist:8552222
Created January 22, 2014 01:56
example of using curl to send a safari push notification with url_args
curl -d 'auth_token=....' \
-d 'device_tokens[]=...' \
-d 'title=Test' \
-d 'body=Hello' \
-d 'label=View' \
-d 'url_args[]=message_id' \
-d 'url_args[]=12345' \
https://api.zeropush.com/notify
@adamvduke
adamvduke / nginx.conf
Created November 14, 2013 21:11 — forked from plentz/nginx.conf
#don't send the nginx version number in error pages and Server header
server_tokens off;
# config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
# to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
# config to don't allow the browser to render the page inside an frame or iframe
# and avoid clickjacking http://en.wikipedia.org/wiki/Clickjacking
# if you need to allow [i]frames, you can use SAMEORIGIN or even set an uri with ALLOW-FROM uri
@adamvduke
adamvduke / postgres-replication-lag-functions.sql
Last active December 17, 2015 01:11
A query to get postgres streaming replication lag
BEGIN;
CREATE OR REPLACE FUNCTION primary_streaming_byte_lag() RETURNS TABLE (client_hostname text, client_addr inet, log_location_diff_bytes numeric, total_byte_lag double precision, total_byte_lag_pretty text, replay_byte_lag double precision, replay_byte_lag_pretty text)
LANGUAGE SQL SECURITY DEFINER
AS $$
SELECT
client_hostname,
client_addr,
log_location_diff_bytes,
( (cur_xlog * 255 * 16 ^ 6) + cur_offset) - ((replay_xlog * 255 * 16 ^ 6) + replay_offset) AS total_byte_lag,
pg_size_pretty((( (cur_xlog * 255 * 16 ^ 6) + cur_offset) - ((replay_xlog * 255 * 16 ^ 6) + replay_offset))::numeric) AS total_byte_lag_pretty,
@adamvduke
adamvduke / mock_apns.rb
Created March 18, 2013 16:53
A quick mockup to demonstrate the socket API that we'd like to have for handling errors and/or broken connections for ZeroPush
require 'socket'
server = TCPServer.open(2195)
connection = server.accept
loop {
data = connection.read(8)
puts "Received \"#{data}\""
if data == "CCCCCCCC"
connection.write("error")
connection.close
set func_call_user NilOrNotNSNull
indent_align_string=false
indent_braces=false
indent_braces_no_func=false
indent_brace_parent=false
indent_namespace=false
indent_extern=false
indent_class=false
indent_class_colon=false
curl -i "https://scontent-a.cdninstagram.com/hphotos-xaf1/outbound-distilleryimage2/t0.0-17/OBPTH/1c8dbe10a8a4....e414f2eeda2_8.jpg"
HTTP/1.1 400 Not Found
Content-Type: text/plain
Server: proxygen
Timing-Allow-Origin: *
X-Cache-Ts: 1447545792
Date: Sun, 15 Nov 2015 00:03:12 GMT
X-FB-Edge-Debug: BBUHPNJ58swqQlRj0vjMAzLKyzlubMK_sF7iftGX9VpdYAnw9_02fPGxmEeelkNXf_DeSr0oNybV0ztpT-DAjg
Connection: keep-alive
Content-Length: 9
@adamvduke
adamvduke / cleanup.rb
Created November 3, 2012 00:27
Get rid of crap files in your music library and convert crap formats to mp3
KEEP_EXTS = [".mp3",".jpg",".mid",".MP3",".wma",".m4a",".JPG",".mpg",".JPEG",".m4v",".mp4",".mov",".flac"]
UNWANTED_EXTS = [".ini",".db",".txt",".md5",".nfo",".pls",".info",".sfv",".NFO",".SFV",".url",".bal",".ogg",".php",".m3u",".LOG",".sls",".log",".pdf"]
CONVERT_EXTS = [".wma"]
def files(path)
Dir.glob("#{path}/**/*")
end
def find_files(path)