Skip to content

Instantly share code, notes, and snippets.

Anson Hoyt ansonhoyt

Block or report user

Report or block ansonhoyt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ansonhoyt
ansonhoyt / excelToJson.rb
Created Mar 1, 2012
Convert Excel of Arbitrary Tasks to JSON
View excelToJson.rb
#!/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 Sep 28, 2012
Demonstrate bugs in CKEditor 4 Beta
View config.js
/* 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 Mar 27, 2013
Finds words of a given length that are made from the given letters. Helps solve puzzles in the "Four Pictures, One Word" game.
View puzzle.rb
#!/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 Dec 16, 2015
Authorizing polymorphic association with CanCan 1.6.9
View ability.rb
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 Jan 3, 2016
`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.
View Erb::scaffold_generator.rb
# 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 Mar 22, 2018
Download all link's target files for the given selector
View linkSelector.js
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 Sep 25, 2018
Values that cause Homebrew's CacheStateDatabase.set to segfault
View CacheStoreDatabase_example.md

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 Sep 26, 2018
Homebrew test case: brew doctor with 1.7.6-9-g2ea3aee and old linkage.db
View brew config
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
You can’t perform that action at this time.