Skip to content

Instantly share code, notes, and snippets.

View nathancolgate's full-sized avatar

Nathan Colgate nathancolgate

View GitHub Profile
@nathancolgate
nathancolgate / mime_types.rb
Last active November 18, 2018 15:17 — forked from ream88/excel_template_handler.rb
Example demonstrating the use of writeexcel gem in rails 3.2
# config/initializers/mime_types.rb
Mime::Type.register "application/vnd.ms-excel", :xls
@nathancolgate
nathancolgate / rackspace_account_meta_temp_url_key.sh
Last active September 26, 2018 15:41
How to Set your Rackspace Temp URL Key (X-Account-Meta-Temp-Url-Key) from the command line
# General Reading: https://developer.rackspace.com/docs/cloud-files/v1/developer-guide/#document-public-access-to-your-cloud-files-account/tempurl
$ curl -v -H "X-Auth-User: <your_rackspace_username>" -H "X-Auth-Key: <your_rackspace_api_key>" https://auth.api.rackspacecloud.com/v1.0
* About to connect() to auth.api.rackspacecloud.com port 443 (#0)
* Trying 67.192.1.11... connected
* Connected to auth.api.rackspacecloud.com (67.192.1.11) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
@nathancolgate
nathancolgate / .profile
Last active December 28, 2016 14:55
iterm2_hostname in bash profile
export iterm2_hostname=xxx.xxx.xxx.xxx
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
@nathancolgate
nathancolgate / gist:2364f2132099c7168d7476667109370d
Created December 16, 2016 18:39
Migrating postgres database from one server to another through tunnels
# Open SSH tunnels to both servers, routing postgres traffic to local port
# I use SSH Tunnel app for that, but I'm pretty sure you could figure out how to
# run that tunnel in the command line
# First: Dump the old DB
pg_dump -U deploy -h 127.0.0.1 -p 3303 -d my_app_production -F c -f outfile.sqlc
# It will prompt you for the user's password, and then you should be golden.
# -U username
# -h host (localhost)
# On my mac
> brew install pstree
> pstree -p PID
require 'arel/nodes/binary'
module Arel
module Nodes
class ContainedInHStore < Arel::Nodes::Binary
def operator; :"<@" end
end
class ContainedInArray < Arel::Nodes::Binary
def operator; :"<@" end
@nathancolgate
nathancolgate / gist:1072361
Created July 8, 2011 17:50
Copying a file from HTTP to S3 via a local temp file in Ruby
# This copies a file from HTTP to S3
require 'net/http'
require 'aws/s3'
http_url = 'http://www.google.com/intl/en_com/images/srpr/logo1w.png'
http_domain = http_url.gsub('http://','').split('/')[0]
http_path = '/' + http_url.gsub('http://','').split('/')[1..999].join('/')
file_name = File.basename(http_url)
s3_path = "path/to/new/#{file_name}"
@nathancolgate
nathancolgate / svg_to_png.rb
Created November 8, 2013 16:21
Converting SVG content from Highcharts into PNGs to be embedded into a PDF. Eventually I settled on using prawn-svg (thanks, Matt!). But I thought this solution was interesting enough to retain.
@pngs = {}
timestamp = Time.now.to_i
Dir.mkdir("#{Rails.root}/tmp/rmagick") unless File.exists?("#{Rails.root}/tmp/rmagick")
Dir.mkdir("#{Rails.root}/tmp/rmagick/reports") unless File.exists?("#{Rails.root}/tmp/rmagick/reports")
Dir.mkdir("#{Rails.root}/tmp/rmagick/reports/#{timestamp}") unless File.exists?("#{Rails.root}/tmp/rmagick/reports/#{timestamp}")
params[:svgs].each do |key,svg|
string = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'+URI.unescape(svg)
string.gsub!("'lucida grande', 'lucida sans unicode', verdana, arial, helvetica, sans-serif",'') # classes_observed_by_grade_level
string.gsub!(/clip-path="url\(#highcharts-[0-9]*\)"/,'clip-path="none"') # classes_observed_by_grade_level
string.gsub!(' opacity="1"','') # classes_observed_by_grade_level
@nathancolgate
nathancolgate / jquery.watable.ie8.js
Created July 30, 2013 21:49
A safer Object.keys compatibility implementation for jquery.WATable so that it will work in IE8
/*
Throwing Object.keys error in IE8 fix:
http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
*/
Object.keys = Object.keys || (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
DontEnums = [
'toString',
'toLocaleString',
@nathancolgate
nathancolgate / gist:5053019
Created February 27, 2013 23:57
Update: Sphinx 2.0.6 still not recognizing postgresql on 10.7.5 passing --pgsql
$ HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install sphinx --pgsql
Warning: Using Clang, but this formula is reported to fail with Clang.
sphinxexpr.cpp:1802:11: error: use of undeclared identifier 'ExprEval'
We are continuing anyway so if the build succeeds, please open a ticket with
the subject
sphinx-2.0.6: builds with Clang-425-10.7