Skip to content

Instantly share code, notes, and snippets.

View halfbaked's full-sized avatar

Eamonn O'Connell halfbaked

View GitHub Profile
@halfbaked
halfbaked / fakeSinonServer.js
Created May 12, 2011 12:38
using sinon.js to fake json response from server
server = sinon.fakeServer.create()
server.autoRespond=true
server.respondWith("GET", /\/customer\/(\d+)/, (xhr, id) ->
xhr.respond( 200, { "Content-Type": "application/json" }, JSON.stringify(window.sampleCustomerJson ))
)
@halfbaked
halfbaked / dogCollection.coffee
Created April 28, 2012 05:43
Auto-update collection changes in backbone
class sp.collections.DogCollection extends Backbone.Collection
initialize: ->
@fetch()
setInterval(@fetchChanges, 15*1000)
model: sp.models.DogModel
url: '/dogs'
@halfbaked
halfbaked / http-loading-interceptor
Created December 11, 2012 14:18
http loading interceptor in AngularJs
# Define new module
angular.module('http-loading-interceptor')
# Add filter at request send time
.config(['$httpProvider', ($httpProvider) ->
interceptor = (data, headersGetter) ->
alert("loading...")
data
$httpProvider.defaults.transformRequest.push(interceptor)
])
@halfbaked
halfbaked / spinner_provider
Created December 11, 2012 14:22
AngularJs SpinJs Provider
angular.module('spinner', [])
.provider('spinner', () ->
@$get = () -> return null
@startSpinner = () ->
spinnerEl = $('<p id="spinner"></p>')
data = spinnerEl.data()
if (data.spinner)
data.spinner.stop()
@halfbaked
halfbaked / http-loading-interceptor-with-spinner-provider.coffee
Created December 11, 2012 14:29
http loading interceptor with spinner provider injected in AngularJs
angular.module('http-loading-interceptor', ['spinner'])
.config(['$httpProvider', 'spinnerProvider', ($httpProvider, spinnerProvider) ->
interceptor = (data, headersGetter) ->
spinnerProvider.startSpinner()
data
$httpProvider.defaults.transformRequest.push(interceptor)
])
.config(['$httpProvider', 'spinnerProvider', ($httpProvider, spinnerProvider) ->
@halfbaked
halfbaked / Config.groovy
Created December 11, 2012 20:48
Grails Config to include external Config file
grails.config.locations = [ ]
grails.config.locations << "file:$userHome/.grails/app-prod.groovy"
@halfbaked
halfbaked / Config.groovy
Created December 11, 2012 21:01
How to include Config Partials placed in src/java (Grails)
grails.config.locations = [ "classpath:Config-core-main.groovy",
"classpath:Config-core-logging.groovy",
"classpath:Config-core-sec.groovy" ]
@halfbaked
halfbaked / MultiPaginateTagLib.groovy
Created December 13, 2012 15:25
Rough description of how one might do multiPageTagLib
Closure paginate = { attrs ->
// define new prefix aware keys
def _sort = attrs.prefix? attrs.prefix +"_sort" : 'sort'
def _offset = attrs.prefix? attrs.prefix + "_offset" : "offset"
def _total = attrs.prefix? attrs.prefix + "_total" : "total"
def writer = out
if (attrs.total == null) {
@halfbaked
halfbaked / CoreGrailsPlugin.groovy
Last active December 10, 2015 00:48
setting the location of database migration changelogs to be in a Grails plugin
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
...
def doWithConfig = { config ->
// Here we need to tell the database migrations plugin the change log is in the s5-core plugin
try {
def pluginManager = PluginManagerHolder.pluginManager
def plugin = pluginManager.getGrailsPlugin('s5-core')
def pluginDir = org.codehaus.groovy.grails.plugins.GrailsPluginUtils.getPluginDirForName('s5-core')?.path
@halfbaked
halfbaked / uaa_config_example
Last active December 16, 2015 09:38
example config for Cloud foundry UAA
oauth:
client:
override: true
autoapprove:
- cf
clients:
cf:
override: true
authorized-grant-types: password,implicit
authorities: uaa.none