This file contains 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
/** | |
* An example to illustrate the CyclicBarrier in java.util.concurrent package. | |
* Here we are creating a barrier to an entry for a coding session. | |
* A minimum of three programmers are necessary to start the coding session. | |
*/ | |
import java.util.concurrent.BrokenBarrierException; | |
import java.util.concurrent.CyclicBarrier; | |
public class CodingDojo { |
This file contains 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
#Put below line in an initializer script | |
Geokit::Geocoders::GOOGLE="<Your api key>" | |
Geokit::Geocoders::GoogleGeocoder3.reverse_geocode([12.9898001,77.7234591]) | |
This file contains 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
# MiniMagick::Image.format method by default converts only the first page. | |
# Carrierwave::MiniMagick.convert(:pdf) does not allow us to pass a second parameter page = nil. | |
# We need to paste in below code in the carrierwave initializer (or you may choose to extract it to lib folder) | |
# and use convert_all_pages_to_pdf in you uploader. | |
module CarrierWave | |
module MiniMagick | |
def convert_all_pages_to_pdf | |
manipulate! do |img| | |
img.format('pdf', nil) |
This file contains 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
//Kotlin Railway Oriented Programming | |
sealed class Result<T> | |
data class Success<T>(val message: T) : Result<T>() | |
data class Failure<T>(val errorMessage: String) : Result<T>() | |
infix fun <T, U> Result<T>.then(f: (T) -> Result<U>) = | |
when (this) { | |
is Success -> f(this.message) | |
is Failure -> Failure(this.errorMessage) |
This file contains 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 HttpRequest(private val url: String, private val method: HttpMethod, private val body: String) { | |
fun matches(anotherRequest: HttpRequest): Result { | |
if (this.url != anotherRequest.url) | |
return Failure("URL did not match. ${this.url} not equal to ${anotherRequest.url}") | |
if (this.method != anotherRequest.method) | |
return Failure("Method did not match. ${this.method} not equal to ${anotherRequest.method}") | |
if (this.body != anotherRequest.body) | |
return Failure("Body did not match. ${this.body} not equal to ${anotherRequest.body}") | |
return Success("everything matches") | |
} |
This file contains 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 HttpRequest(private val url: String, private val method: HttpMethod, private val body: String) { | |
fun matches(anotherRequest: HttpRequest): Result { | |
when (val result = matchUrl(anotherRequest)) { | |
is Failure -> return result | |
} | |
when (val result = matchMethod(anotherRequest)) { | |
is Failure -> return result | |
} | |
when (val result = matchBody(anotherRequest)) { | |
is Failure -> return result |
This file contains 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
sealed class Result<T> | |
data class Success<T>(val message: T): Result<T>() | |
data class Failure<T>(val errorMessage: String): Result<T>() | |
class HttpRequest(private val url: String, private val method: HttpMethod, private val body: String) { | |
fun matches(anotherRequest: HttpRequest): Result<HttpRequest> { | |
return when (val matchUrlResult = matchUrl(anotherRequest)) { | |
is Failure -> matchUrlResult | |
is Success -> { | |
when (val matchMethodResult = matchMethod(anotherRequest)) { |
This file contains 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 arrow.core.Either | |
import arrow.core.flatMap | |
sealed class Result<T> | |
data class Success<T>(val message: T) : Result<T>() | |
data class Failure<T>(val errorMessage: T) : Result<T>() | |
infix fun <F, S> Either<F, S>.then(f: (S) -> Either<F, S>) = | |
this.flatMap { f(it) } |