Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
joshmcarthur / devise_mailer_preview.rb
Last active June 2, 2022 23:32
Devise ActionMailer::Preview
# spec/mailers/previews/devise_mailer_preview.rb
class DeviseMailerPreview < ActionMailer::Preview
# We do not have confirmable enabled, but if we did, this is
# how we could generate a preview:
# def confirmation_instructions
# Devise::Mailer.confirmation_instructions(User.first, "faketoken")
# end
def reset_password_instructions
@joshmcarthur
joshmcarthur / index.html
Created August 10, 2020 06:08
Lighthouse requestig malformed URLs // source https://jsbin.com/repidit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Lighthouse requestig malformed URLs</title>
</head>
<body>
<img width="200" height="420" src="https://lorempixel.com/420/320/abstract/1/Sample?query-param-to-get-over-75-chars" />
@joshmcarthur
joshmcarthur / load_fixtures.rb
Last active July 9, 2020 23:00
How to load fixtures one at a time in Rails 5
# When Rails loads fixtures, it does so via a big multi-insert. If there is something wrong with a
# fixture, it's extremely difficult to find out _which_ fixture is wrong.
# This can be run in a binding.pry OR in a Rails console.
require "active_record/fixtures"
all = fixture_set_names = Dir["spec/fixtures/**/*.yml"].map { |f| File.basename f, '.yml' }
all.each do |fix|
puts fix; ActiveRecord::FixtureSet.create_fixtures("#{Rails.root}/spec/fixtures", [fix])
@joshmcarthur
joshmcarthur / sanitized_file.rb
Last active May 20, 2020 21:50
Patch CarrierWave to test file content type using UNIX's 'file' utility
# lib/carrierwave_ext/sanitized_file.rb
require "carrierwave/sanitized_file"
module CarrierWave
class SanitizedFile
##
# Returns the content type of the file.
#
# === Returns
#
@joshmcarthur
joshmcarthur / example.html
Created February 13, 2019 02:54
IE9 Download Example
<html>
<head>
<title>IE9 Download Example</title>
<script>
function legacyBrowserSave(content, filename) {
var frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.contentWindow.document.open("text/html", "replace");
frame.contentWindow.document.write(content);
@joshmcarthur
joshmcarthur / playground.rb
Created August 19, 2018 21:30
Self-referential, unidirectional has many through association
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "activerecord"
gem "sqlite3"
gem "minitest"
end
require "minitest/autorun"
/*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*/
#define MY_RADIO_NRF24
#define CHILD_ID_HVAC 10
#define MY_DEBUG
#include <MySensors.h>
@joshmcarthur
joshmcarthur / jquery-ajax-retry.js
Created September 13, 2016 00:14
jQuery AJAX Prefilter for retrying failed XHR requests with backoff delay
/**
* This AJAX prefilter is based on http://stackoverflow.com/a/12840617 with some changes:
* 1. References to the question asker's context have been removed (they related to Auth)
* 2. Fixes have been made to code style at JSHint's request.
* 3. Assign max retries so that we can determine how many retries we STARTED from.
* 4. Add a setTimeout call so that the retried requests wait before performing the request.
* 5. Treat a '0' status as an error. (JM: I believe this is because Ember fakes it's own 'XHR' object
* that doesn't contain the actual request status code).
*/
# Like rspec --format doc, (which minitest doesn't have)
#
# usage: minidoc test/integration/robs_cool_potatoes_test.rb
minidoc() {
rscript='
red = "\e[0;31m"
purple = "\e[0;35m"
green = "\e[0;32m"
blue = "\e[0;34m"
none = "\e[0m"
@joshmcarthur
joshmcarthur / jquery.tableflip.js
Created February 11, 2015 22:20
jquery.tableflip.js
jQuery.fn.tableflip = function() {
console.log("╯°□°)╯︵ ┻━┻");
return this;
}