Skip to content

Instantly share code, notes, and snippets.

Avatar
🌯

Tim Morgan RISCfuture

🌯
View GitHub Profile
@RISCfuture
RISCfuture / 1password-scan-fix.rb
Last active Oct 2, 2021
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](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.
View update-all-the-things.sh
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 Jun 6, 2022
Adding TypeScript to a Rails + Webpacker + Vue project
View typescript-vue.md

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
View .rubocop.yml
# Bundler/OrderedGems:
# Exclude:
# - 'Gemfile'
Layout/CaseIndentation:
IndentOneStep: true
Layout/DotPosition:
EnforcedStyle: trailing
@RISCfuture
RISCfuture / mdtable.rb
Created May 29, 2014
mdtable: Clean up Markdown tables in code comments and Markdown files
View mdtable.rb
#!/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 Sep 30, 2015
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|
thread.join
end
end
@RISCfuture
RISCfuture / validates_uniqueness_of.rb
Created May 2, 2009
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 }
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
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")
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?