Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
wget https://credis.googlecode.com/files/credis-0.2.3.tar.gz
tar -zxvf credis-0.2.3.tar.gz
cd credis-0.2.3
make
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
@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 / gen_manifest.rb
Created December 12, 2013 20:02
A minimal ruby script to generate a manifest.json for Safari push notification push packages.
require 'digest'
require 'json'
REQUIRED_ICONSET_FILES = ["icon_16x16.png", "icon_16x16@2x.png", "icon_32x32.png", "icon_32x32@2x.png", "icon_128x128.png", "icon_128x128@2x.png" ]
manifest_keys = REQUIRED_ICONSET_FILES.map{|f| 'icon.iconset/' + f }
manifest_keys << 'website.json'
manifest_values = manifest_keys.map {|file| Digest::SHA1.file(file).hexdigest }
manifest_data = Hash[manifest_keys.zip(manifest_values)].to_json
@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 / 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
@adamvduke
adamvduke / de_dup.rb
Created January 2, 2013 12:51
Find and remove duplicate images from a directory by shelling out to imagemagick for comparisons
require 'open3'
require 'fileutils'
if ARGV[0].nil?
puts "This script requires a directory to operate on"
exit 1
end
def file_names(path)
Dir.glob("#{path}/**/*").map do |file|
@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)
@adamvduke
adamvduke / ig_downloader.rb
Created October 3, 2012 17:59
Download all the photos you've liked on instagram
require 'restclient'
require 'json'
require 'digest'
class IGDownloader
def initialize(output_path)
@base_output_path = output_path
end
@adamvduke
adamvduke / BitwiseMagic.c
Created August 29, 2012 00:17
A C function to compute an average without the risk of integer overflow
#include <stdio.h>
/* https://twitter.com/mikeash/status/240471662422810624
* Compute average with no possibility of integer overflow.
* Note: patented in 1996, so you can't use it!
*/
int patentedAverage(int a, int b)
{
int av = (a/2) + (b/2) + (a&b&1);
return av;