Skip to content

Instantly share code, notes, and snippets.

View eliotsykes's full-sized avatar

Eliot Sykes eliotsykes

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / gmaps4rails_example_1.html.erb
Last active December 19, 2015 12:38
Getting started with gmaps4rails - a simple map with a single point centred on London, UK
<%# Shows a map centred on London, using the default marker/pin image. %>
<%= gmaps4rails([{:lat => 51.51, :lng => -0.12}].to_json) %>
<%= yield :scripts %><%# Usually yield :scripts goes just before the closing body tag %>
@eliotsykes
eliotsykes / asset_server_middleware.rb
Last active December 20, 2015 01:29
***** Checkout the rack-zippy gem, I recommend it over this gist, find it at https://github.com/eliotsykes/rack-zippy ***** An asset server for Rails 3.2.x that serves asset pipeline precompiled assets to clients, including those elusive gzipped (.gz) assets. Sadly Rails' own ActionDispatch::Static middleware does not take care of serving gzippe…
# 1. Add rack-rewrite to your Gemfile and run 'bundle install':
# gem 'rack-rewrite'
#
# 2. Create a file with the contents below in config/initializers/asset_server_middleware.rb
#
# 3. Rename 'YourApp' below
#
# 4. In config/environments/production.rb and config/environments/test.rb, set:
# config.serve_static_assets = true
# config.assets.compile = false
@eliotsykes
eliotsykes / windows_cheatsheet.md
Last active August 29, 2015 14:06
Where to run what on Windows?

Git Bash

Use Git Bash in Windows for:

  • subl commands (e.g. subl ., subl myfile.rb) to open files with Sublime Text
  • git commands (e.g. git add ., git commit -m "message" README.md, git push heroku master)
  • vagrant commands (cd ~/dev-rails-box first)
  • open commands

Vagrant VM

@eliotsykes
eliotsykes / Gemfile
Last active August 28, 2019 02:56
JavaScript testing in Rails 4.x with RSpec, Capybara, PhantomJS, Poltergeist
# Add poltergeist gem to Gemfile, in :test group,
# then run `bundle` to install
group :test do
...
gem 'poltergeist'
...
end