Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
joshmcarthur / git-browse
Created February 27, 2012 20:05
git-browse: Open repositories in Github from a Terminal
#!/usr/bin/env ruby
#### git-browse
### Open a github repository in the default browser
### Author: @sudojosh
### Usage: Run `git browse` inside a repo with at least one github remote
### Installation: Download, run `chmod +x git-browse`, and then copy somewhere on your path
### for example, /usr/local/bin/
remotes = `git remote -v`
@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 / .vimrc.local
Created December 12, 2011 22:14
Add JBuiler syntax highlighting to VIM
" add jbuilder syntax highlighting
au BufNewFile,BufRead *.json.jbuilder set ft=ruby
@joshmcarthur
joshmcarthur / trello-cards-from-csv.rb
Created May 30, 2012 22:32
A Ruby script to import Trello cards from a CSV file
#!/usr/bin/env ruby
# You can skip this bit if you wish - you will need the 'ruby-trello' gem installed, and
# optionally, 'foreman' to run the script with.
require 'bundler/setup'
Bundler.require
require 'trello'
require 'csv'
@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).
*/
@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 / gist:1135392
Created August 9, 2011 22:39
A method to calculate BMI in C#
#region Calculations
/** <summary>A method to calculate Body-Mass Index (BMI) from a given weight and height</summary>
* <param name="weight">The person's weight in kilograms</param>
* <param name="height">The person's height in kilograms</param>
*/
public decimal CalculateBMI(decimal weight, decimal height) {
bmi = Math.pow(weight / height, 2)
return Math.round(bmi, 2)
@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 / email.yml
Created March 31, 2014 03:39
Load email settings from a YAML configuration file
# config/email.yml
---
test:
:delivery_method: :test
:url_host: 'localhost:3000'
development:
:delivery_method: :smtp
:host: "localhost:1025"
production:
:delivery_method: :smtp