Skip to content

Instantly share code, notes, and snippets.

View damien's full-sized avatar
🤝
Open for business! Hire me for your project at https://mindglob.com

Damien Wilson damien

🤝
Open for business! Hire me for your project at https://mindglob.com
View GitHub Profile
@damien
damien / team_membership.rb
Last active April 28, 2021 12:50
Using MiniTest to mock and test ActiveRecord callbacks in Rails 4.2
class TeamMembership < ActiveRecord::Base
# A proc that will enqueue `NotificationMailer.team_invitation`
DEFAULT_NOTIFIER = proc do |user, team|
NotificationMailer.team_invitation(team, user).deliver_later
end
class << self
# This is a class level attribute that is mainly used for testing.
# Defaults to {TeamMembership::DEFAULT_NOTIFIER}
attr_accessor :notifier
@damien
damien / git-log.txt
Created April 1, 2020 18:59
Git log after git subtree split+add
damien@Apollonius ~/workspace/Cataclysm-DDA [dinomod-subtree]
± % git log --oneline --decorate -- data/mods/DinoMod | wc -l
54
damien@Apollonius ~/workspace/Cataclysm-DDA [dinomod-subtree]
± % git log --oneline --decorate -- data/mods/DinoMod | cat
2b43ec698b (HEAD -> dinomod-subtree, origin/dinomod-subtree) Add 'data/mods/DinoMod/' from commit '0d385a83106bec4a9fc73d5576fe5b61974d0db9'
bfa16029be Prepare DinoMod for git subtree inclusion
5d76bd145b Aftershock and dinomod monsters name to object (#38963)
47499c5055 Change maintainer of DinoMod to @damien (#37490)
@damien
damien / weather.rb
Created April 2, 2009 21:06
A simple ruby script that will display the weather for a given zip code using Yahoo's weather API.
require 'net/http'
require 'rexml/document'
puts "Enter your zip code to get today's forecast"
print "Zip: "
zip = gets.chomp
if (zip.nil? or zip == 0)
puts "Invalid zip, program exiting."
@damien
damien / concerns-messagable_with_data.rb
Created July 12, 2012 23:06
Extending Mailboxer through Concerns
module Concerns
module MessagableWithData
extend ActiveSupport::Concern
included do
Message.class_eval do
has_many :message_data,
class_name: MessageData,
@damien
damien / date_time_comparisons_in_active_support.md
Last active July 15, 2016 14:15
Quick dive into how Rails/ActiveSupport does Date, Time, and DateTime comparisons

Date and Time comparisons in ActiveSupport

Question: How do we safely compare a date to an unknown value within a Rails application? Example: params[:date_field] > 2.years.ago

Doing a bit of digging, it looks like 2.years.ago returns an instance of ActiveSupport::TimeWithZone. In ruby, whenever you do a comparison of any sort ruby will follow the rules outlined in the Comparable module of stdlib.

ActiveSupport::TimeWithZone will create a instance of Time in a UTC time zone when doing comparisons with ActiveSupport::TimeWithZone#&lt;=&gt;.

@damien
damien / config.ru
Created August 15, 2011 21:35
A simple rack middleware to debug the request pipeline
# Usage example
require "inspect_middleware"
use InspectMiddleware
run GenericSinatraApp
@damien
damien / sql_query.sql
Last active December 19, 2015 10:09
This SQL query isn't working. :(
SELECT DISTINCT "posts".*
FROM "posts"
INNER JOIN memberships ON posts.group_id = memberships.group_id
WHERE (("posts"."published" = 't'
AND "memberships"."user_id" = 17403
OR "posts"."published" = 't'
AND "posts"."user_id" = 17403))
ORDER BY COALESCE(posts.liked_at, posts.updated_at, posts.created_at) DESC LIMIT 20
OFFSET 0
@damien
damien / Gemfile
Last active December 17, 2015 11:19
Strange IO errors that occur when I attempt to post multipart form data containing an image to a rails app running under Trinidad.
source 'https://rubygems.org'
# Requred for deployment with Trinidad
gem 'bundler'
gem 'rails', '3.2.13'
gem 'activeadmin'
gem 'activerecord-postgres-hstore' # PostgreSQL HStore support for ActiveRecord
gem 'airbrake' # using errbit, see config/errbit.rb
@damien
damien / jquery.serializeObject.js
Created March 4, 2013 05:01
Serialize Object plugin for jQuery. When used on a jQuery element containing a form, this plugin returns an object representation of the given form's data.
// Serialize a form into an object
// Credit goes to Tobias Cohen
// http://stackoverflow.com/a/1186309/51947
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
@damien
damien / stacktrace..txt
Created December 15, 2012 05:05
Null pointer exception from FTB
[21:00:13] LaunchFrame.main:141: FTBLaunch starting up (version 1.1.4)
[21:00:13] LaunchFrame.main:142: Java version: 1.7.0_01
[21:00:13] LaunchFrame.main:143: Java vendor: Oracle Corporation
[21:00:13] LaunchFrame.main:144: Java home: C:\Program Files\Java\jre7
[21:00:13] LaunchFrame.main:145: Java specification: Java Virtual Machine Specification version: 1.7 by Oracle Corporation
[21:00:13] LaunchFrame.main:147: Java vm: Java HotSpot(TM) 64-Bit Server VM version: 21.1-b02 by Oracle Corporation
[21:00:13] LaunchFrame.main:149: OS: amd64 Windows 7 6.1
[21:00:13] LocaleUpdater.checkForUpdates:46: [i18n] Checking for updates ...
[21:00:13] DownloadUtils.getStaticCreeperhostLink:95: http://repo.creeperhost.net/static/FTB2/locales
[21:00:14] LocaleUpdater.checkForUpdates:61: [i18n] remoteVer = 9