Skip to content

Instantly share code, notes, and snippets.

@danhyun
danhyun / api in 19 lines.groovy
Last active August 29, 2015 13:57
fast and easy restclient
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
def apiUrl = 'http://localhost:8888'
def api = new RESTClient(apiUrl, ContentType.JSON)
api.headers = ['auth-key': '11', 'Accept': 'application/json; q=0.9,*/*; q=0.8']
def id = 20784
@danhyun
danhyun / html_fragment_validator.groovy
Last active August 29, 2015 14:03
A groovy service that validates HTML fragments
// For use with your own local copy of nu validator @ http://about.validator.nu/#src
@GrabConfig(systemClassLoader=true)
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
import groovyx.net.http.HTTPBuilder
def client = new HTTPBuilder('http://localhost:8888')
def boundary = '----hyunlabs_boundary'
@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
@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)
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,)
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()))
@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()
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
"""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
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 {