Skip to content

Instantly share code, notes, and snippets.

View solidsnack's full-sized avatar

Jason Dusek solidsnack

  • Dallas, TX
  • 08:42 (UTC)
View GitHub Profile
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; }
tasks.shadowJar {
minimize {
exclude(dependency("org.jetbrains.kotlin:.*"))
}
}
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"
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]'.
--- 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,
@solidsnack
solidsnack / minicron.bash
Created September 6, 2017 17:05
Cron as a tiny shell script (GNU tools required)
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"
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()
}
@solidsnack
solidsnack / template.bash
Created June 28, 2017 03:43
Template script with basic help, error handling and utilities
#!/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
@solidsnack
solidsnack / ssh-srv
Last active November 27, 2019 11:49
SSH to servers that have SRV records
#!/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
@solidsnack
solidsnack / ad-astra.rs
Last active August 28, 2016 05:17
Aster for module generation
#[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";
}