Skip to content

Instantly share code, notes, and snippets.

View tlowrimore's full-sized avatar

Tim Lowrimore tlowrimore

View GitHub Profile
@tlowrimore
tlowrimore / address_books_controller.rb
Last active February 22, 2023 20:24
Keeps your API lookin' good! No need for all that nested_attributes pollution in your request/response payloads
class V1::AddressBooksController < V1::BaseController
def create
@address_book = AddressBook.new address_book_params
unless @address_book.save
errors = @address_book.errors.to_hash(true)
render status: 422, json: { errors: errors }
end
end
private
@tlowrimore
tlowrimore / set_operations.rb
Created March 10, 2016 17:41
Extends the functionality set forth in union_scope.rb, to include EXCEPT and INTERSECT operations
module ActiveRecord
module Scopes
module SetOperations
extend ActiveSupport::Concern
class_methods do
def union_scope(*scopes)
apply_operation 'UNION', scopes
end
@tlowrimore
tlowrimore / jankylog.js
Created September 9, 2020 18:32
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.
function jankylog(msg) {
let konsole = document.getElementById('jankylog');
if(!konsole) {
konsole = document.createElement('pre');
konsole.id = 'jankylog';
konsole.style.backgroundColor = 'white';
konsole.style.padding = '1rem';
document.body.append(konsole);