Skip to content

Instantly share code, notes, and snippets.

case class Event(name: String, start: Int, end: Int)
def validateName(name: String): Option[String] =
if (name.size > 0) Some(name) else None
def validateEnd(end: Int): Option[Int] =
if (end < 3000) Some(end) else None
def validateStart(start: Int, end: Int): Option[Int] =
if (start <= end) Some(start) else None
val raw: List<Char> = "aabcccccaaa".map { it }
println(raw.toList().fold(listOf<Char>()) { acc, value ->
if (acc.isEmpty()) listOf(value)
else {//a2, b
if (acc.last() == value) acc
else acc + value
}
})
helm ls #list releases
helm test #run tests
#installs a release from a remote repo or local folder, in <namespace> and with extra configuration values values.yaml
#helm install <release> <chart_name|local folder> -n <namespace> -f <file_location>
helm install elasticsearch elastic/elasticsearch -n elasticsearch-poc -f ./values.yaml
helm install nginx nginx # the first nginx is the name of the release, the second one is the name of the folder
helm delete <release> #delete a release.
helm delete elasticsearch
#renders charts templates locally
helm template <release> <chart> [flags]
POST /tmdb/_close
POST /tmdb/_open
PUT /tmdb/_settings
{
"analysis": {
"filter": {
"my_shingle": {
"type": "shingle",
"min_shingle_size": 2,
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); #B MapType mapType =
mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
MapType yamlConfigType = mapper .getTypeFactory() .constructMapType( HashMap.class, mapper.getTypeFactory().constructType(String.class), mapType);
Path configFilePath;
Map<String, Map<String, Object>> config = mapper.readValue(configFilePath.toFile(), yamlConfigType);
AuthStrategy authStrategy = null;
Map<String, Object> authConfig = config.get("auth")
if (authConfig.get("strategy").equals(USERNAME_PASSWORD_STRATEGY)) {
authStrategy = new UsernamePasswordAuthStrategy( (String) authConfig.get("username"), (String) authConfig.get("password"));
@mcalavera81
mcalavera81 / request-deduplication
Created August 12, 2021 09:39
request deduplication
function UpdateChatRoom(req: UpdateChatRoomRequest): ChatRoom {
if (req.requestId === undefined) { // #A
return ChatRoom.update(...);
}
const hash = crypto.createHash('sha256').update(JSON.stringify(req)).digest('hex');
const cachedResponse = cache.get(req.requestId);
if (!cachedResult) { // #B
const response = ChatRoom.update(...);
cache.set(req.requestId, { response, hash }); // #C
return response;
@mcalavera81
mcalavera81 / retries-exp-back-off
Last active August 11, 2021 22:54
exponential back-off algorithm
async function getChatRoomWithRetries(id: string, maxDelayMs = 32, maxRetries = 10): Promise<ChatRoom> {
return new Promise<ChatRoom>(async (resolve, reject) => {
let retryCount = 0;
let delayMs = 1000;
while (true) {
try {
return resolve(GetChatRoom({ id }));
} catch (e) {
if (retryCount++ > maxRetries) return reject(e);
await new Promise((resolve) => {
@mcalavera81
mcalavera81 / awsecsdeploy-stack.ts
Last active April 14, 2021 10:19 — forked from bkono/awsecsdeploy-stack.ts
CDK App: ecs, alb, certs, postgres, elasticache, elasticsearch
import cdk = require('@aws-cdk/cdk');
import ec2 = require('@aws-cdk/aws-ec2');
import elastic = require('@aws-cdk/aws-elasticache');
import rds = require ('@aws-cdk/aws-rds');
import es = require("@aws-cdk/aws-elasticsearch");
import ecs = require('@aws-cdk/aws-ecs');
import s3 = require("@aws-cdk/aws-s3");
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import route53 = require('@aws-cdk/aws-route53');
import certificateManager = require("@aws-cdk/aws-certificatemanager");
{
"files.exclude": {
// Hide the node_modules folder
"node_modules/": true,
// Hide all files that end in .d.ts
"**/*.d.ts": true,
// Hide all files that end with .js if they have a .ts file
"**/*.js": {
"when": "$(basename).ts"
},