Skip to content

Instantly share code, notes, and snippets.

View nathancolgate's full-sized avatar

Nathan Colgate nathancolgate

View GitHub Profile
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Slideshowbob
class Application < Rails::Application
@nathancolgate
nathancolgate / config
Created June 8, 2012 01:46
Requirements for posting homebrew ImageMagick issue
$ brew --config
HOMEBREW_VERSION: 0.9
HEAD: d9476a9d1564af87a2fc83a61c434d327a87b8bc
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.7.4
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
@nathancolgate
nathancolgate / gist:4998033
Created February 20, 2013 18:52
mustache.js in_groups_of I needed mustache.js to iterate over a list in groups of 2 to take advantage of Twitter Bootstraps “row” and “span” classes. Here is how I got it done (using jQuery).
$.fn.inGroupsOf = function( countPerGroup, groupName ) {
var groups = [], offset = 0, $group, jsonOptions;
while ( ($group = this.slice( offset, (countPerGroup + offset) )).length ) {
jsonOptions = {};
jsonOptions[groupName] = $group.toArray();
groups.push( jsonOptions );
offset += countPerGroup;
}
return groups;
};
@nathancolgate
nathancolgate / gist:5031247
Last active December 14, 2015 04:49
Sphinx 2.0.6 not recognizing postgresql on 10.7.5
$ HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install sphinx
==> Downloading http://sphinxsearch.com/files/sphinx-2.0.6-release.tar.gz
Already downloaded: /Library/Caches/Homebrew/sphinx-2.0.6.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/sphinx-2.0.6.tar.gz
==> Downloading http://snowball.tartarus.org/dist/libstemmer_c.tgz
Already downloaded: /Library/Caches/Homebrew/libstemmer_c.tgz
/usr/bin/tar xf /Library/Caches/Homebrew/libstemmer_c.tgz
==> ./configure --prefix=/usr/local/Cellar/sphinx/2.0.6 --disable-dependency-tracking --localstatedir=/usr/local/var --with-libstemmer --without-mysql
./configure --prefix=/usr/local/Cellar/sphinx/2.0.6 --disable-dependency-tracking --localstatedir=/usr/local/var --with-libstemmer --without-mysql
@nathancolgate
nathancolgate / gist:5052669
Created February 27, 2013 23:04
Update: Sphinx 2.0.6 still not recognizing postgresql on 10.7.5
$ HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install sphinx
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
@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
@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 / 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}"
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