Skip to content

Instantly share code, notes, and snippets.

View royki's full-sized avatar
😃
I may be slow to respond.

ROY royki

😃
I may be slow to respond.
View GitHub Profile
@royki
royki / cue_for_devops.md
Created May 19, 2024 23:45 — forked from ptMcGit/cue_for_devops.md
CUE for DevOps

CUE for DevOps

Overview

This is a tutorial that uses a toy infrastructure project to highlight some of CUE's features and show how it can be used to simplify and manage infrastructure. Go to Tutorial if you want to skip the introductory stuff.

What is CUE?

From cuelang.org:

@royki
royki / deploy.yaml
Created January 5, 2024 13:16 — forked from alonsoir/deploy.yaml
ansible script to gather VAULT_TOKEN from a VAULT server and run a process which need it. The idea is to maintain secrets in secure, deleting VAULT_TOKEN from file system and historic.
---
- name: Ejecutar Proceso con VAULT_TOKEN
hosts: localhost # Puedes ajustar los hosts según tu entorno
gather_facts: false # Desactivar recopilación de hechos
vars:
vault_address: "http://direccion-de-tu-vault:8200" # Ajusta la dirección de tu Vault Server
tasks:
- name: Establecer VAULT_TOKEN como variable de entorno
import java.util.BitSet
object Solution {
def solution(A: Array[Int]): Int = {
val bitz = new BitSet(A.size + 1)
val good = A.foldLeft(true)((current, i) =>
if (current) {
(i, bitz.get(i)) match {
case (x, _) if x > A.size =>
object Solution {
def solution(A: Array[Int]): Int = {
val positive = new java.util.BitSet()
val negative = new java.util.BitSet()
A.foldLeft(0) { (current, i) =>
val duplicate = if (i < 0) (negative get i * -1)
else (positive get i)
duplicate match {
object Solution {
def solution(A: Array[Int]): Int = {
val (results, _) = A.sorted.foldLeft((0, 0)) { (t, item) =>
val (current, last) = t
val next = last + 1
item match {
case x if x < 0 => (current, last)
case `last` => (item, item)
object Solution {
def solution(A: Array[Int]): Int = {
(A.foldLeft[(Int, Option[Double], Int)]((0, None, -1)) { (t, item) =>
val (index, min, results) = t
val checkPair = index <= A.size - 2
val checkTrio = index <= A.size - 3
import scala.math.{min, abs}
object Solution {
def solution(A: Array[Int]): Int = {
if (A.size < 2 || A.size > 100000) sys.error(s"Invalid input - array size: ${A.size}")
val total = A.map(_.toLong).sum
(A.foldLeft[(Int, Long, Long)](-1, -1, 0l) { (t, i) =>
if (i < -1000 || i > 1000) sys.error(s"Invalid array element: $i")
@royki
royki / CodilityMissingInteger.scala
Created July 31, 2019 20:57 — forked from feliperazeek/CodilityMissingInteger.scala
Codility Missing Integer in Scala
object Solution {
def solution(A: Array[Int]): Int = {
val bitz = new java.util.BitSet(A.size)
val n = A.foldLeft(0) { (total, i) =>
if (i > 0 && i <= A.size && !bitz.get(i)) {
bitz.set(i)
total + 1
} else total
@royki
royki / CodilityTreeHeight.scala
Created July 31, 2019 20:57 — forked from feliperazeek/CodilityTreeHeight.scala
Codility TreeHeight Scala
object Solution {
def solution(T: Tree): Int = {
def height(t: Tree, i: Int): Int = {
val left = (Option(t.l).map(height(_, i + 1)) getOrElse i)
val right = (Option(t.r).map(height(_, i + 1)) getOrElse i)
scala.math.max(i, scala.math.max(left, right))
}
object Solution {
def solution(A: Array[Int]): Int = {
val N = A.size
if (N < 1 || N > 1000000) sys.error(s"Invalid array size: $N")
A.foldLeft(0) { (current, i) =>
i ^ current
}
}