Skip to content

Instantly share code, notes, and snippets.

View nphausg's full-sized avatar
🏠
Engineer @ GXS Bank | MSc πŸŽ“ | Technical Writer πŸ‡»πŸ‡³ πŸ‡ΈπŸ‡¬ πŸ‡²πŸ‡Ύ πŸ‡¦πŸ‡Ί πŸ‡ΉπŸ‡­

Leo N nphausg

🏠
Engineer @ GXS Bank | MSc πŸŽ“ | Technical Writer πŸ‡»πŸ‡³ πŸ‡ΈπŸ‡¬ πŸ‡²πŸ‡Ύ πŸ‡¦πŸ‡Ί πŸ‡ΉπŸ‡­
View GitHub Profile
@nphausg
nphausg / FindTheSmallestPositiveNumberMissing.java
Created December 9, 2021 06:44
FindTheSmallestPositiveNumberMissing from an Sorted Array
/*
* Created by nphau on 09/12/2021, 00:30
* Copyright (c) 2021 . All rights reserved.
* Last modified 09/12/2021, 15:54
*/
public int solution(int[] numbers) {
Arrays.sort(numbers);
int min = 1;
for (int i : numbers){
@nphausg
nphausg / FindTheSmallestPositiveNumberMissing.kt
Last active December 9, 2021 06:43
FindTheSmallestPositiveNumberMissing from an unsorted array
/*
* Created by nphau on 09/12/2021, 00:30
* Copyright (c) 2021 . All rights reserved.
* Last modified 09/12/2021, 15:54
*/
fun solution(numbers: IntArray): Int {
val n = numbers.size
val present = BooleanArray(n + 1)
numbers.forEach { number ->
@nphausg
nphausg / PBKDF2WithHmacSHA512.kt
Created December 3, 2021 03:54
PBKDF2WithHmacSHA512
// Use "PBKDF2WithHmacSHA512" with android O version and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512")
val pwSpec = PBEKeySpec(secret.toCharArray(), salt, iterations, keyLength)
skf.generateSecret(pwSpec).encoded
}
@nphausg
nphausg / SecretKeyFactory_Algorithms.csv
Created December 3, 2021 03:46
SecretKeyFactory algorithms
Algorithm Supported API Levels
AES 23+
DES 1+
DESede 1+
HmacSHA1 23+
HmacSHA224 23+
HmacSHA256 23+
HmacSHA384 23+
HmacSHA512 23+
PBEwithHmacSHA1 1+
import io.ktor.features.*
// ...
fun main() {
private val server by lazy {
embeddedServer(Netty, PORT, watchPaths = emptyList()) {
// configures Cross-Origin Resource Sharing. CORS is needed to make calls from arbitrary
// JavaScript clients, and helps us prevent issues down the line.
install(CORS) {
anyHost()
}
@nphausg
nphausg / embedded_server.gradle
Last active April 10, 2024 09:54
embedded_server.gradle
dependencies {
//...
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
// Embedded Server
implementation 'io.ktor:ktor-server-core:2.2.4'
implementation 'io.ktor:ktor-server-netty:2.2.4'
implementation 'io.ktor:ktor-serialization-kotlinx-json:2.2.4'
implementation 'io.ktor:ktor-client-content-negotiation:2.2.4'
companion object {
private const val PORT = 5001
}
private val server by lazy {
embeddedServer(Netty, PORT, watchPaths = emptyList()) {
install(WebSockets)
install(CallLogging)
routing {
get("/") {
call.respondText(
@nphausg
nphausg / random_state.py
Last active July 25, 2021 15:30
random_state[sklearn].py
>>> x_train, x_test, y_train, y_test = train_test_split(
... x, y, test_size=4, random_state=4
... )
>>> x_train
array([[17, 18],
[ 5, 6],
[23, 24],
[ 1, 2],
[ 3, 4],
[11, 12],
@nphausg
nphausg / python.cosine.distance.py
Created July 20, 2021 16:20
python.cosine.distance
# COSIN DISTANCES
# SOLUTION 1:
import numpy as np
vector_1 = np.array([1, 5, 1, 4, 0, 0, 0, 0, 0])
vector_2 = np.array([2, 4, 1, 1, 1, 1, 0, 0, 0])
def cos_sim(a, b):
"""Takes 2 vectors a, b and returns the cosine similarity
"""
dot_product = np.dot(a, b) # x.y
@nphausg
nphausg / Fastfile
Created June 10, 2021 01:19
Fastfile: lane build bundle
private_lane :bundle do |options|
mode = (options[:mode])
yarn(command: "android:bundle:#{mode}")
sh("rm -rf ../android/app/src/main/res/drawable-*")
sh("rm -rf ../android/app/src/main/res/raw")
sh("cp -a ../app/assets/android/* ../android/app/src/main/res")
end