Skip to content

Instantly share code, notes, and snippets.

@boysbee
boysbee / DiagonalDifference.ws.kt
Created February 20, 2023 10:46
DiagonalDifference
// https://www.hackerrank.com/challenges/diagonal-difference/problem?isFullScreen=true
import java.math.BigDecimal
import kotlin.math.abs
import kotlin.math.absoluteValue
val arr = arrayOf(
arrayOf(1, 2, 3),
arrayOf(4, 5, 6),
arrayOf(9, 8, 9),
@boysbee
boysbee / CountAndFindRankInWording.kts
Created February 20, 2023 03:08
Count Word and Find Rank
fun Map<Int, List<Char>>.findRank(rank: Int): List<Char> {
val e = this.entries.filterIndexed { index, entry ->
index + 1 == rank
}
return e.map { it.value }.flatten()
}
fun countWord(input: String): Map<Int, List<Char>> {
return input.groupBy { it }
.mapValues { (_, values) -> values.size }
@boysbee
boysbee / simple.comand.line.sh
Last active March 4, 2022 10:09
Playwright Simple command line
# Run all the tests
npm playwright test
# Run a single test file
npm playwright test tests/todo-page.spec.ts
# Run a set of test files
npm playwright test tests/todo-page/ tests/landing-page/
# Run files that have my-spec or my-spec-2 in the file name
@boysbee
boysbee / either_applicative_error_runtime.kt
Created June 13, 2019 16:44
runtime error when use either.handleErrorWith from applicativeError
// found runtime error, java.lang.NoSuchMethodError: arrow.core.EitherKt.handleErrorWith(Larrow/Kind;Lkotlin/jvm/functions/Function1;)Larrow/core/Either;
// will back to find more information to fix this issue agian.
// describe("Either.handleErrorWith") {
// it("""should be return Either.Right when Either.Left<E>.handleErrorWith to recover error case""") {
//
// val result:Either<Throwable, String> = Either.Left(BadRequestException()).handleErrorWith { Either.Right("Changed to success") }
// assertSoftly {
// result.isLeft() shouldNotBe true
// }
// }
@boysbee
boysbee / revert-a-commit.md
Created November 22, 2018 08:17 — forked from gunjanpatel/revert-a-commit.md
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}'

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@boysbee
boysbee / jdk8_optional_monad_laws.java
Created November 23, 2017 15:44 — forked from ms-tg/jdk8_optional_monad_laws.java
Does JDK8's Optional class satisfy the Monad laws? Yes, it does.
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```
@boysbee
boysbee / anorm.scala
Created July 18, 2017 16:02 — forked from davegurnell/anorm.scala
A short guide to Anorm
/*
Overview
--------
To run a query using anorm you need to do three things:
1. Connect to the database (with or without a transaction)
2. Create an instance of `anorm.SqlQuery` using the `SQL` string interpolator
3. Call one of the methods on `SqlQuery` to actually run the query
@boysbee
boysbee / nginx-tuning.md
Created June 15, 2017 17:15 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@boysbee
boysbee / docker-compose-chronograf.yml
Created May 4, 2017 11:11
docker-compose influx, chronograf,kapacitor
version: '2'
services:
# Define a Telegraf service
telegraf:
image: telegraf
volumes:
- ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
links:
- influxdb
@boysbee
boysbee / PrometheusMetricsController.scala
Created May 2, 2017 18:52 — forked from jnesbitt/PrometheusMetricsController.scala
Prometheus metrics controller for Play! Framework 2.5
package controllers
import java.io.Writer
import akka.util.ByteString
import io.prometheus.client._
import io.prometheus.client.exporter.common.TextFormat
import play.api.http.HttpEntity
import play.api.mvc._