Skip to content

Instantly share code, notes, and snippets.

Exception in thread 1: comparison of Fixnum with nil failed
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:510:in `>'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:510:in `upto'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:510:in `define_columns'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:127:in `exec'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-plsql-0.5.0/lib/plsql/oci_connection.rb:97:in `exec'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-plsql-0.5.0/lib/plsql/oci_connection.rb:82:in `new_from_query'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-plsql-0.5.0/lib/plsql/oci_connection.rb:132:in `cursor_from_query'
/home/username/.rvm/gems/ruby-2.1.2@gemset/gems/ruby-plsql-0.5.0/lib/plsql/connection.rb:102:in `select_first'
/home/username/.rvm/gems/ruby-2.1.2@gemset/g
@mike-bourgeous
mike-bourgeous / find_rails_translations.sh
Created August 24, 2015 18:33
Shell command to help find possibly unused translations in a Rails app
#!/bin/sh
for f in `grep -o '[^ ]\+:' config/locales/en.yml | sed -e 's/:$//' | sed -e 's/^/:/'`; do
printf "\033[1m$f\033[0m\n"
grep -R "\.t(.*$f" || printf "\033[1;33mNONE FOR $f\033[0m\n"
done
@mike-bourgeous
mike-bourgeous / hl_backtrace.rb
Last active September 17, 2015 00:03
Quick-and-dirty ANSI highlight of standard Ruby backtraces
puts caller.map{|l|
l.sub(
%r{/([^:/]+):(\d+):in `([^']*)'},
"/\e[33m\\1\e[0m:\e[34m\\2\e[0m:in `\e[1;35m\\1\e[0m'"
)
}
@mike-bourgeous
mike-bourgeous / gc_stat.rb
Last active August 4, 2016 06:04
Convenient way to get GC stats for a block of Ruby code.
def gc_stat
GC.disable
asym = :total_allocated_objects
fsym = :total_freed_objects
before = GC.stat
ba = before[asym]
bf = before[fsym]
puts "Before: alloc=#{ba} free=#{bf}"
@mike-bourgeous
mike-bourgeous / quick_and_dangerous_struct.rb
Last active August 12, 2016 04:20
A toy version of OpenStruct, with no error checking
# Faster than OpenStruct, but liable to get your box pwned.
class QuickAndDangerousStruct
def method_missing(name, *args)
make_method(name)
send name, *args
end
def make_method(name)
name = name.to_s
base = name.end_with?('=') ? name[0..-2] : name
@mike-bourgeous
mike-bourgeous / oralaunch
Created August 16, 2016 00:20
Scripts to improve launching Oracle's sqlplus client (put these in ~/bin, call orasql)
#!/bin/sh
# Launches an application with the Oracle instant client environment set.
# Created by Mike Bourgeous, DeseretBook.com
export CLIENT_PATH=/usr/lib/oracle/11.2/client64/lib
export PATH="$PATH:$CLIENT_PATH"
export LD_LIBRARY_PATH="$CLIENT_PATH"
export SQLPATH="$HOME/.oracle:$CLIENT_PATH"
export TNS_ADMIN="$HOME/.oracle"
export NLS_LANG="american_america.utf8"
@mike-bourgeous
mike-bourgeous / mk_sfx.sh
Created October 23, 2016 00:40 — forked from nitrogenlogic/00_mk_sfx_moved.md
Quick-and-dirty script to create a quasi-self-extracting bzipped tar archive
#!/bin/bash
# Creates a base64-encoded self-extracting tar archive. The extracting system
# must have GNU tar, GNU coreutils (for base64), and bzip2 installed.
# Created June 2011 by Mike Bourgeous
# Released into the public domain, or if that is not possible, under CC0
function create_archive()
{
set -e
echo '#!/bin/sh'
@mike-bourgeous
mike-bourgeous / posterous_import.rb
Created October 23, 2016 00:43 — forked from nitrogenlogic/00_posterous_import_moved.md
This quick and dirty script imports posts and images exported by the Posterous backup feature into Octopress. Requires the escape_utils and nokogiri gems. Doesn't import comments. See comments below the gist for more instructions.
#!/usr/bin/env ruby
# This quick and dirty script imports posts and images exported by the
# Posterous backup feature into Octopress. Requires the escape_utils and
# nokogiri gems. Doesn't import comments.
#
# Videos and images are copied into a post-specific image directory used
# by my customized Octopress setup. Encoded videos are downloaded from
# Posterous. Images will probably need to be compressed/optimized afterward.
#
# Links to other posts in the same import will try to be converted. You will
@mike-bourgeous
mike-bourgeous / swap_stderr.sh
Created October 23, 2016 00:45 — forked from nitrogenlogic/00_swap_stderr_moved.md
Swap stdout and stderr, log stderr to a file (BASH)
#!/bin/bash
test() {
echo "Standard out"
echo "Standard error" >&2
}
tmpfile=`mktemp`
test 3>&1 4>&2 2>&3- 1>&4- | tee $tmpfile
cat $tmpfile
@mike-bourgeous
mike-bourgeous / sequel_mssql_merge.rb
Last active December 14, 2016 08:47
SQL MERGE/UPSERT using the Sequel gem
# Code to perform a basic update/insert using MERGE. Tested with MSSQL
# and the TinyTDS adapter. Assumes DB contains a Sequel::Database.
require 'sequel'
module Merge
# Returns a Sequel::Dataset that will update or insert the given Array of
# Hashes of +data+ into the given named +table+, with the given primary
# +key+(s). Hash key names in +data+ must match the table's column names
# The dataset will return one row for each row that was inserted or updated,