Skip to content

Instantly share code, notes, and snippets.

@straydogstudio
straydogstudio / .pryrc
Created Jun 13, 2012 — forked from renz45/.pryrc
Pry: .pryrc configuraton
View .pryrc
#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 Jun 13, 2012
IRB: Simple irb with gems loaded outside of Gemfile
View .irbrc
# 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 Jun 13, 2012
CSS: Image Replacement
View gist:2926239
.ir {
border:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@straydogstudio
straydogstudio / gist:2926264
Created Jun 13, 2012
JavaScript: Sexy PubSub
View gist:2926264
// 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);
View gist:2926269
git push -f origin HEAD^:master
@straydogstudio
straydogstudio / bootstrap_halfsize_spans.less
Last active Oct 11, 2015
Partial spans for Twitter Bootstrap. Includes half/third for normal spans, spans inside Bootstrap tabs, and inputs.
View bootstrap_halfsize_spans.less
// 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 Sep 11, 2018
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.
View circle_path
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 Feb 27, 2013
Useful Javascript Array prototypes
View array.extensions.js
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 Mar 12, 2013
Quick cap:deploy for git modified files, with optional pattern matching
View capdu.sh
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
Rails helpers for Bootstrap styled fields. I use these in conjunction with simple_form to provide non model fields.
View bootstrap_helper.rb
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