Skip to content

Instantly share code, notes, and snippets.

View eurica's full-sized avatar

David Hayes eurica

View GitHub Profile
@eurica
eurica / twilio-numbers.rb
Created December 20, 2013 20:55
Ruby script to check numbers against the Twilio Price list.
require 'csv'
#Parse the CSV that Twilio provides https://www.twilio.com/resources/rates/international-rates.csv
numbers = []
CSV.foreach('international-rates.csv', :headers => true) do |row|
starts = row[2].split(",")
starts.each do |p|
numbers.push([p.strip, p.strip.length, row[1], row[0]])
end
end
@eurica
eurica / README.md
Last active December 21, 2015 23:49 — forked from mbostock/.block
Fixed-X Force Directed Tree
@eurica
eurica / PagerDutyWebhookToEmail.php
Last active November 22, 2019 02:12
Simple example of using PagerDuty webhooks and PHP to forward all incident state changes to an email address.
Sample PHP code to accept PagerDuty webhooks and send out notifications by email on state changes.
For more information, see http://developer.pagerduty.com/documentation/rest/webhooks
This example threads emails based on "$status: $description on $service" so each update to each incident would start a new thread.
This code is unsupported by PagerDuty.
<?php
$emailAddress = "CHANGEME@example.com";
@eurica
eurica / s3upload.sh
Created May 1, 2013 00:46
A bash script to upload files for static hosting on s3
# Bash script to upload files to static s3 hosting with s3cp
# dave@pagerduty.com April 30th, 2013
# Modified from https://github.com/roqs23/sync-svn-updates-to-s3/blob/master/svnupd2s3.sh
export COMMON_HEADER="--header \"x-amz-acl: public-read\" --header \"Vary: Accept-Encoding\" "
export HTML_HEADER="--header \"Cache-Control: max-age=604800,must-revalidate\" --header \"Content-Type: text/html\""
export CSS_HEADER="--header \"Cache-Control: max-age=604800,must-revalidate\" --header \"Content-Type: text/css\""
export JS_HEADER="--header \"Cache-Control: max-age=604800,must-revalidate\" --header \"Content-Type: application/javascript\""
export PNG_HEADER="--header \"Cache-Control: max-age=2592000,must-revalidate\" --header \"Content-Type: image/png\""
export GIF_HEADER="--header \"Cache-Control: max-age=2592000,must-revalidate\" --header \"Content-Type: image/gif\""
@eurica
eurica / otp.php
Created November 9, 2012 06:16
One time pad server code sample
<?
// One Time Pad from string demo.
// http://euri.ca/2012/11/encryption-that-calls-home-skyfall-movie-magic/
// Don't use this in production, obviously since you can brute force the seed.
// (Actually coming up with a server that generates OTPs in response to a seed is a decent problem)
$seed = "LOCALSECRET" + $_SERVER["QUERY_STRING"];
$hash = hash('sha256', $seed);
$dec = hexdec($hash);
mt_srand($dec);
@eurica
eurica / gist:825248
Created February 13, 2011 22:50
Automated backup script for Android smartphone
@echo off
set destdir=G:\autobackups
set devicefile=htc_desire
for %%d in (E F G H I J K L) do (
if exist %%d:\%devicefile% (
echo %%d is the %devicefile%
xcopy %%d:\ "%destdir%\%devicefile%" /V /E /D /C /I /Y > %destdir%\%devicefile%\lastbackup.txt
)
)
@eurica
eurica / autobackup.bat
Created February 3, 2011 06:10
My automated backup script
@rem Simple recursive backup script dave@euri.ca 2011
@echo off
rem I strongly recommend backing up to a different drive or machine
set sourcedir=c:\projects
set destdir=g:\autobackups\projects
for /f "tokens=1-3 delims=/ " %%g in ('date /t') do (
set mm=%%g
set dd=%%h
@eurica
eurica / gist:668653
Created November 9, 2010 03:32
random image
$img = imageCreateTrueColor(512, 512);
for ($i=0; $i < 512; $i++) {
for ($j=0; $j < 512; $j++) {
$c=mt_rand(0,255);
$col = imageColorAllocate($img, $c, $c, $c);
imagesetpixel($img, $i, $j, $col);
}
}
header("Content-Type: image/png");
imagepng($img);
@eurica
eurica / raplet2.php
Created November 8, 2010 17:32
minimum viable raplet 2
<?php
/*
David Hayes dave@euri.ca
Quasi-minimal viable Raplet:
// */
$in = $_GET; //raplet.php?email=rahul@rapportive.com&name=Rahul%20Vohra&twitter_username=rahulvohra&callback=jsonp123456789
$jsonContainer = $in['callback'];
@eurica
eurica / raplet1.php
Created November 8, 2010 17:31
the minimum viable raplet
<?php
/*
David Hayes dave@euri.ca
Quasi-minimal viable Raplet:
// */
$in = $_GET; //raplet.php?email=rahul@rapportive.com&name=Rahul%20Vohra&twitter_username=rahulvohra&callback=jsonp123456789
$jsonContainer = $in['callback'];