Skip to content

Instantly share code, notes, and snippets.

View mhshams's full-sized avatar

Mohammad Sarbandi mhshams

  • Berlin, Germany
View GitHub Profile
@mhshams
mhshams / Test.kt
Created March 24, 2014 22:21
unit tests.
test fun `testing a simple add operation`() {
assertEquals(4, 2 + 2, "2 + 2 = 4")
}
class MySpeck extends Specification {
def "check sum of two integer"() {
given: "we have two integers, 10 and 20"
def a = 10
def b = 20
when: "we add these two numbers"
def c = a + b
fun main(args: Array<String>) {
val vertx = Vertx.vertx()
vertx.createHttpServer().requestHandler { request ->
request.response().end("Hello World!")
}.listen(8080) { result ->
if (result.succeeded()) {
vertx.createHttpClient().getNow(8080, "localhost", "/") { response ->
response.bodyHandler { body -> println("Server Response: ${body.toString()}") }
@mhshams
mhshams / Address
Created December 12, 2011 09:24
Address (Groovy Bean)
class Address {
String number
String firstLine
String secondLine
String postCode
String City
String State
}
@mhshams
mhshams / Main
Created December 12, 2011 09:41
Client (second implementation)
println person.getAddressFirstLine()
println person.getAddressSecondLine()
@mhshams
mhshams / Person
Created December 12, 2011 09:24
Person (Groovy Bean)
class Person {
String firstName
String lastName
Address address
}
@mhshams
mhshams / Main
Created December 12, 2011 09:26
Only talk to your immediate friends.
println person.getAddress().getFirstLine()
println person.getAddress().getSecondLine()
@mhshams
mhshams / Person
Created December 12, 2011 09:40
Person (Second Implementation)
class Person {
String firstName
String lastName
private Address address
String getAddressFirstLine() {
address.firstLine
}
String getAddressSecondLine() {
@mhshams
mhshams / File
Created December 14, 2011 07:29
private static File generateFile(String prefix, String suffix, File dir)
throws IOException
{
long n = LazyInitialization.random.nextLong();
if (n == Long.MIN_VALUE) {
n = 0; // corner case
} else {
n = Math.abs(n);
}
return new File(dir, prefix + Long.toString(n) + suffix);
def mergeSort(list) {
def size = list.size()
if (size < 2) {
return list
} else {
def m = (int)(size / 2)
def left = list[0..<m]
def right = list[m..<size]