Skip to content

Instantly share code, notes, and snippets.

View agius's full-sized avatar
🐐
goat rodeo

Andrew Evans agius

🐐
goat rodeo
View GitHub Profile
@agius
agius / blunder.rb
Created October 12, 2013 00:11
Centralized error reporting module - control what services you use and how you log errors in one place.
module Blunder
# Centralizes error reporting, so we don't get custom
# library names like BugSnag or Errplane all over our code
def self.oops(exception, custom_data = {})
raise if Rails.env == 'test'
exception = Exception.new(exception) unless exception.is_a?(Exception)
custom_data = custom_data.with_indifferent_access
Rails.logger.error("\n\nBlunder Exception: #{exception}")
Rails.logger.error("backtrace:#{exception.backtrace.take(20).join("\n")}\n\n") if exception.backtrace.present?
env = custom_data.delete(:env)
@agius
agius / hamlconvert.rb
Created August 20, 2013 04:53
Recursively browse directory and convert all .haml files to .erb via Herbalizer (https://github.com/danchoi/herbalizer)
#!/usr/bin/env ruby
require 'open3'
# things herbalizer hates:
# nested hashes: %div{data: {href: src }} -> %div{data: Hash[href: src] }
# comments in the first line
# blank first line
# ruby-style interpolation: Message to #{person} -> Message to \ = person
# ternary operators inside blocks: %div{href: one ? two : three } -> put on separate line
@agius
agius / bookmarklet_toolbar.js
Last active December 17, 2015 23:58
Prose Bookmarklet
s = document.createElement('script');
s.setAttribute('src','http://prose.atevans.com/bookmarklet.js');
document.head.appendChild(s);
@agius
agius / metroify.rb
Created May 20, 2013 14:10
An application_helper function to output stuff in a metro-like format for bootstrap.
def metroify(collection, partial, opts = {})
return "" unless collection.present?
output = ""
coll_copy = collection.dup
renderize = lambda do |obj, tile|
locals = {tile: tile}
locals = locals.merge(opts[:locals]) if opts[:locals]
render_opts = opts.dup.merge(partial: partial, object: obj, locals: locals)
render(render_opts).to_s
@agius
agius / image_parse.rb
Created January 29, 2013 16:12
Parsing base64 encoded images
if params['format'] == 'base64' || params[:image].is_a?(String)
img = Magick::Image.read_inline(params[:image])
fn = params['filename']
else
img = img = Magick::Image.from_blob(params[:image][:tempfile].read)
fn = params[:image][:filename]
end
@agius
agius / dragupload.js
Created January 29, 2013 16:09
Upload via drag & drop
var uploadImage = function(){
$(".alert").remove();
var img = $("#drop-target img").first();
if(typeof(img) == "undefined" || typeof(img) == "null") {
alertBox("Can't seem to find your image.");
return false;
}
var formData = new FormData();
formData.append("images[]", img.attr('src'));
@agius
agius / gridify.rb
Created December 3, 2012 23:46
Gridify app helper
def gridify(collection, partial, opts = {})
rows = []
coll_copy = collection.dup
cols = opts[:cols] || 3
begin
row = []
cols.times { row << coll_copy.shift }
row.compact!
rows << row
end while coll_copy.present?
@agius
agius / dwolla_error.txt
Created December 2, 2012 01:41
Dwolla API fault
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Receiver</Valu... xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalSer... xml:lang="en-US">The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.</Text></Reason></Fault>
@agius
agius / json_diff.rb
Created May 8, 2012 00:52
Ruby JSON Diff
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
unless ARGV.count > 1
puts "Usage: json_diff.rb json_file_1.json json_file_2.json"
exit
end
def different?(a, b, bi_directional=true)
@agius
agius / added thumbnail generation with RMagick
Created March 14, 2012 23:55
Script to create & edit new jekyll post
#!/usr/bin/env ruby
# Script to quickly generate a new post for Jekyll
# 2012 Andrew Evans - http://atevans.com
require "net/http"
require "uri"
require 'RMagick'
def titleize(str)