This file contains hidden or 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
fun idSequence(seed:Int=0) : Sequence<Int>{ | |
return generateSequence(seed,{it + 1}) | |
} | |
class TreeNode<T>(val id: T){ | |
val childNodes = mutableListOf<TreeNode<T>>() | |
fun addChild(node: TreeNode<T>) = childNodes.add(node) | |
fun removeChild(node: TreeNode<T>) = childNodes.remove(node) | |
fun children() = childNodes.asIterable() |
This file contains hidden or 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 Queue<T> { | |
val elements: MutableList<T> = mutableListOf() | |
fun isEmpty() = elements.isEmpty() | |
fun count() = elements.size | |
fun enqueue(item: T) = elements.add(item) | |
fun dequeue() = if (!isEmpty()) elements.removeAt(0) else null | |
fun peek() = if (!isEmpty()) elements[0] else null | |
override fun toString(): String = elements.toString() | |
} |
This file contains hidden or 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 Stack<T>{ | |
val elements: MutableList<T> = mutableListOf() | |
fun isEmpty() = elements.isEmpty() | |
fun count() = elements.size | |
fun push(item: T) = elements.add(item) | |
fun pop() : T? { | |
val item = elements.lastOrNull() | |
if (!isEmpty()){ | |
elements.removeAt(elements.size -1) | |
} |
This file contains hidden or 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
import java.util.* | |
fun Pair<Int,Int>.isWall(offset: Int) = isWall(this.first, this.second, offset) | |
fun isWall(x: Int, y: Int, offset:Int) = Integer.bitCount(x*x + 2*x*y + y*y + 3*x + y + offset) % 2 == 1 | |
data class Move(val pos: Pair<Int,Int>, val visited: List<Pair<Int,Int>>, val depth: Int) | |
fun Move.adjacentCells(offset: Int): List<Pair<Int,Int>>{ | |
return listOf(Pair(pos.first-1, pos.second), |
This file contains hidden or 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
// Assumes 'java', 'groovy' or 'scala' plugins have been applied before | |
// Add integration test source sets | |
sourceSets { | |
integrationTest { sourceSet -> | |
["java", "groovy", "scala", "resources"].each { | |
if (!sourceSet.hasProperty(it)) return | |
sourceSet."$it".srcDir file("src/integration-test/${it}") | |
} | |
} |
This file contains hidden or 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 org.nhs.mesh.util.lzw; | |
import java.io.IOException; | |
import java.io.InputStream; | |
/** | |
* Wrapper around an Input Stream which allows the Code Points to be read sequentially from | |
* an LZW compressed file. | |
* | |
* @author Andy Bowes |
This file contains hidden or 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or 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 RomanNumeral { | |
def toRomanNumerals( number: Int) : String = { | |
toRomanNumerals( number, List( ("M", 1000),("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90), | |
("L", 50), ("XL",40), ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1) )) | |
} | |
private def toRomanNumerals( number: Int, digits: List[(String, Int)] ) : String = digits match { | |
case Nil => "" | |
case h :: t => h._1 * ( number / h._2 ) + toRomanNumerals( number % h._2, t ) | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:mongo="http://www.springframework.org/schema/data/mongo" | |
xsi:schemaLocation="http://www.springframework.org/schema/context | |
http://www.springframework.org/schema/context/spring-context-3.0.xsd | |
http://www.springframework.org/schema/data/mongo | |
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd | |
http://www.springframework.org/schema/beans |
This file contains hidden or 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
import org.bson.types.ObjectId; | |
import org.springframework.data.mongodb.repository.MongoRepository; | |
import org.springframework.data.repository.RepositoryDefinition; | |
import uk.co.jfactory.database.music.domain.Album; | |
import java.util.List; | |
@RepositoryDefinition( domainClass = Album.class, idClass = ObjectId.class ) | |
public interface AlbumRepository extends MongoRepository<Album, ObjectId> { |
NewerOlder