Skip to content

Instantly share code, notes, and snippets.

View RISCfuture's full-sized avatar
🌯

Tim Morgan RISCfuture

🌯
View GitHub Profile
@RISCfuture
RISCfuture / 1pw-u2f.rb
Created July 29, 2023 04:02
Find sites in 1Password that support Universal Two-Factor
require 'json'
require 'uri'
require 'net/http'
require 'active_support/core_ext/enumerable'
directory_uri = URI.parse('https://api.2fa.directory/v3/all.json')
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
RISCfuture / 1password-scan-fix.rb
Last active October 2, 2021 00:48
Scan and fix 1Password passwords
### 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](https://1password.com/downloads/command-line/)
# (`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
fi
if hash brew 2>/dev/null; then
brew update
brew upgrade
brew upgrade --cask --greedy
@RISCfuture
RISCfuture / typescript-vue.md
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 https://github.com/RISCfuture/AvFacts/commit/666a02e58b4626a074a03812ccdd193a3891a954.

Setup

  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
RISCfuture / .rubocop.yml
Created March 13, 2018 19:57
WIP RuboCop
# Bundler/OrderedGems:
# Exclude:
# - 'Gemfile'
Layout/CaseIndentation:
IndentOneStep: true
Layout/DotPosition:
EnforcedStyle: trailing
@RISCfuture
RISCfuture / mdtable.rb
Created May 29, 2014 01:51
mdtable: Clean up Markdown tables in code comments and Markdown files
#!/usr/bin/env ruby
require 'find'
def parse_cells(row)
row.split('|').map(&:strip)[1..-1]
end
def header?(cells)
cells.all? { |cell| cell =~ /^:?\-+:?$/ }
@RISCfuture
RISCfuture / rails_template.rb
Last active September 30, 2015 20:27
Tim's Awesome Rails Template
# encoding: utf-8
require 'open3'
def rvm_env(cmd)
Open3.popen3 "bash -c 'source ~/.rvm/scripts/rvm && #{cmd}'" do |stdin, stdout, stderr, thread|
thread.join
end
end
@RISCfuture
RISCfuture / validates_uniqueness_of.rb
Created May 2, 2009 02:01
Reimplementation of validates_uniqueness_of that works optimally with MySQL.
module ActiveRecord::Validations::ClassMethods
def validates_uniqueness_of(*attr_names)
configuration = { :case_sensitive => true }
configuration.update(attr_names.extract_options!)
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
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
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")
end
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?