This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_within_board(location, direction): | |
"""Tests if the move stays within the boundaries of the board.""" | |
index = (0, 1) [direction in ['right', 'left']] | |
limit = (0, 4) [direction in ['right', 'down']] | |
return (location[index] < limit, location[index] > limit) [direction in ['left', 'up']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def "controller processes request"() { | |
given: | |
MockHttpServletRequest request = new MockHttpServletRequest() | |
Customer customer = Mock(Customer) | |
Order cart = Mock(Order) | |
BroadleafRequestContext context = new BroadleafRequestContext() | |
request.setAttribute(CustomerStateRequestProcessor.customerRequestAttributeName, customer) | |
request.setAttribute(CartStateRequestProcessor.cartRequestAttributeName, cart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ahalife.controller.system | |
import com.ahalife.service.WebClientService | |
import org.springframework.mock.web.MockHttpServletRequest | |
import org.springframework.mock.web.MockHttpServletResponse | |
import spock.lang.Specification | |
import spock.lang.Unroll | |
import javax.servlet.FilterChain | |
class CrawlFilterSpec extends Specification { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""I am the creator of this program. | |
This is a gambling game where one player is "Even" and the other player is "Odd." | |
Each player begins with some money, and each player chooses some money to bet. | |
If the sum is odd, the odd player wins. | |
If the sum is even, the even player wins. | |
Play ends when a player has less than twice the maximum bet. | |
Play also ends when the human player decides to quit by entering a bet of 0. | |
""" | |
import sys, random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = raw_input("even or odd? ") | |
while input.lower() not in ['even', 'odd']: | |
print "I said even or odd!" | |
input = raw_input("even or odd? ") | |
print "Good, you chose %s" % input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def returning_function(): | |
print "inside of returning function" | |
return "hello" | |
def void_function(): | |
print "inside of void function" | |
returning_function() | |
void_function() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (UPSShipmentStatusType.PICKUP.getType().equalsIgnoreCase(activityType.getStatus().getType()) | |
|| UPSShipmentStatusType.PICKUP_SCAN.getType().equalsIgnoreCase(activityType.getStatus().getCode()) | |
|| UPSShipmentStatusType.DESTINATION_SCAN.getType().equalsIgnoreCase(activityType.getStatus().getCode()) | |
|| UPSShipmentStatusType.DELIVERY_SCAN.getType().equalsIgnoreCase(activityType.getStatus().getCode()) | |
|| UPSShipmentStatusType.DELIVERED.getType().equalsIgnoreCase(activityType.getStatus().getType())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def powers(i): | |
numbers = (i, i * i, i * i * i,) | |
print "The number %s has square %s and cube %s" % numbers | |
return numbers | |
assert powers(2) == (2, 4, 8,) | |
assert powers(-2) == (-2, 4, -8,) | |
assert powers(3) == (3, 9, 27,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prompt = "Give me a number: " | |
i = input(prompt) | |
while i: | |
print "You entered %s whose square is %s" % (i, i * i) | |
i = input(prompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseUrlHandler implements Handler { | |
void handle(Context context) throws Exception { | |
context.with { | |
def headers = request.headers | |
def scheme = headers.contains('X-Forwarded-Proto') ? headers.get('X-Forwarded-Proto') : 'http' | |
def domain = headers.get('Host') ?: headers.get('host') | |
def baseUrl = "${scheme}://${domain}" as String |