Skip to content

Instantly share code, notes, and snippets.

View RISCfuture's full-sized avatar

Tim Morgan RISCfuture

View GitHub Profile
RISCfuture / 1pw-u2f.rb
Created July 29, 2023 04:02
Find sites in 1Password that support Universal Two-Factor
View 1pw-u2f.rb
require 'json'
require 'uri'
require 'net/http'
require 'active_support/core_ext/enumerable'
directory_uri = URI.parse('')
directory_sites = JSON.parse(Net::HTTP.get(directory_uri))
.map(&:last).index_by { |s| s['domain'] }
op_sites = JSON.parse(`op item list --categories login --format=json`)
RISCfuture / 1password-scan-fix.rb
Last active October 2, 2021 00:48
Scan and fix 1Password passwords
View 1password-scan-fix.rb
### 1password-scan-fix.rb ###
# This script locates 1Password passwords linked to URLs that either a)
# redirect to a newer URL or b) fail to load. For each of these URLs, you will
# be prompted as to whether you would like to modify or delete the URL.
# This script requires the
# [1Password CLI](
# (`brew install 1password-cli`). You will need to sign in to 1Password CLI
# by following the instructions on that web page first.
softwareupdate -i -a
if hash mas 2>/dev/null; then
mas upgrade
if hash brew 2>/dev/null; then
brew update
brew upgrade
brew upgrade --cask --greedy
RISCfuture /
Last active June 3, 2023 05:48
Adding TypeScript to a Rails + Webpacker + Vue project

Adding TypeScript to a Rails + Webpacker + Vue project

These instructions assume you already have a Rails 5.2 project using Webpacker 4 with Vue 2 and Vuex 3. I'll show you how to add TypeScript to the project, and type-safe your Vue components, including single-file components (SFCs). This document will not teach you TypeScript syntax or type theory. It also assumes your code already works without TypeScript. You shouldn't use this article to, for example, get started with Vuex, because I'm leaving out lots of necessary boilerplate code and focusing just on TypeScript changes.

If you want to see a commit on a project accomplishing this migration, visit


  1. Run rails webpacker:install:typescript. This should modify config/webpacker.yml and config/webpack/environment.js (leave those changes), add tsconfig.json and config/webpack/loaders/typescript.js (leave those files), and add some other files in `a
RISCfuture / .rubocop.yml
Created March 13, 2018 19:57
WIP RuboCop
View .rubocop.yml
# Bundler/OrderedGems:
# Exclude:
# - 'Gemfile'
IndentOneStep: true
EnforcedStyle: trailing
RISCfuture / mdtable.rb
Created May 29, 2014 01:51
mdtable: Clean up Markdown tables in code comments and Markdown files
View mdtable.rb
#!/usr/bin/env ruby
require 'find'
def parse_cells(row)
def header?(cells)
cells.all? { |cell| cell =~ /^:?\-+:?$/ }
RISCfuture / rails_template.rb
Last active September 30, 2015 20:27
Tim's Awesome Rails Template
View rails_template.rb
# encoding: utf-8
require 'open3'
def rvm_env(cmd)
Open3.popen3 "bash -c 'source ~/.rvm/scripts/rvm && #{cmd}'" do |stdin, stdout, stderr, thread|
RISCfuture / validates_uniqueness_of.rb
Created May 2, 2009 02:01
Reimplementation of validates_uniqueness_of that works optimally with MySQL.
View validates_uniqueness_of.rb
module ActiveRecord::Validations::ClassMethods
def validates_uniqueness_of(*attr_names)
configuration = { :case_sensitive => true }
validates_each(attr_names,configuration) do |record, attr_name, value|
# The check for an existing value should be run from a class that
# isn't abstract. This means working down from the current class
# (self), to the first non-abstract class. Since classes don't know
# their subclasses, we have to build the hierarchy between self and
RISCfuture / find_in_batches.rb
Created May 1, 2009 23:30
Reimplementation of find_in_batches that fixes bugs and works with composite_primary_keys
View find_in_batches.rb
module ActiveRecord::Batches
def find_in_batches(options = {})
relation = self
unless arel.orders.blank? && arel.taken.blank?
ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
if (finder_options = options.except(:start, :batch_size)).present?
raise "You can't specify an order, it's forced to be #{batch_order}" if options[:order].present?