Skip to content

Instantly share code, notes, and snippets.

View nakov's full-sized avatar
🎯
Focused on the global SoftUni expansion: https://softuni.org

Svetlin Nakov nakov

🎯
Focused on the global SoftUni expansion: https://softuni.org
View GitHub Profile
@nakov
nakov / secp256k1-example.js
Last active April 9, 2024 16:32
ECDSA in JavaScript: secp256k1-based sign / verify / recoverPubKey
let elliptic = require('elliptic');
let sha3 = require('js-sha3');
let ec = new elliptic.ec('secp256k1');
// let keyPair = ec.genKeyPair();
let keyPair = ec.keyFromPrivate("97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a");
let privKey = keyPair.getPrivate("hex");
let pubKey = keyPair.getPublic();
console.log(`Private key: ${privKey}`);
console.log("Public key :", pubKey.encode("hex").substr(2));
@nakov
nakov / ffmpeg -h decoder=h264_cuvid
Created November 29, 2020 16:09
ffmpeg: NVidia hardware encoder `h264_nvenc` and hardware decoder `h264_cuvid` - Documentation (Nov 2020)
ffmpeg version 2020-11-29-git-f194cedfe6-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable
@nakov
nakov / course-program.md
Created February 8, 2024 12:35
Containers, Cloud and DevOps

Containers, Cloud and DevOps

Containers, Cloud and DevOps (88 hours).

Virtualization and containers, Docker, DevOps, cloud technologies and platforms. Exercises with Docker, Azure and GitHub Actions.

Course Program

Part I: Containers

@nakov
nakov / modsqrt.py
Created March 7, 2018 13:00
mod_sqrt - Python 3 implementation
def modular_sqrt(a, p):
def legendre_symbol(a, p):
""" Compute the Legendre symbol a|p using
Euler's criterion. p is a prime, a is
relatively prime to p (if p divides
a, then a|p = 0)
Returns 1 if a has a square root modulo
p, -1 otherwise.
@nakov
nakov / AES-256-CTR-Argon2-HMAC-SHA256-example.js
Last active November 9, 2023 02:32
Cryptography for JavaScript Developers: Hashes, HMAC, PBKDF2, Scrypt, Argon2, AES-256-CTR, ECDSA, EdDSA, secp256k1, Ed25519
const aes = require("aes-js");
const argon2 = require("argon2");
const crypto = require("crypto");
const cryptoJS = require("crypto-js");
// Encrypt using AES-256-CTR-Argon2-HMAC-SHA-256
async function aes256ctrEncrypt(plaintext, password) {
let argon2salt = crypto.randomBytes(16); // 128-bit salt for argon2
let argon2Settings = { type: argon2.argon2di, raw: true,
timeCost: 8, memoryCost: 2 ** 15, parallelism: 2,
@nakov
nakov / ECDSA-secp256k1-example.java
Last active July 21, 2023 09:37
ECDSA with secp256k1 in Java: generate ECC keys, sign, verify
import org.bouncycastle.util.encoders.Hex;
import org.web3j.crypto.*;
import java.math.BigInteger;
public class ECCExample {
public static String compressPubKey(BigInteger pubKey) {
String pubKeyYPrefix = pubKey.testBit(0) ? "03" : "02";
String pubKeyHex = pubKey.toString(16);
String pubKeyX = pubKeyHex.substring(0, 64);
@nakov
nakov / (1) script.js
Last active June 6, 2023 11:57
k6 Performance Test Script - Example
import { sleep, group, check } from "k6";
import http from "k6/http";
export let options = {
thresholds: {
// 95% of requests must finish within 500 ms & 99% within 1500 ms
http_req_duration: ['p(95) < 500', 'p(99) < 1500'],
},
};
@nakov
nakov / http-get.js
Created February 20, 2023 14:09
Shelly HTTP GET
Shelly.call(
"HTTP.GET",
{"url": "https://api.zippopotam.us/us/90210"},
function (response) {
if (response && response.code && response.code === 200) {
print(JSON.stringify(response.body));
Shelly.emitEvent("HTTP-result", response.body);
}
else {
print("Error: HTTP request failed.");
@nakov
nakov / plugs-play-with-LED-lights.js
Created February 8, 2023 15:06
Shelly Plug: Play with LED
function shellyPlugSChangeLEDColor(red, green, blue, brightness) {
let config = {
"config": {
"leds": {
"colors": {
"switch:0": {
"on": {
"rgb": [red, green, blue],
"brightness": brightness
}
@nakov
nakov / Output
Created February 8, 2023 13:35
Shelly: Number to String without Trailing Zeros
Num (standard): 123.131000
Num (no trailing zeros): 123.131