Skip to content

Instantly share code, notes, and snippets.

@dcvezzani
dcvezzani / gist:4e210993c2a0b620cdec
Created April 16, 2015 22:41
move files to a new location; leave redirect behind
base_dst_path="/Volumes/Extra/dave/downloads"
for file in \
BW-1161.exe milkallergy-companion-and-cookbook.pdf iPhoneConfigUtility.dmg Screenhero.zip iPhotoLibraryUpgrader.dmg join.me.zip
do
#mv $file $base_dst_path
ln -s $base_dst_path/$file
#echo -e "# file was moved on "$(date +"%Y-%m-%d %H:%M:%S")"\nopen \"$base_dst_path/$file\"" > $file.txt
done
@dcvezzani
dcvezzani / OS-Mac-git-pre-commit-hook
Created September 24, 2012 18:07
pre-commit hook for Git on a system running OSX (Mac)
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# put the first changeset hash value in your project here (I think)
against=facf87a3fa1c853a7dd8dde8cba32e1fc8fde3ea
fi
for FILE in `git diff-index --name-status $against -- | cut -c3-` ; do
@dcvezzani
dcvezzani / multi_io.rb
Created October 27, 2015 20:39
Writes to both STDOUT and the specified file; can include as many IO streams as you want
# Usage example:
#
# log_filename = File.join(log_path, "#{Sinatra::Base.environment.to_s}.log")
# $log_file = File.open(log_filename, 'a+')
#
# STDOUT.sync = true if 'yes' == ENV['API_DEBUG']
# $log_file.sync = true if 'yes' == ENV['API_DEBUG']
#
# require 'logger'
# $logger = Logger.new MultiIO.new(STDOUT, $log_file)
@dcvezzani
dcvezzani / including-lib-bcms-my401k-in-config-routes.rb
Last active December 15, 2015 18:19
For some reason, the routes for the BcmsMy401k::Engine are being applied twice. Obviously, the cause should be chased down, but since this only takes place when the application is loaded, it shouldn't be too big a deal in the short run to check and see if the routes were already drawn before drawing them again. The config/routes.rb depends on th…
# config/routes.rb
BrowsercmsDemo::Application.routes.draw do
...
mount_bcms_my401k
mount_browsercms
end
...
BcmsMy401k::Engine.routes.draw do
@dcvezzani
dcvezzani / features-support-env.rb
Created April 3, 2013 22:27
The features/support/env.rb file provides configurations for running cucumber tests. Spork is used here to speed up the tests (or specifically, loading the environment for the tests). Spork and Cucumber both have blocks that may be used to judiciously load information or reset the database. 'Before' and 'After' blocks are run for each cucumber s…
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
...
require File.expand_path("./config/environment.rb")
...
@dcvezzani
dcvezzani / db-my401k.seeds.rb
Created April 3, 2013 22:34
Instead of using fixtures, we actually modify the database, seeding it one time per cucumber run.
# db/my401k.seeds.rb
require 'cms/data_loader'
extend Cms::DataLoader
if(Cms::Category.count == 0)
my401k_product_type = create_category_type(:guest, :name => 'My401k Product')
create_category(:about_plan, :name => 'About Plan', :category_type => my401k_product_type)
create_category(:manage_account, :name => 'Manage Account', :category_type => my401k_product_type)
create_category(:helpful_resources, :name => 'Helpful Resources', :category_type => my401k_product_type)
@dcvezzani
dcvezzani / correct-user-login-features-pages.feature
Created April 4, 2013 18:48
With the correct user login, I am not getting the authorization errors I was getting previously.
Feature: Content Pages
Editors should be able to manage their own pages
Background:
# make sure user is logged out
Given I am a guest
When I visit "/my401k/plan_sponsor/create_new_content"
And login as a plan sponsor
...
@dcvezzani
dcvezzani / incorrect-user-login-features-pages.feature
Created April 4, 2013 18:44
Cucumber feature using incorrect user login.
Feature: Content Pages
Editors should be able to manage their own pages
Background:
Given I am a guest
...
@javascript
Scenario: An editor saves the selected category and navigates next to select the desired lay
When a registered user visits "/my401k/plan_sponsor/create_new_content"
@dcvezzani
dcvezzani / before-filters-for-cucumber-each-scenario-features-support-env.rb
Created April 4, 2013 18:53
I know this won't work for *all* tests, but for now, this works. There must be a very good reason for default truncation for all @javascript. I keep having to add exceptions to the list (the next one would have been the users table), I we'll see how far this goes.
Before('@no-txn,@selenium,@culerity,@celerity') do
# I added this block and changed to transaction because @javascript was truncating most of my tables
#DatabaseCleaner.strategy = :truncation, {:except => %w[groups]}
DatabaseCleaner.strategy = :truncation
end
Before('@javascript') do
#DatabaseCleaner.strategy = :truncation, {:except => %w[groups categories category_types content_types content_type_groups bcms_my401k_layouts]}
DatabaseCleaner.strategy = :transaction
end
@dcvezzani
dcvezzani / app-assets-javascripts-my401k-plan-sponsor-create-new-content-wizard.js
Last active December 15, 2015 20:40
Manage CKEditor instances with persisting data and successfully loading editors on an html page through an Ajax call.
/*
updates form controls with the content of the editors
typically called just before persisting to the database
*/
function CKupdate(){
if(typeof(CKEDITOR) != "undefined"){
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
}
}