Skip to content

Instantly share code, notes, and snippets.

View straydogstudio's full-sized avatar

Noel Peden straydogstudio

View GitHub Profile
@straydogstudio
straydogstudio / .pryrc
Created June 13, 2012 19:18 — forked from renz45/.pryrc
Pry: .pryrc configuraton
#switch default editor for pry to sublime text
Pry.config.editor = "sublime"
#format prompt to be <Rails version>@<ruby version>(<object>)>
Pry.config.prompt = proc do |obj, level, _|
prompt = "\e[1;30m"
prompt << "#{Rails.version} @ " if defined?(Rails)
prompt << "#{RUBY_VERSION}"
"#{prompt} (#{obj})>\e[0m"
end
@straydogstudio
straydogstudio / .irbrc
Created June 13, 2012 20:07
IRB: Simple irb with gems loaded outside of Gemfile
# switch default editor for pry to sublime text
Pry.config.editor = "subl"
# format prompt to be <Rails version>@<ruby version>(<object>)>
Pry.config.prompt = proc do |obj, level, _|
prompt = "\e[1;30m"
prompt << "#{Rails.version} @ " if defined?(Rails)
prompt << "#{RUBY_VERSION}"
"#{prompt} (#{obj}:#{level})>\e[0m"
end
@straydogstudio
straydogstudio / gist:2926239
Created June 13, 2012 20:13
CSS: Image Replacement
.ir {
border:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@straydogstudio
straydogstudio / gist:2926264
Created June 13, 2012 20:19
JavaScript: Sexy PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
@straydogstudio
straydogstudio / gist:2926269
Created June 13, 2012 20:20
Git: Undo Push
git push -f origin HEAD^:master
@straydogstudio
straydogstudio / bootstrap_halfsize_spans.less
Last active October 11, 2015 20:18
Partial spans for Twitter Bootstrap. Includes half/third for normal spans, spans inside Bootstrap tabs, and inputs.
// Partial size grid additions
// I have found sometimes I need partial spans (e.g. put two fields evenly below a span3 element)
// This now generates all spans, even though span4half is the same as span2. It is helpful when generating a page
// and you need to have half of an arbitrary span.
#gridExtended {
.core (@gridColumnWidth, @gridGutterWidth) {
//
// Partial spans
//
@straydogstudio
straydogstudio / circle_path
Last active September 11, 2018 21:18
Convert latitude/longitude pair with radius in meters to 16 sided polygon useful in GIS. Useful for converting a Google maps drawing manager circle into a polygon for storage in a GIS system. Implemented as a class method.
def self.circle_path(center, radius, complete_path = false)
# For increased accuracy, if your data is in a localized area, add the elevation in meters to r_e below:
r_e = 6378137.0
@@d2r ||= Math::PI/180
@@multipliers ||= begin
segments = 16
dRad = 2*Math::PI/segments
(segments + (complete_path ? 1 : 0)).times.map do |i|
rads = dRad*i
y = Math.sin(rads)
@straydogstudio
straydogstudio / array.extensions.js
Created February 27, 2013 18:10
Useful Javascript Array prototypes
Array.prototype.unique = function() {
var o = {}, i, l = this.length, r = [];
for(i=0; i<l;i+=1) o[this[i]] = this[i];
for(i in o) r.push(o[i]);
return r;
};
Array.prototype.values_at = function() {
var o = [], i, l = arguments.length;
for(i=0; i<l;i+=1) o.push( this[arguments[i]] );
@straydogstudio
straydogstudio / capdu.sh
Created March 12, 2013 15:58
Quick cap:deploy for git modified files, with optional pattern matching
function capdu {
if [ -z "$1" ]
then
FILES=`gst | grep modified: | ruby -e 'puts ARGF.map {|l| l.split()[2]}.join(",")' | xargs echo`
else
FILES=`gst | grep modified: | grep $1 | ruby -e 'puts ARGF.map {|l| l.split()[2]}.join(",")' | xargs echo`
fi
if [ -z "$FILES" ]
then
echo "No modified files exist"
@straydogstudio
straydogstudio / bootstrap_helper.rb
Created May 30, 2013 16:34
Rails helpers for Bootstrap styled fields. I use these in conjunction with simple_form to provide non model fields.
module BootstrapHelper
def bootstrap_best_in_place_if(condition, object, field, options = {})
content_tag(:div, class: "control-group string optional #{options.delete(:wrapper_class)}".strip) do
label_tag(field, options.delete(:label), class: 'string optional control-label') +
content_tag(:div, class: 'controls') do
best_in_place_if condition, object, field, options
end
end
end