Skip to content

Instantly share code, notes, and snippets.

View adamcrown's full-sized avatar

Adam Crownoble adamcrown

View GitHub Profile
@adamcrown
adamcrown / printing_from_an_oracle_function.sql
Created June 28, 2012 00:19
Printing the results of an Oracle function
-- Must me NUMBER or CHAR if you want to print it. Printing a VARCHAR is too complex for expensive databases like Oracle.
VARIABLE r CHAR (1000);
BEGIN
-- := is for assignment. vs = for equality
-- bind variables are prefixed with a colon
-- BANIST1 is the instance
-- BSK_INFO_REQUEST is the package
-- get_prel_codes() is the function
:r := BANINST1.BSK_INFO_REQUEST.get_prel_codes();
@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
@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 / 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 / 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 / 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 / elasticsearch-_all-test.sh
Created June 22, 2016 02:59
Elasticsearch edgengram fields in _all issue
# elasticsearch: Version: 2.3.3, Build: 218bdf1/2016-05-17T15:40:04Z, JVM: 1.8.0_92
# Arch Linux
# Kernel version 4.4.3-1-custom
# Setup a basic index using an edgengram filter
curl -XPUT "http://localhost:9200/test_index?pretty=true" -d'
{
"settings": {
"analysis": {
"filter": {
@adamcrown
adamcrown / job_role.html.slim
Last active September 15, 2016 16:48
Vue.js for accets_nested_attributes_for
#vue-job-requirements-app data-job-requirements=job_requirements_json(@job_role.job_requirements)
.form-group v-for="req in requirements"
input type="hidden" name="job_role[job_requirements_attributes][{{ $index }}][id]" value="{{ req.id }}"
input type="hidden" name="job_role[job_requirements_attributes][{{ $index }}][_destroy]" value="{{ req._destroy }}"
.input-group v-if="req._destroy != '1'" transition="fade-out"
input.form-control type="text" name="job_role[job_requirements_attributes][{{ $index }}][description]" value="{{ req.description }}"
.input-group-addon v-on:click="removeRequirement($index)"
i.fa.fa-times.text-danger
button.btn.btn-success.btn-xs type="button" v-on:click="addRequirement()"
i.fa.fa-plus
@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 / user.rb
Created October 25, 2016 03:19
couchrest_model User model
class User < CouchRest::Model::Base
self.database = server.database('_users')
def self.model_type_value() 'user' end
property :name
property :password
property :roles
property :_id
before_save :generate_id, :assign_admin_role