Skip to content

Instantly share code, notes, and snippets.

View edoloughlin's full-sized avatar

Ed O'Loughlin edoloughlin

View GitHub Profile
@edoloughlin
edoloughlin / NPE_on_line_1.clj
Created January 23, 2011 21:11
This fails with NPE on line 1...
(ns myapp.domain.user
(:require clj-record.boot)
(:require
[myapp.util.date :as date-util]
[clj-time.core :as clj-time]
[clojure.contrib.sql :as sql]
[clj-record.validation.built-ins :as valid]
[clj-record.callbacks.built-ins :as cb]
[clj-time.core :as clj-time]
[myapp.config :as config]
@edoloughlin
edoloughlin / coffee-maps.coffee
Created January 16, 2011 16:21
How do I add a map to an array of maps?
mymap = []
# neither of these works:
mymap += { a: 1, b : 2 }
mymap = mymap + { a: 1, b : 2 }
user=> (def a 1)
#'user/a
user=> (def b 1)
#'user/b
user=> (defn f [x y z] [x y z])
#'user/f
user=> (f (inc a) (dec b) (+ a b))
[2 0 2]
user=>
@edoloughlin
edoloughlin / messy_syntax.coffee
Created January 13, 2011 20:50
Is there a neater way of writing this?
$('#main_menu li#setup_interview a').bind 'click',
{ callback: () => @interviewEditor.setup()
menuId: '#setup_interview' },
@menuClickCallback
@edoloughlin
edoloughlin / main_menu.coffee
Created January 13, 2011 17:12
Can't set a class method as a click handler
class MainMenu
interviewEditor = null
highlight: (menuId) ->
$('#main_menu li').removeClass('active_menu_item')
$("#main_menu li##{menuId}").addClass('active_menu_item')
clearContentArea: () ->
$('div#content').children().remove()
@edoloughlin
edoloughlin / if-let-confusion.clj
Created December 31, 2010 16:17
if-let treating nil as true?
; I've got
(if-let [session (last (find @*sessions* session-token))]
(something) (something-else))
; The (last (find @*sessions* session-token)) expression evaluates
; to nil but (something) is then evaluated when I would expect
; that (something-else) should be evaluated. What gives?
(ns my.util.sql
(:use clojure.contrib.condition)
(:require
[clojure.contrib.sql :as sql]
[clj-record.core :as rec]
[my.util.error :as err]))
(def *transaction-error* nil) ; While a transaction-wrapper is running, bound to the last error message set by rollback-with-raise
(defn rollback-with-raise
#####################################
#
# Register
beta_registration_complete_dialog = ->
div id:'registration-complete', ->
p class: 'msg-title', -> 'Your registration is complete'
div class: 'msg-body', ->
p 'Thank you!'
p 'You have successfully registered for our beta.'
@edoloughlin
edoloughlin / unclosed-indent.coffee
Created November 22, 2010 12:40
"unclosed INDENT" on second line
# Coffeescript gives an "unclosed INDENT" on the line 5
# API.login takes 4 args: two strings and two callback functions
finishRegistrationCb (userDetails) ->
API.login userDetails.email, passwordPlaintext
(userSession) ->
$.modal $.tempest('beta-registration-complete_dialog', { email, userDetails.email_addr }
$('#continue-button').bind 'click', (event) ->
window.location = '/'
(error) ->
class MyAPI
objectToXml: (obj) ->
'<?xml version="1.0"?>' + (new XMLSerializer()).serializeToString objectToDOM(obj)
login: (email, password, success_callback, error_callback) ->
console.log "API login. email: [#{email}], password: [#{password}]"
xmlData = objectToXml { login: { email: email, password: password }}
# do something with xmlData