Skip to content

Instantly share code, notes, and snippets.

@dirkraft
dirkraft / kotlin.gradle
Last active July 6, 2017 19:57
Gradle Kotlin support.
/*
# Put this in root build.gradle
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories { mavenCentral() }
dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
}
# Then in each project build.gradle where desired:
apply from: '../gradle/kotlin.gradle'
*/
@dirkraft
dirkraft / kotlin.min.gradle
Last active June 23, 2017 15:04
Minimal Gradle Kotlin support.
/*
# Put this in root build.gradle
buildscript {
ext.kotlin_version = '1.1.2-5'
repositories { mavenCentral() }
dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
}
# Then in each project build.gradle where desired:
apply from: '../gradle/kotlin.min.gradle'
*/
@dirkraft
dirkraft / userscripts.github.issueLinkTitle.js
Last active March 19, 2018 19:26
UserScript to decorate #1234 issue links with their actual title. Needs an access token: https://github.com/settings/tokens
// ==UserScript==
// @name GitHub Issue Link Title (GHILT)
// @version 0.0.1
// @author dirkraft
// Must match aggressively due to HTML5 History, which won't trigger Tampermonkey @match.
// @match https://github.com/*/*
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// ==/UserScript==
@dirkraft
dirkraft / logback.xml
Last active June 22, 2017 16:20
Basic logback.xml with colorized output
<configuration scan="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<!-- @formatter:off -->
<pattern>%highlight(%-5level) %d{yyyy-MM-dd'T'HH:mm:ss.SSS} %yellow([%thread]) %blue(%logger{36}) %msg%n</pattern>
<!-- @formatter:on -->
</encoder>
</appender>
@dirkraft
dirkraft / PgCopy.scala
Created February 23, 2018 23:09
Postgres COPY helper in Scala using JDBC Postgres driver. Made for TSV-representable rows.
import org.postgresql.copy.CopyManager
import org.postgresql.core.BaseConnection
import org.slf4j.LoggerFactory
import java.nio.charset.Charset
import java.sql.Connection
/** Postgres helper to bulk load data into a db as quickly as possible. */
class PgCopy(db: DbAccess) extends Serializable {
@dirkraft
dirkraft / console_table.py
Last active June 17, 2021 15:53
Print tabular data to a console making a best effort to write one row per line, adjusting column sizes and truncating automatically to fit each row.
"""
Print tabular data to a console making a best effort to write one row per line,
adjusting column sizes and truncating automatically to fit each row.
The main function is `console_table.fmt`. Execute this script to run the sample.
https://gist.github.com/dirkraft/f0759cebfd4d4567365c36570f1e3e51
Written against python 3.6.3. Requires pydash (sorry purists, I like this library :D ).
create view index_dupes as
SELECT pg_size_pretty(sum(pg_relation_size(sub.idx))::bigint) AS size,
(array_agg(sub.idx))[1] AS idx1,
(array_agg(sub.idx))[2] AS idx2,
(array_agg(sub.idx))[3] AS idx3,
(array_agg(sub.idx))[4] AS idx4
FROM ( SELECT pg_index.indexrelid::regclass AS idx,
(((((((pg_index.indrelid::text || '
'::text) || pg_index.indclass::text) || '
'::text) || pg_index.indkey::text) || '
/*
Copyright Alex Leone, David Nufer, David Truong, 2011-03-11. kathack.com
javascript:var i,s,ss=['http://kathack.com/js/kh.js','http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'];for(i=0;i!=ss.length;i++){s=document.createElement('script');s.src=ss[i];document.body.appendChild(s);}void(0);
*/
var BORDER_STYLE = "1px solid #bbb",
CSS_TRANSFORM = null,
CSS_TRANSFORM_ORIGIN = null,
POSSIBLE_TRANSFORM_PREFIXES = ['-webkit-', '-moz-', '-o-', '-ms-', ''],