Skip to content

Instantly share code, notes, and snippets.

@wyattisimo
wyattisimo / err_drill.rb
Last active March 12, 2019 14:20
Drills into related Mongoid models to create a single error message.
##
# Drills into related Mongoid models to create a single error message.
#
# @param obj [Object] An instance of a Mongoid model class.
# @param prefix [String] The class/attribute name prefix (for recursive calls).
#
# @return [String] A string of concatenated error messages.
#
def err_drill(obj, prefix = nil)
prefix = "#{obj.class.to_s.downcase}." if prefix.nil?
@wyattisimo
wyattisimo / gjt.sh
Last active July 26, 2023 21:16
shell script to output list of Jira tickets based on git commit history
#!/usr/bin/env bash
# Git Jira Tickets
# Outputs a list of Jira ticket numbers from a git log
# Usage: gjt <since_commit>
commit_messages=$(git log --merges --pretty=format:'%h %s' $1^..HEAD | sed "s/ /SPACE_DELIMITER/g")
lines=()
module ActiveSupport::JSON::Encoding
def self.escape(string)
if string.respond_to?(:force_encoding)
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
end
json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }
json = %("#{json}")
json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding)
json
end
@wyattisimo
wyattisimo / sinatra-starter.sh
Created March 4, 2014 18:53
Sinatra Starter
#!/bin/bash
# Sets up a simple Sinatra project.
# Assumes RVM, Bundler and Foreman.
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo Expected 1 or 2 arguments but got $#
echo Usage: sinatra-starter PROJECT_NAME [RUBY_VERSION]
exit
fi
@wyattisimo
wyattisimo / gist:1045379
Last active September 26, 2015 05:17
HTML5 canvas workaround for browsers that ignore the maxWidth argument of fillText() and strokeText()
/*
Workaround for browsers that ignore the maxWidth argument of fillText() and strokeText()
Sample usage:
context.fillTextW("DISPROPORTIONABLENESS", 0, 10, 50);
*/
CanvasRenderingContext2D.prototype.fillTextW = function(text, x, y, maxWidth) {
this.fillOrStrokeText("fillText", text, x, y, maxWidth);
}
CanvasRenderingContext2D.prototype.strokeTextW = function(text, x, y, maxWidth) {