Skip to content

Instantly share code, notes, and snippets.

View adamcrown's full-sized avatar

Adam Crownoble adamcrown

View GitHub Profile
@adamcrown
adamcrown / add_netid_to_prod_center_accounts
Created January 22, 2015 20:12
Add NetIDs to CSV for production center accounts
#!/usr/bin/env ruby
script_name = File.basename(__FILE__)
file_path = ARGV[0]
abort "No input CSV file provided. Example: #{script_name} ./prod_center_accounts.csv" if file_path.nil?
abort 'File must have a .csv extension' unless file_path =~ /\.csv\Z/
new_file_path = file_path.gsub(/\.csv\Z/, '_with_netids.csv')
@adamcrown
adamcrown / config.ru
Created August 21, 2014 16:02
Example Sinatra rack-cas app
# Run with command:
# CAS_SERVER="http://example.com/login" rackup
require 'sinatra/base'
require 'rack/cas'
require 'yaml'
class SinatraRackCASExample < Sinatra::Base
before do
unless session['cas'] && session['cas']['user']
@adamcrown
adamcrown / Gemfile
Last active August 29, 2015 14:05
Simple static asset serving rack app
source 'https://rubygems.org'
gem 'rack'
@adamcrown
adamcrown / log.rb
Created June 4, 2014 15:45
Easy global log for Ruby
# Usage:
# Log.info 'done'
# Log.debug @var.inspect
# Log.error 'OH NOES!!!1'
# etc.
module Log
def self.method_missing(meth, *args, &block)
if logger.respond_to? meth
logger.send meth, *args, &block
@adamcrown
adamcrown / etc-hosts
Last active August 29, 2015 14:01
/etc/hosts file for Biola web servers
10.200.160.83 apps.static1.prod.biola.edu
10.200.160.83 career.static1.prod.biola.edu
10.200.160.83 wireless.static1.prod.biola.edu
10.200.160.83 www.static1.prod.biola.edu
10.200.160.246 academics.ruby2.staging.biola.edu
10.200.160.246 answers.ruby2.staging.biola.edu
10.200.160.246 api.ruby2.staging.biola.edu
10.200.160.246 apps.ruby2.staging.biola.edu
10.200.160.246 forms.ruby2.staging.biola.edu
@adamcrown
adamcrown / everbridge_csv_to_sql
Created October 11, 2013 17:55
Converts an Everbridge.net group export CSV file into a SQL query to insert data into the everbridge_user table in Biola's WS database. The purpose being to resync WS with Everbridge if it has gotten out of sync.
#!/usr/bin/env ruby
require 'csv'
file = ARGV.first
TABLE = 'everbridge_user'
date_modified = Time.now.strftime '%Y-%m-%d %H:%M:%S'
CSV.foreach(file, headers: :first_row) do |row|
@adamcrown
adamcrown / upay.css
Last active December 16, 2015 21:59
Bootstrap style uPay CSS
* { margin: 0; }
html, body { height: 100%; font-family: Arial, Helvetica, sans-serif; }
body { background: #f5f5f5; }
img { border-style: none; font-weight: normal; }
a:link, a:visited { color: #009; font-weight: bold; text-decoration: none; }
a:hover, a:active { color: #6cb33f; font-weight: bold; text-decoration: none; outline: none; }
a:focus, a:active { outline: none; }
:focus { outline-style: none; }
.clear { clear: both; margin: 0px; padding: 0px; height: 1px; }
p { color: #333; margin: 0px 0px 5px; font-size: 0.8em; display: block; width: 100%; }
@adamcrown
adamcrown / batch_delete_od_users.rb
Created February 5, 2013 17:57
A couple simple classes to aid in batch searching and deleting users from a local Apple Open Directory server
class LocalODServer
attr_accessor :username, :password
def initialize(username, password)
@username = username
@password = password
end
def ip
'127.0.0.1'
@adamcrown
adamcrown / faye.conf
Created January 31, 2013 19:01
Faye + RVM + thin upstart script
description "faye"
version "1.0"
author "Adam Crownoble"
env LANG=en_US.UTF-8
env APP_ROOT=/srv/rack/faye-server
start on startup
stop on shutdown
@adamcrown
adamcrown / active_record_sessions_batch_delete.rb
Last active December 11, 2015 00:18
Deleting a large batch of session records can really overload the DB (at least MySQL). This script paces it out a bit.
def batch_session_prune(keep_after = 1.month.ago, batch_by = 1.day, pause_time = 10)
time = ActiveRecord::SessionStore::Session.order(:updated_at).first[:updated_at]
while time < keep_after
time = time + batch_by
puts "Deleting sessions from #{time.to_s(:short)}"
ActiveRecord::SessionStore::Session.where('updated_at < ?', time).delete_all
sleep pause_time