Skip to content

Instantly share code, notes, and snippets.

View erkattak's full-sized avatar

Erik Straub erkattak

View GitHub Profile
\set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]%# '
\set PROMPT2 '[more] %R > '
-- By default, NULL displays as an empty space. Is it actually an empty
-- string, or is it null? This makes that distinction visible.
\pset null '[NULL]'
-- Use table format (with headers across the top) by default, but switch to
-- expanded table format when there's a lot of data, which makes it much
-- easier to read.
\x auto
-- Verbose error reports.
@erkattak
erkattak / turbo_dev.rb
Created August 27, 2014 15:53
TurboDev - Speed up Rails development environment's asset serving
# from https://github.com/discourse/discourse/blob/21e08a423e8839c6bacb4ee688b924a4fb71113f/lib/middleware/turbo_dev.rb
# lib/middleware/turbo_dev.rb
module Middleware
# Cheat and bypass Rails in development mode if the client attempts to download a static asset
# that's already been downloaded.
#
class Allocation < AR::Base
# allocations schema
# - line_item_id - indexed
# - type - string [ ‘CreditAllocation’, ‘DebitAllocation’ ] - indexed
# - allocatable_id - integer - indexed
# - amount - integer
belongs_to :line_item
belongs_to :allocatable, class_name: ‘LineItem’
end
{
"animation_enabled": false,
"auto_complete_commit_on_tab": true,
"auto_complete_with_fields": true,
"bold_folder_labels": true,
"caret_extra_width": 2,
"caret_style": "phase",
"color_scheme": "Packages/User/Tomorrow-Night.tmTheme",
"copy_with_empty_selection": false,
"create_window_at_startup": false,
@erkattak
erkattak / procs_on_procs.rb
Last active December 21, 2015 04:49
how would one refactor this?
DeviceCloud.event_notification_processors = [ ParkingSessionEventHandler, ParkingLotEventHandler, PermitPurchaseEventHandler ]
DeviceCloud.event_notification_handler = Proc.new do |event_notification|
DeviceCloud.event_notification_processors.each { |processor| processor.perform_async(event_notification.raw_data) if processor.processable?(event_notification.type) }
end
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch(%r{^spec/factories/.+\.rb$})
@erkattak
erkattak / irb.log
Created July 24, 2013 21:21
Should the aggregate feed be empty here?
irb(main):001:0> ActivityFeedItem.all
ActivityFeedItem Load (4.1ms) SELECT "activity_feed_items".* FROM "activity_feed_items"
=> [#<ActivityFeedItem id: 1, municipality_id: 1, nickname: "Coin Door Closed", item_type: "sentry_alert", title: "coin_vault_door_closed", text: "DIGI DUAL 2: Coin Door Closed ", created_at: "2013-07-24 21:03:30", updated_at: "2013-07-24 21:03:30">]
irb(main):002:0> ActivityFeed.feed 1, 1
ActivityFeedItem Load (787.7ms) SELECT "activity_feed_items".* FROM "activity_feed_items" WHERE (id in ('1','30','29','28','27'))
=> [#<ActivityFeedItem id: 1, municipality_id: 1, nickname: "Coin Door Closed", item_type: "sentry_alert", title: "coin_vault_door_closed", text: "DIGI DUAL 2: Coin Door Closed ", created_at: "2013-07-24 21:03:30", updated_at: "2013-07-24 21:03:30">]
irb(main):003:0> ActivityFeed.feed 1, 1
ActivityFeedItem Load (1.6ms) SELECT "activity_feed_items".* FROM "activity_feed_items" WHERE (id in ('1','30','29','28','27'))
=> [#<ActivityFeedItem id: 1, municipality_id: 1,
class A < ActiveRecord::Base
serialize :foo, FooSerializer
class FooSerializer
attr_accessor :attributes, :to, :be, :serialized
end
end
@erkattak
erkattak / date_time_formats.rb
Created April 2, 2013 01:41
Throw this in an initializer and you'll be able to display date/time strings however you want. Just pass object.date_field.to_s(:time_with_zone), etc.
Time::DATE_FORMATS.merge!(
datetime_military: '%Y-%m-%d %H:%M',
datetime: '%Y-%m-%d %I:%M%P',
time: '%l:%M%p',
time_with_zone: '%l:%M%p %Z',
time_military: '%H:%M%P',
datetime_short: '%m/%d %I:%M',
date: '%e',
day: '%a',
time_zone: '%Z',
@erkattak
erkattak / cash_transaction_spec.rb
Created October 22, 2012 14:50
BigDecimal Float comparison
require 'spec_helper'
describe CashTransaction do
context "when transaction is not a refund" do
subject { CashTransaction.new refund: false }
context "when an amount is positive" do
before(:each) do
subject.amount = 19.90
subject.save
end