Skip to content

Instantly share code, notes, and snippets.

View nacengineer's full-sized avatar

David Southard nacengineer

  • UW Madison, General Library System
  • Madison, WI
  • 13:38 (UTC -05:00)
View GitHub Profile
@nacengineer
nacengineer / bootstrap_modal.rb
Created June 18, 2012 01:56
Add a Twitter Bootstrap Modal picture array to your view. (HAML, RAILS 3.2, Google Picasa)
# This is how I leveraged twitter bootstrap modals http://twitter.github.com/bootstrap/javascript.html#modals
# in Rails 3.2 with bootstrap-sass working. This is HAML syntax. With Twitter Bootstrap > 2.0.3.1. The pictures are
# pulled from Google Picasa Web Albums and are the url to the thumbnail image. This also explains the .gsub in the
# helper as I swap the thumbnail out out with a larger image. This will give you a thumbnail array similar to the
# "more examples" one on this page http://twitter.github.com/bootstrap/components.html#thumbnails
# in your helper file.
require 'securerandom'
def modal_page( image )
@nacengineer
nacengineer / gsub.rb
Created June 26, 2012 20:25
gsub regex for whitespace
some_string.gsub(/\s+/, "")
@nacengineer
nacengineer / setup-statsd.sh
Created August 2, 2012 23:25 — forked from collegeman/setup-statsd.sh
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
@nacengineer
nacengineer / flay.rb
Last active December 10, 2015 00:49
A simple method to add to test helpers for displaying error messages
# assumptions: rails, object responds to errors
# in your test use this line where object is the object being validated
# :msg => flay_the_errors(__method__).call( object.errors)
def flay_the_errors( method )
Proc.new do |x|
y = "\n### oh noes #{method} failed! ###\n"
y << "Full Inspect:\n"
y << x.inspect << "\n"
x.each {|k,v| y << "- #{k} #{v}\n"}
y
@nacengineer
nacengineer / holiday.rb
Last active December 10, 2015 15:29
Simple Object to return Christmas and Thanksgiving as Date and query if its the Christmas holiday season
# also check out this sweet gem! https://github.com/alexdunae/holidays
class Christmas
attr_reader :christmastime, :christmas, :usa_thanksgiving
def initialize
@christmastime = is_christmastime?
end
def is_christmastime?(seed_date = Date.today, padding = 0)
@nacengineer
nacengineer / iterate.rb
Created January 16, 2013 19:36
quick iteration
a = []
@user.user_logins.each do |x|
a << x.created_at
end
# now a should have all the entries you need
a.inspect
@nacengineer
nacengineer / user_login.rb
Last active December 11, 2015 05:19
user login objects
<% @user.login_list.each do |n| %>
<li><%= n %></li>
<% end %>
# chain this onto the object
def self.last_five(id)
where(:id => id).limit(5).sort('descending')
end
@nacengineer
nacengineer / unicorn_control.sh
Created January 18, 2013 02:23
Unicorn Control Script with some Princess Bride Sprinkled in.
#!/usr/bin/env bash
# Modified for Rails 3 by Dave Southard January 17th, 2012
# Now with more princess bride!
RAILS_ENV=production
APP_ROOT=/var/rails/unicorn/$1
CURRENT_APP=$APP_ROOT/current
PID=/etc/unicorn/pids/$1.pid
OLD_PID=$PID.oldbin
START_COMMAND="bundle exec unicorn -D -E $RAILS_ENV -c /etc/unicorn/conf/$1.conf"
@nacengineer
nacengineer / sublime_text_2_user_settings.json
Created January 22, 2013 21:33
my sublime text user settings
{
"binary_file_patterns":
[
"*.jpg",
"*.jpeg",
"*.png",
"*.gif",
"*.ttf",
"*.tga",
"*.dds",
@nacengineer
nacengineer / meow.scss
Created January 23, 2013 03:03
An SCSS version of Zac Stewart's Meow CSS
.meows {
position: fixed;
top: 0;
right: 0;
}
.meow {
margin: 20px 20px 0 0;
position: relative;