Skip to content

Instantly share code, notes, and snippets.

View jdickey's full-sized avatar
💭
Open to possibilities. Enquire within.

Jeff Dickey jdickey

💭
Open to possibilities. Enquire within.
View GitHub Profile
@jdickey
jdickey / users_controller.rb
Created June 10, 2013 03:48
Rails controller derived from `InheritedResources::Base` (see https://github.com/josevalim/inherited_resources) that plays nice with Devise (see http://devise.plataformatec.com.br/) when updating a user record that has no changes to password. Discussed on my blog at http://archlever.blogspot.com/2013/06/tools-save-you-time-except-when-they.html
# Actions for Users. Not necessarily a finer distinction one way or another yet.
class UsersController < InheritedResources::Base
# FIXME respond_to :json # should spec JSON actions, too
respond_to :html
load_and_authorize_resource
def update
# Devise has the convention that, for updates where the password is NOT to
# be modified, the password and password-confirmation fields MUST NOT be

See this StackOverflow question to understand what all this is for.

Thanks for any help.

Attached are:

  • 01_config_routes.rb -- showing how the :comments resource is nested within :articles
  • 02_app_models_article.rb -- showing the (containing) Article model
  • 03_app_models_comment.rb -- showing the (contained) Comment model
  • 04_app_models_ability.rb -- "main" CanCan Ability class; uses three modules (05-07) to manage the specifics of the three different roles (guest, logged-in user and admin);
@jdickey
jdickey / Benchmarking Bundler.sh
Created August 31, 2013 16:31
Benchmarking script building my current project using the new `-j` feature in Bundler 1.4.0pre2 per http://robots.thoughtbot.com/post/59584648154/parallel-gem-installing-using-bundler
#!/bin/bash
for BIJOBS in 1 2 4
do
export T1=`date`
rm -rf Gemfile.lock vendor/cache/* vendor/ruby/*
bundle install --jobs $BIJOBS --path vendor
bundle package --all
bundle install --binstubs
echo Reporting start and end times for BIJOBS=$BIJOBS
echo $T1
@jdickey
jdickey / 00-Sinon Reefer Madness.md
Last active December 23, 2015 22:19
Misadventures while seeking Enlightenment as to "how come my jQuery Ajax call doesn't work, Bunky?"

The Background

Rails app uses Devise authentication, and (inter alia) supports a REST API so that front-end CoffeeScript/JavaScript code can access authentication-protected resources. Front end Script code makes heavy use of LucidJS as a lightweight pub/sub message queue for decoupling. ( That part works like a champ, by the way.)

The Problem

We've also been using Sinon.js and its FakeXMLHttpRequest so that we could test Ajax calls without actually hitting the server. Up until this one episode, that had been beautiful. However...

A seemingly simple, straightforward method was giving "syntax error" failures coming back from jQuery.post using Sinon. The original exploratory code looked like file 01-original-gruam.js.coffee below, with the relevant spec as [02-original-gruam_spec.js.coffee](http

@jdickey
jdickey / 0_reuse_code.js
Created September 25, 2013 17:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jdickey
jdickey / HAML error that's driving me nuts.md
Last active January 26, 2016 13:57
index.html.haml that's giving an odd error. Why?

Introduction

The index.html.haml file that follows is from a very basic Rails app meant to demonstrate the convergence of

  • some bespoke Script code (not relevant here; we're not getting that far)
  • Twitter Bootstrap (currently using 3.03; any 3.0+ should be fine with the CSS styles here)
  • posabsolute's jQuery Validation Engine, (hereinafter "jQVE")

This is meant to be used by a Rails (3.2.16) app with Gems haml-rails 0.4 and haml 4.0.4, along with jqVE 2.6.2. The server is Thin 1.6.1.

Errors In My Errors?

@jdickey
jdickey / 00-solving-a-third-party-Gem-dependency-description.md
Last active October 2, 2022 21:39
Solving a third-party Gem dependency when building a Gem

So I built a dummy Rails-plugin gem...

rails plugin new foo --skip-bundle -O --full

and filled in my .gemspec as below, including the line

s.add_dependency "rails-assets-sugar"

and added

@jdickey
jdickey / removing all files and subdirectories in a deep thick tree
Last active August 29, 2015 13:56
Removing all files in a deep, thick tree of files and directories
$ find . | cpio -pmdu /tmp/foo
1738239 blocks
$ cd /tmp/foo
$ du -hsc .
916M .
916M total
$ find .[a-z]* * | wc -l
27791
$ time find .[a-z]* * -delete
@jdickey
jdickey / 00-Four Generations of spec_helper.rb.md
Last active August 29, 2015 13:57
Four generations of an RSpec `spec/spec_helper.rb` file.
@jdickey
jdickey / RuboCop- and coverage-aware teaspoon_env.rb
Created March 30, 2014 18:57
Teaspoon `spec/teaspoon_env.rb` file with added code-coverage settings and RuboCop warnings disabled.
# encoding: utf-8
# This file allows you to override various Teaspoon configuration directives
# when running from the command line. It is not required from within the Rails
# environment, so overriding directives that have been defined within the
# initializer is not possible.
#
# Set RAILS_ROOT and load the environment.
ENV['RAILS_ROOT'] = File.expand_path('../../', __FILE__)
require File.expand_path('../../config/environment', __FILE__)