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
^([^:]+:\/\/)([^@]+\@)?([^:\/]+)(:\d+)?(\/[^\s\?\#]+)+(\?([^\n\#]+)(\#\S+)?|(\#\S+))?$
@agius
agius / hash_extension.rb
Created October 6, 2011 00:17
Useful methods for ruby hashes
class Hash
# gets hash-nested values, returns nil if any key is missing
def dig(*path)
path.inject(self) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end
# Deletes key from self and returns self
def kill(key)
@agius
agius / gist:1468681
Created December 12, 2011 19:26 — forked from danielgwood/gist:1244903
MongoDB shell cheatsheet
// A bunch of functions you can use in the MongoDB shell
// taken from http://api.mongodb.org/js/1.8.2/index.html
// amongst other sources
// Used in place of print() to view the contents of objects
printjson(x);
printjsononeline(x);
// File system interaction
ls(...);
@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)
@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 / 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 / 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 / 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 / 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 / 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