Skip to content

Instantly share code, notes, and snippets.

View nhajratw's full-sized avatar

Nayan Hajratwala nhajratw

View GitHub Profile
SICP 1.2
Fork me. Solve me.
====
-71/300 <=
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 1 5)))))
(* 3 (- 6 2) (- 2 7)))
Please excuse my embarrassing Groovy code. This is a simplified cuke4duke Step definition.
GroceryService is a java class that makes a call to repository.findByNamedQueryAndNamedParam("Store.by_zip_code_with_active_promotions", "zip", "48176")
The error i'm getting is:
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.mock.interceptor.MockFor.findByNamedQueryAndNamedParam() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [Store.by_zip_code_with_active_promotions, zip, 48176] (NativeException)
When(~"the service is invoked") {
store = new Store()
package com.chikli.st
import org.junit.runner.RunWith
import org.scalatest.{FeatureSpec, GivenWhenThen}
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class GolSpec extends FeatureSpec with GivenWhenThen {
feature("a cell with zero neighbors dies in the next generation") {
@nhajratw
nhajratw / gist:1468043
Created December 12, 2011 16:10
Trying to iterate through a Backbone.Collection
I have a model:
class Offer extends Backbone.Model
And a Collection:
class Offers extends Backbone.Collection
model: Offer
initialize: ->
@nhajratw
nhajratw / gist:1468963
Created December 12, 2011 20:33
Trying to get basic CoffeeScript/Backbone working
There are 2 main problems with the code below:
1) It appears that fetch is getting called twice somehow
2) The fetched JSON is not parsing into the OfferClass objects.
I have a server that returns the following JSON at /offerClasses
[ {"id":1,"name":"Introductory"}, {"id":2,"name":"Loyalty"} ]
Coffee file
@nhajratw
nhajratw / gist:1667727
Created January 24, 2012 04:04
Getting Backbone to communicate with XML services using CoffeeScript
# Keep track of the original sync method so we can
# delegate to it at the end of our new sync.
originalSync = Backbone.sync
# Our new overriding sync with dataType and ContentType
# that override the default JSON configurations.
Backbone.sync = (method, model, options) ->
options = _.extend(options,
dataType: 'xml'
@nhajratw
nhajratw / gist:1670278
Created January 24, 2012 13:56
Example of converting XML to JSON in a Backbone/CoffeeScript using JATH
class OE.Offer extends Backbone.Model
class OE.Offers extends Backbone.Collection
model: OE.Offer
url: 'http://localhost:7000/offer/opportunities/merchant/123'
parse: (response) ->
template = ["//offer", {
id: 'id',
name: 'name',
@nhajratw
nhajratw / gist:1754368
Created February 6, 2012 19:48
Example of using page objects with radio buttons + wait
class TypeTab
include PageObject
radio_button(:premium_offer_yes, {:name => 'premium-offer', :value => 'true'})
radio_button(:premium_offer_no, {:name => 'premium-offer', :value => 'false'})
# doesn't seem to work in a block
def non_working_select_data
premium_offer_yes_element.when_visible do
<root>
<a>
<b>123</b>
<b>456</b>
<b>789</b>
</a>
<a>
<b>foo</b>
</b>bar</b>
</a>
@nhajratw
nhajratw / gist:2227011
Created March 28, 2012 15:10
trying to get the element() accessor of page_object to work.
The reason we're using "element" is because the html contains a "dl" element.
---------------
class HeaderInfo
include PageObject
element(:merchant, :id => 'merchant-name')