Skip to content

Instantly share code, notes, and snippets.

View mhshams's full-sized avatar

Mohammad Sarbandi mhshams

  • Berlin, Germany
View GitHub Profile
/**
* A Set is a data structure that contains multiple (zero or more) elements.
* - The elements in the Set are unique. (no duplication)
* - The elements in the Set are not kept in given order. (unordered)
*/
class MySet {
/**
* This property shows the number of elements that are currently available in the Set.
*/
var size: Int = 0
package io.dahgan
/**
* Queue is a data structure that stores some elements and these elements can be received in FIFO order.
* That means the first element that is inserted to queue would be the first one that can be removed.
*
* Our queue has a limited capacity and can NOT store element more than its capacity.
*
* Note to developer:
* - define an array of integers to keep the queue elements.
package io.dahgan
/**
* Stack is a data structure that stores some elements and these elements can be received in LIFO order.
* That means the last element that is pushed to stack would be the first one that can be poped.
*
* Our stack has a limited capacity and can not store element more than its capacity.
*
* Note to developer:
* - define an array of integers to keep the stack elements.
@mhshams
mhshams / Binary.kt
Last active January 22, 2016 09:45
/**
* A function that takes TWO arrays of Integer, compares them and then returns:
* - 1, if the first array is greater than second one
* - -1, if the second array is greater tan first one
* - 0, if both arrays are the same.
*
* How to Compare?
* Starting from index 0, compare the elements of both array in the same positions until you find one is bigger than the other.
*
* Examples:
/**
* ** Spec productions
*
* These are copied directly from the YAML specification, with some changes to adapt to Kotlin language syntax and
* also ease some of the decisions.
*
* See: http://www.yaml.org/spec/1.2/spec.html
*/
/**
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()}") }
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
@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")
}
@mhshams
mhshams / gist:6136923
Created August 2, 2013 01:45
final results
/opt/jdk1.8.0/bin/java -Didea.launcher.port=7533 -Didea.launcher.bin.path=/opt/idea-IU-129.161/bin -Dfile.encoding=UTF-8 -classpath /opt/jdk1.8.0/jre/lib/rt.jar:/opt/jdk1.8.0/jre/lib/javaws.jar:/opt/jdk1.8.0/jre/lib/charsets.jar:/opt/jdk1.8.0/jre/lib/jfr.jar:/opt/jdk1.8.0/jre/lib/jsse.jar:/opt/jdk1.8.0/jre/lib/jce.jar:/opt/jdk1.8.0/jre/lib/resources.jar:/opt/jdk1.8.0/jre/lib/management-agent.jar:/opt/jdk1.8.0/jre/lib/plugin.jar:/opt/jdk1.8.0/jre/lib/deploy.jar:/opt/jdk1.8.0/jre/lib/ext/sunec.jar:/opt/jdk1.8.0/jre/lib/ext/sunpkcs11.jar:/opt/jdk1.8.0/jre/lib/ext/dnsns.jar:/opt/jdk1.8.0/jre/lib/ext/cldrdata.jar:/opt/jdk1.8.0/jre/lib/ext/sunjce_provider.jar:/opt/jdk1.8.0/jre/lib/ext/zipfs.jar:/opt/jdk1.8.0/jre/lib/ext/localedata.jar:/home/me/code/string-intern/out/production/string-intern:/opt/idea-IU-129.161/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain StringKeyTest
With Warm up String: 82373148
With Warm up Object: 30957921
With Warm up Builder: 72123213
With Warm up String: 61386367
With W
@mhshams
mhshams / StringKeyTest.java
Created August 2, 2013 01:44
final version
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author me
*/