Skip to content

Instantly share code, notes, and snippets.

View mattgaidica's full-sized avatar

Matt Gaidica, Ph.D. mattgaidica

View GitHub Profile
@mattgaidica
mattgaidica / index.html
Created February 8, 2012 00:59
Simple Geolocation for iPhone
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GEO</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
@mattgaidica
mattgaidica / checksum.rb
Created June 7, 2012 04:45
Create an MD5 hash (checksum) for an external file
require 'tempfile'
require 'net/http'
require 'digest/md5'
file = Tempfile.new('temp_file')
begin
Net::HTTP.start("domain.tld") { |http|
resp = http.get("/02185773dcb5a468df6b.pdf")
file.write(resp.body)
@mattgaidica
mattgaidica / compare.rb
Created June 7, 2012 22:11
Comparing two files via MD5 hash on Amazon S3 using Ruby
require 'digest/md5'
require 'aws/s3'
#set your AWS credentials
AWS::S3::Base.establish_connection!(
:access_key_id => 'XXX',
:secret_access_key => 'XXX'
)
#get the S3 file (object)
@mattgaidica
mattgaidica / deploy.rake
Created June 23, 2012 04:34 — forked from njvitto/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
@mattgaidica
mattgaidica / Better Database Pulling With Heroku
Created June 23, 2012 04:37 — forked from jackkinsella/Better Database Pulling With Heroku
Taps isn't reliable for anything but dummy databases. This command invokes the more powerful PGBackups. A side effect is that every time you pull your database locally a backup is also generated on your server.
#!/bin/bash
# Best use case is to create a file "update_local_db.sh" in your project folder and then call the command with bash update_local_db
# Follow me: @jackkinsella
function LastBackupName () {
heroku pgbackups | tail -n 1 | cut -d"|" -f 1
}
# This part assumes you have a low limit on no. of backups allowed
@mattgaidica
mattgaidica / lazy.rb
Created July 20, 2012 18:46
Lazy Levenshtein
# test by running:
# ruby lazy.rb
# use control+c to exit
require 'amatch'
include Amatch
def lazy input, matches, abbreviations=true
# setup the Levenshtein comparator
distances = {}
m = Levenshtein.new(input)
@mattgaidica
mattgaidica / status.rb
Created August 9, 2012 21:46
Simple Status Ticker for API Endpoints
require 'HTTParty'
require 'terminal-display-colors'
require 'json'
# set your endpoints!
endpoints = {
"Google" => "http://google.com",
"Twitter" => "http://twitter.com"
}
# seconds to sleep between pings
def shift_hsv(startHue,nColors,ii)
((360 * (ii - 1)/nColors) + startHue) % 360
end
function colors = linesUM(nColors,onlySecondary)
if ~exist('nColors','var')
nColors = Inf;
end
if ~exist('onlySecondary','var')
onlySecondary = false;
end
% maize & blue + BRIGHT colors, n=8
primaryUMcolors = [254 202 48;...
function cb = cbAside(ax,labelText,cbColor,caxisVals)
cbOffset = .001;
cb = colorbar(ax,'Location','east');
% % cb.FontSize = 8;
gcaPos = ax.Position;
cbPos = cb.Position;
set(cb,'position',[gcaPos(1) + gcaPos(3) + cbOffset gcaPos(2) cbPos(3)/2 gcaPos(4)]);
set(cb,'YAxisLocation','right');
cb.Color = 'r';