Skip to content

Instantly share code, notes, and snippets.

@breckenedge
breckenedge / git_aliases.sh
Last active July 16, 2021 18:05
Git shell aliases
# Fragment of shell aliases I use with git
alias g="git"
alias gb="git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'"
alias gca="git commit --amend"
alias gd="git branch -d"
alias gD="git branch -D"
alias gf="git fetch"
alias gfa="git fetch --all"
alias gu="git pull"
alias gp="git push"
@breckenedge
breckenedge / as_hash_from_object.rb
Created January 7, 2015 15:08
For converting an object to a hash (tired of writing one-time-use presenters for JSON, needed quick method)
# Calls attributes on obj, returning results as a hash. Be careful to never
# run this code with user-provided attributes.
#
# Example:
# as_hash_from_object(user, ["first_name", "last_name", "account.name"])
# #=> {"first_name" => "Aaron", "last_name" => "Breckenridge", "account.name" => "System Root"}
def as_hash_from_object(object, attribs)
attribs.each_with_object({}) do |attrib, hash|
hash[attrib] = attrib.split('.').reduce(object) { |o, i| o.respond_to?(i) ? o.send(i) : nil }
end
@breckenedge
breckenedge / _partial.jbuilder
Last active August 18, 2020 13:11
Cache warmer for Jbuilder-based JSON views
json.cache! model.cache_key do
json.(model, *%i(id name description created_at super_long_running_helper_method))
json.foo foo # 'bar'
# ...
end
@breckenedge
breckenedge / ss_util_rollup.html
Created June 17, 2013 02:08
Completely boring text-concat in Javascript
<!DOCTYPE html>
<html>
<head>
<title>SpreadsheetUtil.rollup()</title>
<style>
body, textarea {
font-family: 'Lucida Console', 'Consolas', courier;
color: #7f7;
}
@breckenedge
breckenedge / concatenators_controller.rb
Created August 18, 2012 03:17
PDF merge controller
require 'net/http'
class Pdf::ConcatenatorsController < ApplicationController
respond_to :html, :js, :json, :xml
def index
pdf_concatenators = PdfConcatenator.all
respond_with @pdf_concatenators
end
@breckenedge
breckenedge / colspec.xslt
Created August 9, 2012 19:34
FrameMaker Colspec Template Fix
<xsl:template match="colspec[not(@colnum)]">
<xsl:element name="colspec">
<xsl:attribute name="colnum">1</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
@breckenedge
breckenedge / prawn-concatenate-example.rb
Created July 11, 2012 18:51
PDF Concatenation with Prawn - Slow Example
require 'rubygems'
require 'benchmark'
require 'bundler'
Bundler.setup
require 'prawn'
require 'ruby-debug'
sources = ['ML091590492.pdf', 'file1.pdf', 'file2.pdf']
document = Prawn::Document.new(:template => sources.first)
@breckenedge
breckenedge / rails_4_install_windows.bat
Created July 3, 2012 02:37
installing rails 4 beta in wondows
@echo OFF
REM Run as administrator, I think :-/
REM Download and install ruby 1.9.3
REM Download and install devkit: ruby dk.rb init & ruby dk.rb install
call gem install rake -v 0.9.2.2 --no-ri --no-rdoc
call gem install json -v 1.7.3 --no-ri --no-rdoc
call gem install rdoc -v 3.12 --no-ri --no-rdoc
call gem install jquery-rails -v 2.0.2 --no-ri --no-rdoc
REM ytf does this have old rails 3.2.6 requirements
call gem install sprockets -v 2.4.4 --no-ri --no-rdoc
@breckenedge
breckenedge / gist:2877801
Created June 5, 2012 20:51
plant quarters pivot
SELECT PLANT_NAME as 'plant name', [2009Q2], [2009Q3], [2009Q4], [2010Q1], [2010Q2], [2010Q3], [2010Q4], [2011Q1], [2011Q2], [2011Q3], [2011Q4], [2012Q1]
FROM
(
SELECT PLANT_CODE as plant, [QUARTER] as qtr FROM RECALL..[TREND_IR_FINDINGS]
WHERE CC_ASPECT LIKE '%H1b%'
) AS src
PIVOT
(
COUNT(qtr) FOR qtr IN ([2009Q2], [2009Q3], [2009Q4], [2010Q1], [2010Q2], [2010Q3], [2010Q4], [2011Q1], [2011Q2], [2011Q3], [2011Q4], [2012Q1])
) AS pvt
@breckenedge
breckenedge / download_urls_from_osti
Created March 29, 2011 15:19
used to download pdfs from the OSTI.GOV information bridge
require 'rubygems'
require 'mechanize'
require 'progressbar'
docs = File.readlines('URLS.txt')
pb = ProgressBar.new('downloading', docs.length)
docs.each do |line|
url = line.strip
if !File.exist?(File.basename(url))