Skip to content

Instantly share code, notes, and snippets.

@blzjns
blzjns / trie.js
Last active April 11, 2022 07:24
Find words using a tree-like struct (Trie)
/*
E.g.:
[root-node]
/ | \
B D S
/ | \
A O__ E__
/\ \ \ \
@blzjns
blzjns / trivy_templating.md
Last active March 29, 2022 22:10
How to use golang templates for generating custom trivy reports

Trivy templating

Trivy uses golang templates. Thus, whenever opening a tag {{an_opening_tag}}, most likely it needs to be closed with {{end}}.

For example:

The tag range works similarly to a for-each loop, where . represents an initial object

{{range . as $myObj}}--- This a text concatenating {{$myObj.Target}} ---{{end}}
if [ -z $mexer_c_nois ]; then
se_prepara
fi
@blzjns
blzjns / binaryJump.js
Created January 9, 2022 10:44
BinarySearch on multi-dimensional (2D grid), best jump/move from position [X, Y] given a set of directions (up, down, left, right)
/*
Using BinarySearch,
from a given point [x, y] on a 2D grid (WxH) find the next-best position in order to reach an element as soon as possible.
*/
const W = readInt('Building width: '); // width of the building.
const H = readInt('Building height: '); // height of the building.
const N = readInt('Max. no of turns: '); // maximum number of turns before game over.
let X = readInt('Start from X: ');
let Y = readInt('Start from Y: ');
@blzjns
blzjns / git-prompt.sh
Last active February 15, 2020 04:42
Custom git bash command-line header. Displays user name, current path, repo name, and repo branch
displayUserTxt=">_ blzjns"
userBgColor="\e[7;49;32m"
branchColor="\e[1;35m"
pathColor="\e[0;33m"
repoColor="\e[36m"
boldTxt=$(tput bold)
noTextFmt="\e[0m"
if test -f /etc/profile.d/git-sdk.sh; then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
@blzjns
blzjns / BubbleSortExample.java
Created September 8, 2017 00:05
Bubble Sort Sample with Comments
package com.company;
import java.util.Arrays;
public class BubbleSortExample {
public static void main(String[] args) {
int[] list = {34, 203, 3, 746, 200, 984, 198, 764, 9}; // list of numbers, aka: array
bubbleSort(list);
@blzjns
blzjns / fixGitUntrackedFiles.sh
Last active December 12, 2019 16:16
Fixes failing (not working) .gitignore
git rm -r --cached .
git add .
git commit -m "fix untracked files"
@blzjns
blzjns / CircuitBreakerSpotlight.scala
Created August 25, 2016 19:44 — forked from patriknw/CircuitBreakerSpotlight.scala
Circuit Breaker Spotlight
import akka.pattern.CircuitBreaker
val breaker =
CircuitBreaker(system.scheduler,
maxFailures = 5,
callTimeout = 10.seconds,
resetTimeout = 1.minute)
def dangerous: Future[String] =
breaker.withCircuitBreaker(Future(dangerousCall))
@blzjns
blzjns / CustomContentType.scala
Created August 10, 2016 18:19
akka http custom content type
import akka.http.scaladsl.Http
import akka.http.scaladsl.client.RequestBuilding._
val customContentType = ContentType(MediaType.customWithFixedCharset("binary", "octet-stream", HttpCharsets.`UTF-8`)) //Content-Type: binary/octet-stream
val someData = "{}"
//simple http call using above content type
Http().singleRequest(
Put("http://127.0.0.1:8080/someendpoint")
@blzjns
blzjns / MultipartFormData.scala
Last active August 30, 2019 13:27
multipart akka http scala request formdata file client
import java.nio.file.{Path, Paths}
import akka.stream.scaladsl.Source
val foo: Path = Paths.get("/images/foo.jpg")
val bar: Path = Paths.get("/images/bar.png")
val data = Multipart.FormData {
Source {
List (
Multipart.FormData.BodyPart.fromPath("foo", ContentTypes.`application/octet-stream`, foo),