Skip to content

Instantly share code, notes, and snippets.

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']]
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)
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 {
"""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
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
@danhyun
danhyun / returns.py
Last active August 29, 2015 14:05
python function demo
def returning_function():
print "inside of returning function"
return "hello"
def void_function():
print "inside of void function"
returning_function()
void_function()
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()))
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,)
@danhyun
danhyun / number.py
Created August 27, 2014 21:12
keep printing numbers as long as it is not 0
prompt = "Give me a number: "
i = input(prompt)
while i:
print "You entered %s whose square is %s" % (i, i * i)
i = input(prompt)
@danhyun
danhyun / BaseUrlHandler.groovy
Created August 20, 2014 14:06
Setting base url
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