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
public class Reflection { | |
private static final ReflectionFactory factory; | |
static { | |
ReflectionFactory impl; | |
try { | |
Class<?> implClass = Class.forName("kotlin.reflect.jvm.internal.ReflectionFactoryImpl"); | |
impl = (ReflectionFactory) implClass.newInstance(); | |
} | |
catch (ClassCastException e) { impl = null; } |
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
tasks.shadowJar { | |
minimize { | |
exclude(dependency("org.jetbrains.kotlin:.*")) | |
} | |
} |
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
diff --git a/build.gradle.kts b/build.gradle.kts | |
index f8a65c9..9bd44d6 100644 | |
--- a/build.gradle.kts | |
+++ b/build.gradle.kts | |
@@ -6,6 +6,8 @@ dependencies { | |
} | |
plugins { | |
+ application | |
+ id("com.github.johnrengelman.shadow") version "5.1.0" |
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
export default function null2undefined<T, K extends keyof T>( | |
o: T, | |
name: K, | |
): NullableAsUndefined<T>[K] { | |
const val = o[name]; | |
return val || undefined; // Error on this line -- | |
// Type 'T[K] | undefined' is not assignable to | |
// type 'T[K] extends infer U | null ? U | undefined : T[K]'. | |
// Type 'undefined' is not assignable to | |
// type 'T[K] extends infer U | null ? U | undefined : T[K]'. |
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
--- Formatted size for total usage, percentages for indexes, toast, data. | |
--- No system tables. | |
SELECT pg_class.oid :: regclass AS tab, | |
pg_size_pretty(total) AS disk_usage, | |
(100.0 * index / greatest(1, total)) :: numeric(6, 2) AS "%index", | |
(100.0 * toast / greatest(1, total)) :: numeric(6, 2) AS "%toast", | |
(100.0 * (total - index - toast) / greatest(1, total)) :: numeric(6, 2) AS "%data", | |
reltuples AS "~rows" | |
FROM pg_class LEFT JOIN pg_namespace ON pg_namespace.oid = relnamespace, | |
pg_total_relation_size(pg_class.oid) AS total, |
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
function minicron {( | |
set -o errexit -o pipefail -o nounset | |
spec="$1" ; shift | |
cmd=( "$@" ) | |
present="$(date -u +%FT%TZ)" | |
target="$(date -u +%F)T$spec:00Z" | |
next_target="$(date -u -d tomorrow +%F)T$spec:00Z" | |
if [[ $present > $target ]] | |
then target="$next_target" |
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 median(data: List<Long>): Long { | |
val sorted = data.sorted() | |
// NB: When data.size is odd, we have: i == j | |
val i = sorted.size / 2 | |
val j = (sorted.size - 1) / 2 | |
val meanOfMiddle = (sorted[j] + sorted[i]) / 2.0 | |
return meanOfMiddle.toLong() | |
} |
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
#!/bin/bash | |
set -o errexit -o nounset -o pipefail | |
function -h { | |
cat <<USAGE | |
USAGE: template.bash | |
Implement your script with this template. | |
USAGE | |
}; function --help { -h ;} # A nice way to handle -h and --help |
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
#!/bin/bash | |
set -o errexit -o nounset -o pipefail | |
function --help { | |
cat <<USAGE | |
USAGE: ssh-srv <DNS name> <SSH options and args>* | |
Allows SSH to nodes referenced by SRV records. The SRV records can be | |
referenced in a "plain style": | |
service.example.com |
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
#[allow(dead_code, non_upper_case_globals)] | |
pub mod code { | |
const x: &'static str = "X string"; | |
const y: &'static str = "Y string"; | |
const z: &'static str = "another string"; | |
} |
NewerOlder