Skip to content

Instantly share code, notes, and snippets.

View kepocnhh's full-sized avatar

Stanley Wintergreen kepocnhh

View GitHub Profile
@kepocnhh
kepocnhh / sagp.sh
Created October 15, 2023 12:47
OS X security add generic password
#!/usr/local/bin/bash
echo 'Enter service name (default is common):'
read SERVICE_NAME || exit 1
if test -z "$SERVICE_NAME"; then
SERVICE_NAME='common'; fi
echo 'Enter account name:'
read ACCOUNT_NAME || exit 1
@kepocnhh
kepocnhh / osx_security_sample_tk.sh
Last active October 14, 2023 16:40
OS X security sample to keychain.
KEYCHAIN='keychain_baz'
# https://www.unix.com/man-page/osx/1/security/
security delete-keychain "$KEYCHAIN"
security create-keychain -P "$KEYCHAIN"
if test $? -ne 0; then
echo 'Create keychain error!'; exit 1; fi
SERVICE_NAME='service_foo'
@kepocnhh
kepocnhh / osx_security_sample_ww.sh
Created October 14, 2023 16:29
OS X security sample with warning.
SERVICE_NAME='service_foo'
ACCOUNT_NAME='account_bar'
PASSWORD_VALUE='password_bar'
security delete-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" &> /dev/null
# Add a generic password item to the default keychain.
security add-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w "$PASSWORD_VALUE" -T ''
if test $? -ne 0; then
@kepocnhh
kepocnhh / osx_security_sample.sh
Last active October 14, 2023 16:25
OS X security sample.
SERVICE_NAME='service_foo'
ACCOUNT_NAME='account_bar'
PASSWORD_VALUE='password_bar'
security delete-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" &> /dev/null
# Add a generic password item to the default keychain without warning.
security add-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w "$PASSWORD_VALUE"
if test $? -ne 0; then
@kepocnhh
kepocnhh / ExtraType.kt
Created October 11, 2023 18:58
ExtraType dictionary extensions
sealed interface ExtraType<T : Any>
object Str : ExtraType<String>
object Int32 : ExtraType<Int>
object Int64 : ExtraType<Long>
private fun <T : Any> Bundle.getOrNull(type: ExtraType<T>, key: String): T? {
if (!containsKey(key)) return null
return when (type) {
Str -> getString(key, null) as T?
Int64 -> getLong(key, -1) as T
@kepocnhh
kepocnhh / gpg_write.sh
Last active May 1, 2023 14:54
Rewrite encrypted.
#!/usr/local/bin/bash
if test $# -ne 2; then
echo "Script needs 2 arguments: ENCRYPTED, KEY. But actual is $#!"; exit 1; fi
ENCRYPTED="$1"
KEY="$2"
for it in ENCRYPTED KEY; do
if test -z "${!it}"; then echo "Argument \"$it\" is empty!"; exit 1; fi; done
@kepocnhh
kepocnhh / gpg_read.sh
Last active May 1, 2023 14:54
Copy to clipboard parsed decrypted.
#!/usr/local/bin/bash
if test $# -ne 2; then
echo "Script needs 2 arguments: ENCRYPTED, KEY. But actual is $#!"; exit 1; fi
ENCRYPTED="$1"
KEY="$2"
for it in ENCRYPTED KEY; do
if test -z "${!it}"; then echo "Argument \"$it\" is empty!"; exit 1; fi; done
@kepocnhh
kepocnhh / sign_jar_check.sh
Created April 30, 2023 17:18
Signature JAR check.
#!/usr/local/bin/bash
if test $# -ne 4; then
echo "Script needs 4 arguments: ISSUER, KEYSTORE, KEYSTORE_PASSWORD KEY_ALIAS. But actual is $#!"; exit 1; fi
KEYSTORE_TYPE='pkcs12'
ISSUER="$1"
KEYSTORE="$2"
KEYSTORE_PASSWORD="$3"
KEY_ALIAS="$4"
#!/bin/bash
VARIANT='snapshot'
gradle clean && \
gradle "lib:assemble${VARIANT}MavenMetadata" && \
gradle "lib:assemble${VARIANT}Jar" && \
gradle "lib:assemble${VARIANT}Pom"
if test $? -ne 0; then
// https://en.wikipedia.org/wiki/Geometric_series
/**
* @param a is coefficient
* @param r is the common ratio
* @return sum of a*r.pow(n) + a*r.pow(n - 1) + ... + a*r.pow(m - 1) + a*r.pow(m)
*/
fun getSumOfGeometricSeries(
a: Int = 1,
r: Double = 10.0,