Skip to content

Instantly share code, notes, and snippets.

View straydogstudio's full-sized avatar

Noel Peden straydogstudio

View GitHub Profile
@straydogstudio
straydogstudio / with_runner.rb
Last active April 13, 2023 02:31
Render template inside a Rails runner script
view_assigns = {widgets: Widget.all}
av = ActionView::Base.new(ActionController::Base.view_paths, view_assigns)
av.class_eval do
# include any needed helpers (for the view)
include ApplicationHelper
end
# normal render statement
content = av.render template: 'widgets/index.xlsx.axlsx'
# do something with content, such as:
@straydogstudio
straydogstudio / README.txt
Last active January 6, 2021 00:30 — forked from flaviaza/README.txt
A jQuery fixed header table implementation. Designed to work with Bootstrap, but should work generally.
Here is a simple jQuery plugin to make a table header fixed on top of a div when this is scrolled.
Using the code from twitter bootstrap documentation page, this code is customized for table header.
Create the table with the table-fixed-header class and a thead tag:
<table class="table table-striped table-fixed-header" id="mytable">
<thead class="header">
<tr>
<th>Email Address</th>
<th>First Name</th>
<th>Last Name</th>
@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)

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array): T[] 🔒 ES3
require 'axlsx'
title = "Some report"
selected_columns = %w(one two three four five)
Axlsx::Package.new do |package|
package.workbook do |workbook|
# Disabling this will improve performance for very large documents
workbook.use_autowidth = false
@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
@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 / 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 / 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 / gist:2926269
Created June 13, 2012 20:20
Git: Undo Push
git push -f origin HEAD^:master