Skip to content

Instantly share code, notes, and snippets.

@adamphillips
adamphillips / Javascript dateDiff function to calculate difference in terms of days, months and years
Created October 6, 2010 00:17
A quick javascript dateDiff function that returns results in terms of days, months and years taking into account variable month lengths and leap years
/*
* Function to calculate the absolute difference in days, months and years between 2 days taking into account variable month lengths and leap years
* It ignores any time component (ie hours, minutes and seconds)
*
*/
function dateDiff(dt1, dt2)
{
/*
* setup 'empty' return object
*/
@adamphillips
adamphillips / deploy.rb
Created March 30, 2012 18:52 — forked from netzpirat/deploy.rb
Capistrano recipe to sync rails database and files within a multi stage environment
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3
@adamphillips
adamphillips / gist:3608009
Created September 3, 2012 09:03
Sublime text 2 shortcuts

Sublime Text 2 Keyboard Shortcuts (OSX)

Bookmarks

Cmd + F2 : Toggle bookmark

F2 : Jump to next bookmark

Shift + F2 : Jump to prev bookmark

From bd8aa4106da1aa9f92aafceeac0701b7cf7962bd Mon Sep 17 00:00:00 2001
From: Adam Phillips <[email protected]>
Date: Mon, 4 Mar 2013 09:46:49 +0000
Subject: [PATCH 1/2] Modified as shared helper to reduce typing
Now that the as helper has had more use, it's become apparent that most
cases benefit from using the display_name parameter to describe the kind
of user being tested. Therefore, in order to reduce typing, the helper
has been changed so that if the second parameter passed is a string, it
is taken to be the display name.
From 713527f239f58ab21a40226e2816176c93152d50 Mon Sep 17 00:00:00 2001
From: Adam Phillips <[email protected]>
Date: Mon, 11 Mar 2013 09:56:50 +0000
Subject: [PATCH 1/2] Rejigged existing CSE search controller tests
Rejigged the existing tests into the new format before updating them to
remove bookfairs and writers.
---
.../test/functional/cse_search_controller_test.rb | 119 ++++++++++++---------
1 file changed, 68 insertions(+), 51 deletions(-)
From 363260815f1a5812d659c6d865ab884b20d46167 Mon Sep 17 00:00:00 2001
From: Adam Phillips <[email protected]>
Date: Thu, 6 Jun 2013 14:15:31 +0100
Subject: [PATCH] Bug 3011: Tell a friend failing to hide the spam trap
There are two parts to this - the spam trap was not being hidden due to missing
CSS and then was erroring on submit as it was missing some code to check how
much time had passed between the initial get request and the post request.
For the first part, the CSS was removed accidentally in commit 62727113a63e0
@adamphillips
adamphillips / benchmark_url
Last active May 29, 2019 10:48
A quick and dirty url benchmarking script. Needs a chmod +x. Alternatively just run it with ruby
#!/usr/bin/env ruby
# Used to perform multiple requests of urls for benchmarking
#
# @example
# # Requests the url 3 times outputting times for each
# ./benchmark_url 3 http://my.url.com
# ruby benchmark_url 3 http://my.url.com
#
# # Requests each url 5 times outputting times for each
From 2441910d94cad6e15b8f859369b8242022d7ca4e Mon Sep 17 00:00:00 2001
From: Adam Phillips <[email protected]>
Date: Wed, 5 Mar 2014 23:10:33 +0000
Subject: [PATCH] Change Rails dependency to 3.1
---
activeadmin-cms.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activeadmin-cms.gemspec b/activeadmin-cms.gemspec
@adamphillips
adamphillips / gist:33c83c56a2e06c25eed1
Created May 21, 2014 22:41
PS3 controller Gosu button constants
# After pairing a PS3 Controller on OSX to use with Gosu, this is how Gosu
# recognises the different controller actions
# Left Stick
GpUp, GpDown, GpLeft, GpRight
# Right Stick (doesn't recognise up and down)
GpLeft, GpRight
GpButton1 # Left Stick press
class FairSummaryJson
def initialize(fair, options={})
@cash_report_url = options.fetch(:cash_report_url) { '' }
end
def to_hash
{
id: fair.id,
school: SchoolSummaryJson.new(fair.school).to_hash
cash_report_url: cash_report_url