Skip to content

Instantly share code, notes, and snippets.

View nhajratw's full-sized avatar

Nayan Hajratwala nhajratw

View GitHub Profile
@nhajratw
nhajratw / gist:3737704
Created September 17, 2012 14:30
empty loop? mmmmkay.....
for (int i = 0; i < GEN_OFFSET_FILE_SKIPLINE_VERSION2 && br.readLine() != null; i++) {
// empty block
}
@nhajratw
nhajratw / gist:3527731
Created August 30, 2012 12:42
Do not write code like this
if (!(this == null && rhs == null || code == null && rhs.code == null) &&
(this == null && rhs != null ||
this != null && rhs == null ||
code != null && rhs.code == null ||
code == null && rhs.code != null ||
!code.equals(rhs.code))) {
return false;
}
@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')
<root>
<a>
<b>123</b>
<b>456</b>
<b>789</b>
</a>
<a>
<b>foo</b>
</b>bar</b>
</a>
@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
@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: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: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: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: ->
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") {