This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> List<List<T>>.transpose(): List<List<T>> { | |
var transposed = mutableListOf<List<T>>() | |
for (i in first().indices) { | |
val col: MutableList<T> = ArrayList() | |
forEach { row -> | |
col.add(row[i]) | |
} | |
transposed.add(col) | |
} | |
return transposed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Start-Process powershell.exe "-WindowStyle Minimized -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit | |
} | |
Get-PnpDevice -Class "Display" | Disable-PnpDevice -Confirm:$false | |
Get-PnpDevice -Class "Display" | Enable-PnpDevice -Confirm:$false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by pgebert on 03/08/23. | |
* | |
* Encodes and decodes a string on a Linux system. | |
*/ | |
// encode with base64 - Output: SGVsbG8= | |
echo -n 'Hello' | base64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.TreeMap | |
fun <K, V> treeMapOf(vararg pairs: Pair<K, V>): TreeMap<K, V> = | |
TreeMap<K, V>().apply { putAll(pairs) } | |
fun <K : Comparable<K>, V> Map<K, V>.toTreeMap(): TreeMap<K, V> = | |
TreeMap<K, V>().apply { putAll(this@toTreeMap) } | |
// Usage: | |
val mapA = treeMapOf(1 to "A") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION jsonb_replace_by_key(obj jsonb, search text, substitute jsonb) RETURNS jsonb | |
STRICT LANGUAGE SQL AS $$ | |
SELECT CASE jsonb_typeof(obj) | |
WHEN 'object' THEN | |
(SELECT coalesce(jsonb_object_agg(key, CASE WHEN key = search | |
THEN substitute | |
ELSE jsonb_replace_by_key(value, search, substitute) | |
END), '{}'::jsonb) | |
FROM jsonb_each(obj)) | |
WHEN 'array' THEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by pgebert on 01/02/22. | |
* | |
* Get the first and last n digits of an integer number | |
*/ | |
import math | |
def first_n_digits(num: int, n: int): | |
return abs(num) // 10 ** (int(math.log(num, 10)) - n + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by pgebert on 01/02/22. | |
* | |
* Iterator for fibonacci numbers. | |
*/ | |
from typing import Iterator | |
def fibonacci() -> Iterator[int]: | |
a, b = 1, 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Generator | |
import pytest | |
from flask import Flask | |
from ..app import create_app | |
/** | |
* Created by pgebert on 10/01/22. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by pgebert on 14/01/22. | |
* | |
* Test whether a number is prime or not in python. | |
*/ | |
def is_prime(n: int) -> bool: | |
"""Primality test for integers.""" | |
if n <= 3: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import json | |
/** | |
* Created by pgebert on 06/12/21. | |
* | |
* Decryption of an example jwt token with python. | |
*/ | |
token = 'eyJuYW1lIjogInVzZXJfbmFtZSJ9' |
NewerOlder