Skip to content

Instantly share code, notes, and snippets.


Tim Lowrimore tlowrimore

View GitHub Profile
tlowrimore / jankylog.js
Created Sep 9, 2020
A janky-ass console logger for debugging web apps in iOS Safari, when you don't just have a Mac lying around for accessing a debug console.
View jankylog.js
function jankylog(msg) {
let konsole = document.getElementById('jankylog');
if(!konsole) {
konsole = document.createElement('pre'); = 'jankylog'; = 'white'; = '1rem';
tlowrimore / set_operations.rb
Created Mar 10, 2016
Extends the functionality set forth in union_scope.rb, to include EXCEPT and INTERSECT operations
View set_operations.rb
module ActiveRecord
module Scopes
module SetOperations
extend ActiveSupport::Concern
class_methods do
def union_scope(*scopes)
apply_operation 'UNION', scopes
tlowrimore / address_books_controller.rb
Last active Sep 22, 2021
Keeps your API lookin' good! No need for all that nested_attributes pollution in your request/response payloads
View address_books_controller.rb
class V1::AddressBooksController < V1::BaseController
def create
@address_book = address_book_params
errors = @address_book.errors.to_hash(true)
render status: 422, json: { errors: errors }
tlowrimore / palindrome.rb
Created Mar 12, 2014
Detects whether a number is palindromic without converting the number to a String.
View palindrome.rb
module Palindrome
def self.palindrome?(n)
n == reverse(n)
def self.reverse(n)
rs = 0
while n > 0
n, r = n.divmod 10
rs = rs * 10 + r
tlowrimore / vigenere.rb
Last active Aug 29, 2015
A Naive (Somewhat Readable) Vigenére Cipher
View vigenere.rb
module Vigenere
def self.encrypt(key, phrase)
exec key, phrase
def self.decrypt(key, phrase)
exec key, phrase, -1
def self.exec(key, phrase, direction=1)
View controller.rb
module Sluggo::Controller
MATCHER = /(^.+)-(.*$)/
def self.included(base)
base.send :include, InstanceMethods
module InstanceMethods
tlowrimore / or_scope.rb
Created Mar 27, 2013
OR's together provided scopes, returning an ActiveRecord::Relation. This implementation is smart enough to not only handle your _where_ clauses, but it also takes care of your joins! *Note* This is a work in progress, so it has room to grow
View or_scope.rb
module ActiveRecord::OrScope
def self.included(base)
base.send :extend, ClassMethods
module ClassMethods
def or_scope(*scopes)
conditions =
.map { |scope| "(#{{ |clause| "(#{clause})"}.join(" AND ")})" }
tlowrimore / assets_gz.conf
Last active Dec 14, 2015
Apache config directives for serving Rails's precompiled .gz files, created by the asset pipeline during precompile.
View assets_gz.conf
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
RewriteEngine On
RewriteCond %{HTTP:Accept-Encoding} gzip
tlowrimore / union_scope.rb
Last active Nov 9, 2021
Unions multiple scopes on a model, and returns an instance of ActiveRecord::Relation.
View union_scope.rb
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.#{primary_key}"
sub_query = { |s| }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"
tlowrimore / gist:3842767
Created Oct 5, 2012
troublesome Vagrantfile
View gist:3842767
# -*- mode: ruby -*-
# vi: set ft=ruby :
base_box = "precise64"
# ------------------------------------------------------------------------------
# Short-hand node defs.
# ------------------------------------------------------------------------------
nodes = {
:eh_app_node => {