Skip to content

Instantly share code, notes, and snippets.

View AlexITC's full-sized avatar

Alexis Hernandez AlexITC

View GitHub Profile
@AlexITC
AlexITC / scala-steward.yml
Created June 2, 2022 21:48
Scala steward sample github actions job
# See https://hector.dev/2020/11/18/centralized-scala-steward-with-github-actions
name: Scala Steward
on:
schedule:
# Schedule to run every Sunday @ 12PM UTC. Replace this with
# whatever seems appropriate to you.
- cron: "0 0 * * 0"
# Provide support for manually triggering the workflow via GitHub.
workflow_dispatch:
@AlexITC
AlexITC / README.md
Created April 12, 2021 18:51 — forked from magnetikonline/README.md
Nginx keepalive connections config example to upstream servers.

Nginx upstream HTTP keepalive config example

As per Nginx documentation, the key directives of proxy_http_version and proxy_set_header need to be set as per below:

upstream backend {
	server 127.0.0.1:8080;
	keepalive 8;
}

server {

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@AlexITC
AlexITC / config.yml
Created November 3, 2019 01:41
Angular integration with CircleCi
build-web:
working_directory: ~/repo
docker:
- image: circleci/node:8-browsers
steps:
- checkout
- restore_cache:
key: my-project-{{ .Branch }}-{{ checksum "enterprise-web/package-lock.json" }}
- run: cd web && npm install
- save_cache:
import play.api.libs.json._
import scala.reflect.runtime.universe._
case class Sample(id: String, value: Int = 0)
def checkedReads[T](underlyingReads: Reads[T])(implicit typeTag: TypeTag[T]): Reads[T] = new Reads[T] {
def classFields[T: TypeTag]: Set[String] = typeOf[T].members.collect {
case m: MethodSymbol if m.isCaseAccessor => m.name.decodedName.toString
}.toSet
@AlexITC
AlexITC / apply-commits.rb
Last active January 15, 2021 16:24
Update a commit log file from commits on external repos
# script that updates the commit log from external repos
#
# steps:
# - create a file called commits.log containing the git log to be applied,
# a simple way is replacing the commit hash with the last known commit hash
# and run this command on the external repo:
# git log | sed '/7467bdc51ad57371ef20bffc2f79cc4a792eb97f/Q' > commits.log
#
# - move the commits.log file to the root of the XSN repo.
# - run: ruby apply-commits.rb
@AlexITC
AlexITC / gist:1ebdb88e0913e6224478bcb797136c86
Created August 31, 2018 15:07 — forked from liudong/gist:3993726
Java: Generate Public/Private Keys
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.KeyFactory;
import java.security.spec.EncodedKeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.NoSuchAlgorithmException;
@AlexITC
AlexITC / update-xsnd.sh
Last active July 27, 2018 23:20
Update the xsn masternode
# run the following commands, one after another one
# these commands assumed you have a working masternode
# 1. download latest version
wget https://github.com/X9Developers/XSN/releases/download/v1.0.13/xsn-1.0.13-linux64.tar.gz -O xsn.tar.gz
# 2. unzip the files
tar -zxvf xsn.tar.gz
# 3. stop previous xsnd if running, if this fails, it means no xsnd was running
// from https://github.com/AlexITC/crypto-coin-alerts/blob/master/alerts-server/app/com/alexitc/coinalerts/data/anorm/AnormPostgresDAL.scala#L24
def withConnection[A](block: Connection => ApplicationResult[A]): ApplicationResult[A] = {
try {
database.withConnection(block)
} catch {
case e: PSQLException if isIntegrityConstraintViolationError(e) =>
Bad(createIntegrityConstraintViolationError(e)).accumulating
}
}
@AlexITC
AlexITC / PostgresErrorMapper.scala
Last active January 26, 2018 04:14
Map PSQLException to a foreign key violation error
import org.postgresql.util.PSQLException
object PostgresErrorMapper {
// see https://www.postgresql.org/docs/9.6/static/errcodes-appendix.html
def isForeignKeyViolationError(e: PSQLException): Boolean = "23503" == e.getSQLState
def createForeignKeyViolationError(e: PSQLException): PostgresIntegrityViolationError = {
// assumes not null
val detail = e.getServerErrorMessage.getDetail