Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
tjmcewan / database.yml
Last active December 24, 2015 13:29
app-agnostic, feature branch supporting, drop-in database.yml(based on http://www.reinteractive.net/posts/22-branch-specific-database-yml)
<%
app_name = Dir.getwd.split('/')[-1]
branch = `git symbolic-ref --short HEAD 2>/dev/null`.chomp.gsub(/\W/, '_')
db_name = branch.match(/feature/) ? "#{app_name}_#{branch}" : "#{app_name}_master"
puts "DATABASE: #{db_name}"
%>
mysql2: &mysql2
adapter: mysql2
socket: /tmp/mysql.sock
@tjmcewan
tjmcewan / branch_handling.md
Last active October 31, 2017 19:15
some options & shortcuts to make git branch management simple and sane

Run these once to setup git options:

git config --global push.default current
git config --global merge.defaultToUpstream true
git config --global branch.autosetupmerge true
git config --global branch.autosetuprebase remote
git config --global alias.cb 'checkout -b'
git config --global alias.ps 'push -u'
git config --global alias.pl '!git fetch -p && git rebase'

Use them like this:

@tjmcewan
tjmcewan / git-rebase-todo
Last active December 19, 2015 06:59
multi-stage deploy using git rebase -i
# x (or exec) will run anything on the same line as a shell command.
# we need to checkout a temporary branch because git won't push detached HEADs.
# after deploy, the "checkout -" means checkout the previously checked out thing,
# which will go back to our detached head and we clean up the temporary branch so
# that we don't need to worry about merging.
# if your branch is already based on the same point as your rebase command, then
# the 'pick' stage is essentially the same as a fast-forward merge; no new commits
# are created.
@tjmcewan
tjmcewan / unsyncer.js
Last active December 15, 2015 02:29
Sync or Unsync all Box folders on the current page
$('#mod-item-list>li').each(function(index, el){
// defaults to unsync; to sync, set unsync to 0
var unsync = 1;
var folder_id = el.attributes['data-view_id'].textContent;
var data = ["q[items][0]=", folder_id, "&q[unsync]=", unsync, "&request_token=", request_token, "&realtime_subscriber_id=", realtime_subscriber_id].join('');
var url = ["https://", location.host, "/index.php?rm=box_sync_mark_item_sync"].join('');
$.post(url, data, function(x,status,z){ console.log(folder_id, ': ', status) });
});
@tjmcewan
tjmcewan / successful install.sh
Created February 17, 2013 23:43
The words "fatal error" and "1 error generated" should generally _not_ be followed by "Successfully installed..."
$ pip install pyyaml
Downloading/unpacking pyyaml
Downloading PyYAML-3.10.tar.gz (241kB): 241kB downloaded
Running setup.py egg_info for package pyyaml
Installing collected packages: pyyaml
Running setup.py install for pyyaml
checking if libyaml is compilable
cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c build/temp.macosx-10.8-x86_64-2.7/check_libyaml.c -o build/temp.macosx-10.8-x86_64-2.7/check_libyaml.o
build/temp.macosx-10.8-x86_64-2.7/check_libyaml.c:2:10: fatal error: 'yaml.h' file not found
@tjmcewan
tjmcewan / backtrace.txt
Created January 7, 2013 05:49
jasminerice-runner error backtrace
Running jasmine specsrake aborted!
Modal dialog present
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/command_processor.js:10287:in `nsCommandProcessor.execute'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/driver_component.js:7328:in `Dispatcher.executeAs/<'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/driver_component.js:7488:in `Resource.handle'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/driver_component.js:7435:in `Dispatcher.dispatch'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@g
Loaded Taps v0.3.23
Receiving schema
Schema: 0% | | ETA: --:--:--
Schema: 6% |== | ETA: 00:00:48
Schema: 13% |===== | ETA: 00:00:46
Schema: 20% |======== | ETA: 00:00:41
Schema: 26% |========== | ETA: 00:00:38
Schema: 33% |============= | ETA: 00:00:34
Schema: 40% |================ | ETA: 00:00:30
Schema: 46% |=================== | ETA: 00:00:27
@tjmcewan
tjmcewan / mass_assignment_exception.rb
Created July 13, 2011 14:29
raise exception on attempted mass assignment of a protected attribute
# monkey-patch to raise an exception when attempting to mass-assign a protected attr
# more info: http://is.gd/MiA1mn
module ActiveModel
module MassAssignmentSecurity
module Sanitizer
protected
def warn!(attrs)
self.logger.debug "WARNING: Can't mass-assign protected attributes: #{attrs.join(', ')}" if self.logger
raise RuntimeError, "these attributes are protected from mass assignment, use `attr_accessible :#{attrs.join(', :')}`"
end
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::RecordNotUnique:
Mysql2::Error: Duplicate entry '1' for key 'PRIMARY': INSERT INTO `nodes` (`type`, `ancestry`, `parent_id`, `name`, `ancestry_depth`, `created_at`, `updated_at`, `active`, `id`) VALUES ('Team', NULL, 2, 'Team 1', 0, '2011-06-26 10:19:42', '2011-06-26 10:19:42', 1, 1)
# ./spec/support/custom.rb:18:in `setup_league_structure'
# ./spec/support/controller_macros.rb:5:in `block in login_user'