Skip to content

Instantly share code, notes, and snippets.

View nathancolgate's full-sized avatar

Nathan Colgate nathancolgate

View GitHub Profile
@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 / 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 / static_copy.sh
Created April 21, 2015 17:45
The modern Web is a dynamic place. However, sometimes it's necessary (or desirable) to remove the dynamic functionality of a website, while preserving its static content.
wget -P /path/to/destination/directory/ -mpck --user-agent="" -e robots=off --wait 1 -E https://www.example.com/
@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):
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 / ssl_puma.sh
Last active May 31, 2022 09:13 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key
$ cd ~/.ssh
$ openssl genrsa -des3 -passout pass:x -out lvh.me.pass.key 2048
# 2) Generate RSA key
$ openssl rsa -passin pass:x -in lvh.me.pass.key -out lvh.me.key
# 3) Get rid of private key
$ rm lvh.me.pass.key
# On my mac
> brew install pstree
> pstree -p PID
@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)
@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 / rails_server_setup.sh
Created March 11, 2019 14:23
How we setup servers from 2014 - 2016
# Digital Ocean / Rails 4.1.6 / Ruby 2.1.3 / nginx 1.4.6 / Ubuntu 14.04x64 / Capistrano 3.2.1
# https://gorails.com/deploy/ubuntu/14.04
# https://coderwall.com/p/yz8cha/deploying-rails-app-using-nginx-unicorn-postgres-and-capistrano-to-digital-ocean
# http://www.cubicleapps.com/articles/ubuntu-rails-ready-with-nginx-unicorn
# 1) SETUP DEPLOY USER AND GET ROOT ACCESS OUT OF THE WAY
you@local:~$ ssh root@IPADDRESS
root@remote:~$ adduser USERNAME
root@remote:~$ visudo
# # User privilege specification