Skip to content

Instantly share code, notes, and snippets.

View mepatterson's full-sized avatar

M. E. Patterson mepatterson

View GitHub Profile
@mepatterson
mepatterson / README.md
Created September 8, 2020 22:09 — forked from leastbad/README.md
Choices.js Stimulus wrapper preview

Choices.js Stimulus wrapper

https://joshuajohnson.co.uk/Choices/

Soon, this will be published as an NPM package, but there's an absence of documentation right now. It supports almost all functions from the original library; soon it will support 100% of them.

This wrapper adds Ajax pre-fetch search. Happens if controller has a data-search-path attribute.

Stimulus controller targets use new v2 syntax. Controller attaches a reference to itself on the element so that you can access the internal state from external scripts.

import { Controller } from "stimulus";
import consumer from "../channels/consumer";
export default class extends Controller {
static targets = ["message"];
connect() {
this.element[this.identifier] = this;
consumer.subscriptions.create("NotificationChannel", {
@mepatterson
mepatterson / gist:5702783
Last active December 18, 2015 01:19
examples from my presentation on building a game industry Unlocks system with Goliath and Grape
# ====== TODAY'S KATA:
# * create an Achievements API
# * create an Achievement model, a User model, and a db table for many-many relationship between the two
# * now, write the Goliath+Grape code to create 3 endpoints:
# * 1. an endpoint to SHOW an Achievement (GET /v1/achievements/1)
# * 2. an endpoint to SHOW a User (GET /v1/users/1)
# * 3. an endpoint to GRANT an Achievement to a user (???)
# EXAMPLE GEMFILE THAT SHOULD WORK:
@mepatterson
mepatterson / gist:3176111
Created July 25, 2012 13:10
common refactorings
# NOTES
# - many of my style changes reflect the excellent Github Ruby Style Guide
# https://github.com/styleguide/ruby/
# - convention for naming Time-based db fields is xxxx_at, Date-based is xxxx_on
# - naming methods find_by_blah_blah_blah is old, Rails 1-ish. Newer convention is just simple names
# and scoping, so you can do things like: user.named('Bob').with_children(2)
# ( as opposed to: user.find_by_name_and_children('Bob', 2) )
@mepatterson
mepatterson / gist:2025104
Created March 12, 2012 22:28
beautiful logging for Rails 3
# create a file in initializers directory called "beautify_log.rb" (or whatever you want) and put in this code --
#
# ActiveSupport patches
#
module ActiveSupport
# Format the buffered logger with timestamp/severity info.
class BufferedLogger
@mepatterson
mepatterson / gist:2025099
Created March 12, 2012 22:28
quiet assets in Rails 3.1 log
# create a file called 'quiet_assets.rb' in the initializers directory, and put this code in--
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
@mepatterson
mepatterson / mepatterson.zsh-theme
Created February 3, 2012 20:54
'mepatterson' oh-my-zsh theme
PROMPT='%{$fg_bold[blue]%}%1~%{$reset_color%}%{$fg[red]%} %{$fg[green]%}ᐅ%{$reset_color%} '
RPROMPT='$(git_prompt_info) %{$reset_color%}%{$fg_bold[grey]%}$(~/.rvm/bin/rvm-prompt v g)%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$bg_bold[black]%}%{$fg[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%} ✓ %{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%} ⚡ %{$fg[yellow]%}"
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.load_once_paths += %W( #{Rails.root}/lib )
config = YAML.load(File.read(File.join(Rails.root, "config", "mongo.yml")))
MongoMapper.setup(config, Rails.env, { :logger => Rails.logger })
module IdentityMapAddition
def self.included(model)
model.plugin MongoMapper::Plugins::IdentityMap
end
end
MongoMapper::Document.append_inclusions(IdentityMapAddition)
config.cache_classes = true
config.whiny_nils = true
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_view.cache_template_loading = true
config.action_controller.allow_forgery_protection = false