Skip to content

Instantly share code, notes, and snippets.

View calebwoods's full-sized avatar

Caleb Woods calebwoods

View GitHub Profile
@calebwoods
calebwoods / nginx.conf
Created May 10, 2014 20:18
Sample Nginx config for deployment of Angular.js app
server { listen 80;
server_name example.com;
access_log /var/log/example.com/nginx.access.log;
error_log /var/log/example.com/nginx.error.log;
root /var/www/apps/example.com/public;
charset utf-8;
location / {
rewrite ^ https://$host$request_uri? permanent;
}
@calebwoods
calebwoods / pg_hba.conf
Created November 21, 2013 14:50
Ansible Postgres Setup
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file. A short
# synopsis follows.
#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access. Records take one of these forms:
@calebwoods
calebwoods / resize.rb
Last active October 24, 2017 11:41
Script for resizing a directory of images using Ruby. Note requires the RMagick gem to be installed and assumes Rbenv is used for managing the Ruby Version. Blog post: http://www.calebwoods.com/2015/02/01/batch-resizing-images-ruby/
#!/usr/bin/ruby
require 'RMagick'
require 'pathname'
@directory = Pathname(File.expand_path(ARGV[0]))
@size = ARGV.fetch(1) { 1025 }
def resize_image(file)
img = Magick::Image.read(file).first
@calebwoods
calebwoods / Gemfile
Last active February 6, 2017 21:45
Simple standalone ActiveRecord setup. Usage: [pry|irb] -r ./post.rb
source 'https://rubygems.org'
gem 'activerecord', '>= 4.2.0'
gem 'sqlite4'
@calebwoods
calebwoods / bookmarklet.js
Last active January 3, 2016 12:59
Bookmarklet to fill custom merge message for Github Pull Request. Format used by @RoleModel
javascript:(function () {
var mergeMessage = $('.merge-commit-message');
if (mergeMessage.length > 0) {
prNum = location.pathname.split('/').slice(-1)[0];
var prTitle = $('.discussion-topic-title').text();
mergeMessage.val('' + prTitle + ' [KB #NUMBER] (GH #' + prNum + ')');
}
})();
@calebwoods
calebwoods / api_context.rb
Created May 20, 2013 20:30
Testing helper methods to use with Rack::Deflater
def api_post_gziped(url, params={}, api_token = 'test_token')
gzipped_data = ActiveSupport::Gzip.compress(params.to_json)
post(url, gzipped_data, headers.merge('HTTP_AUTHORIZATION' => basic_auth_for(api_token),
"HTTP_ACCEPT_ENCODING" => "gzip",
'CONTENT_TYPE' => 'gzip/json'))
end
def decompressed_json_body
Yajl::Parser.parse(ActiveSupport::Gzip.decompress(response.body))
end
@calebwoods
calebwoods / index.html
Created November 27, 2012 14:53
Draw Polygons on Google Maps
<html>
<head>
<title>Draw Sample Polygons</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="https://raw.github.com/HPNeo/gmaps/master/gmaps.js"></script>
</head>
<body>
<div id="map" style="width: 600px; height: 600px"></div>
@calebwoods
calebwoods / utm_zone_partial.js
Created November 26, 2012 20:02
Test of acreage calculation for polygons that span more than 1 UTM zone.
// Zone spanning polygon
{
"type": "MultiPolygon",
"coordinates": [
[
[
[-90.00575, 35.99485],
[-89.99339, 35.99485],
[-89.99339, 36.00481],
[-90.00575, 36.00481],
@calebwoods
calebwoods / gist:1254706
Created September 30, 2011 19:13
MySQL Issue RVM: Run this command from terminal to fix the mysql2 issues with rvm. Assumes the gem is installed in the global gemset.
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.3-p0@global/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
@calebwoods
calebwoods / gist:1254258
Created September 30, 2011 16:18
Failing PUT
describe "with invalid params" do
it "assigns the snippet as @snippet" do
snippet = FactoryGirl.create(:snippet)
# Trigger the behavior that occurs when invalid params are submitted
Snippet.any_instance.stub(:save).and_return(false)
put :update, :id => snippet.id.to_s, :snippet => {}
assigns(:snippet).should eq(snippet)
end
it "re-renders the 'edit' template" do