Skip to content

Instantly share code, notes, and snippets.

View ansonhoyt's full-sized avatar

Anson Hoyt ansonhoyt

  • 22:49 (UTC -04:00)
View GitHub Profile
@ansonhoyt
ansonhoyt / excelToJson.rb
Created March 1, 2012 03:03
Convert Excel of Arbitrary Tasks to JSON
#!/usr/bin/env ruby
# Reads an Excel and writes as JSON
# - Assumes header row containing field names, first sheet is read
# - Keeps null values
#
# TODO:
# - accept filename and read based on extension (xlsx, xls, csv).
# - output actual JSON.
# - clean up.
@ansonhoyt
ansonhoyt / config.js
Created September 28, 2012 12:54
Demonstrate bugs in CKEditor 4 Beta
/* Example Configuration for CKEditor Beta 4
*/
CKEDITOR.editorConfig = function(config) {
config.toolbarStartupExpanded = false; // Bug: toolbar doesn't render at all.
// config.toolbarStartupExpanded = true; // This works fine. Toolbar can be collapsed.
config.toolbarCanCollapse = true;
}
@ansonhoyt
ansonhoyt / puzzle.rb
Created March 27, 2013 12:33
Finds words of a given length that are made from the given letters. Helps solve puzzles in the "Four Pictures, One Word" game.
#!/usr/bin/envy ruby
#
# Finds words of a given length that are made from the given letters.
# Helps solve "Four Pictures, One Word" puzzles.
# @author Anson Hoyt
require 'optparse'
# Parse command line arguments
def parse(args)
@ansonhoyt
ansonhoyt / ability.rb
Last active December 16, 2015 02:59
Authorizing polymorphic association with CanCan 1.6.9
class Ability
include CanCan::Ability
def initialize(user, session=nil)
@user = user
@session = session
@user ? user_rules : public_rules
end
def user_rules
@ansonhoyt
ansonhoyt / Erb::scaffold_generator.rb
Last active January 3, 2016 14:39
`rails g scaffold` or `rails g scaffold_controller` never invokes my override of Erb::Generators::ScaffoldGenerator. I can workaround by setting `config.generators.template_engine :all` and moving the override there. That feels wrong.
# lib/generators/erb/scaffold/scaffold_generator.rb
# See http://stackoverflow.com/questions/4696954/how-to-have-the-scaffold-to-generate-another-partial-view-template-file
# require 'rails/generators/erb'
# require 'rails/generators/resource_helpers'
require 'rails/generators/erb/scaffold/scaffold_generator' # see http://stackoverflow.com/questions/16320882/rails-generate-both-html-and-js-views-with-scaffold
module Erb # :nodoc:
module Generators # :nodoc:
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator # :nodoc:
@ansonhoyt
ansonhoyt / linkSelector.js
Created March 22, 2018 18:29
Download all link's target files for the given selector
let linkSelector = '.download-button';
document.querySelectorAll(linkSelector).forEach(function(link) {
let clone = link.cloneNode(); // avoid existing event listeners
clone.setAttribute('download', ''); // indicate the download action
clone.click(); // trigger the download
});
@ansonhoyt
ansonhoyt / CacheStoreDatabase_example.md
Created September 25, 2018 16:59
Values that cause Homebrew's CacheStateDatabase.set to segfault

In CacheStoreDatabase.set(key, value) the statement db[key] = value fails for:

key:

/usr/local/Cellar/qt-4/4.8.7

value:

{"keg_files_dylibs":{"/usr/local/Cellar/qt-4/4.8.7/Assistant.app/Contents/MacOS/Assistant":["/usr/local/Cellar/qt-4/4.8.7/lib/QtHelp.framework/Versions/4/QtHelp","/usr/local/Cellar/qt-4/4.8.7/lib/QtSql.framework/Versions/4/QtSql","/usr/local/Cellar/qt-4/4.8.7/lib/QtCore.framework/Versions/4/QtCore","/usr/local/Cellar/qt-4/4.8.7/lib/QtGui.framework/Versions/4/QtGui","/usr/local/Cellar/qt-4/4.8.7/lib/QtNetwork.framework/Versions/4/QtNetwork","/usr/local/Cellar/qt-4/4.8.7/lib/QtWebKit.framework/Versions/4/QtWebKit","/usr/lib/libc++.1.dylib","/usr/lib/libSystem.B.dylib"],"/usr/local/Cellar/qt-4/4.8.7/Designer.app/Contents/MacOS/Designer":["/usr/local/Cellar/qt-4/4.8.7/lib/QtDesignerComponents.framework/Versions/4/QtDesignerComponents","/usr/local/Cellar/qt-4/4.8.7/lib/QtDesigner.framework/Versions/4/QtDesigner","/usr/local/Cellar/qt-4/4.8.7/lib/QtScript.framework/Versions/4/QtS
@ansonhoyt
ansonhoyt / brew config
Last active September 26, 2018 12:11
Homebrew test case: brew doctor with 1.7.6-9-g2ea3aee and old linkage.db
HOMEBREW_VERSION: 1.7.6-9-g2ea3aee
ORIGIN: https://github.com/Homebrew/brew.git
HEAD: 2ea3aee461f4b2f22ccc9b6f72b4426448bc1039
Last commit: 27 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: ae68a80c0257579b3c109cb56c53c6dcc979d984
Core tap last commit: 22 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_DEV_CMD_RUN: 1
CPU: octa-core 64-bit haswell
@ansonhoyt
ansonhoyt / invalid_query_active_record_523.rb
Created June 24, 2019 19:50
ActiveRecord :has_many only partially applies a scoped :through association where the scope has #merge conditions.
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
@ansonhoyt
ansonhoyt / Gemfile
Created June 27, 2020 03:12 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers