Skip to content

Instantly share code, notes, and snippets.

View eliotsykes's full-sized avatar

Eliot Sykes eliotsykes

View GitHub Profile
@eliotsykes
eliotsykes / ngFocusAndBlur.js
Created April 16, 2013 09:27
AngularJS ngFocus and ngBlur directives - one way to get them before they get released. Before using, consider re-naming ngFocus and ngBlur to something that doesn't invade the ng namespace, e.g. replace all 'ngFocus' and 'ngBlur' strings with 'ngcFocus' and 'ngcBlur' (where c = cats/custom).
app.directive('ngFocus', ['$parse', function($parse) {
return function(scope, element, attr) {
var fn = $parse(attr['ngFocus']);
element.bind('focus', function(event) {
scope.$apply(function() {
fn(scope, {$event:event});
});
});
}
}]);
@eliotsykes
eliotsykes / actions.js
Created July 13, 2012 16:24
selenium selenese helper functions
// Perform HTTP POST to the given URL using selenium. Put this in actions.js.
// Works with selenese: | post | http://url-to-http-post-to.com/ |
Selenium.prototype.doPost = function(url) {
var form = this.getCurrentWindow().document.createElement('form');
form.id = 'formAddedBySeleniumDoPost';
form.method = 'POST';
form.action = url;
var body = this.browserbot.findElement("css=body");
if (typeof body == "undefined") {
throw new SeleniumError("No body element to append form element to for performing POST to url '" + url + "'");
@eliotsykes
eliotsykes / HOMEDIR-.ssh-config
Created June 27, 2012 15:26
SSH connection sharing in multiple terminals
# Put this in your local ~/.ssh/config to be prompted for password only once for multiple terminals
ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r
@eliotsykes
eliotsykes / thinRestart.sh
Created June 17, 2012 11:00
Robust Thin restart|start|stop script for HTTP and SSL in development
#! /bin/bash
# restart will start thin without error even when it is not already running.
echo "Usage: ./script/thin start|stop|restart"
# Log and pid file names will include port number before the .log/.pid extension.
bundle exec thin --pid tmp/pids/thin.pid --servers 1 --daemonize --log log/thin.log --port 3000 $1
bundle exec thin --pid tmp/pids/thin.pid --servers 1 --daemonize --log log/thin.log --port 3001 --ssl $1
@eliotsykes
eliotsykes / DebugFilters.groovy
Created May 16, 2012 15:20
Grails Debug Filter - log requests
// Put me in grails-app/conf/DebugFilters.groovy
class DebugFilters {
def filters = {
all(controller:'*', action:'*') {
before = {
log.error "${request.method}: $request.forwardURI $request.params"
}
after = { Map model ->
@eliotsykes
eliotsykes / DataNukerService.groovy
Created May 10, 2012 08:01
Grails GORM Truncate Tables in H2
package com.jetbootlabs.services
/*
* Truncates H2 tables mapped by the domainClasses variable. Useful for cleaning up test data.
*
* Temporarily disables referential integrity to avoid constraint violation errors when
* deleting records.
*
* Inspired by Luke Daley's blog post on how to do this in MySQL:
* http://ldaley.com/post/398082618/brute-force-fixture-cleanup-in-grails