Skip to content

Instantly share code, notes, and snippets.

View holgerbrandl's full-sized avatar

Holger Brandl holgerbrandl

View GitHub Profile
// Code generated by moshi-kotlin-codegen. Do not edit.
@file:Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION",
"RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier",
"PLATFORM_CLASS_MAPPED_TO_KOTLIN")
package org.kalasim.scratch
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
1 Product 1 Pa wafer 7.28571 25
2 Product 2 Pb wafer 4.28571 25
3 Product 3 test wafer 0.42 25
pacman::p_load(zeallot)
load_multiple <- function (rdataFile)
{
load(rdataFile, ex <- new.env())
mget(objects(ex, sorted = T), envir = ex)
}
foo = 1
bar = 2
CREATE STREAM ratings (title VARCHAR, release_year INT, rating DOUBLE, timestamp VARCHAR)
WITH (kafka_topic='ratings',
key='title',
timestamp='timestamp',
timestamp_format='yyyy-MM-dd HH:mm:ss',
partitions=1,
value_format='avro');
INSERT INTO ratings (title, release_year, rating, timestamp) VALUES ('Die Hard', 1998, 8.2, '2019-07-09 01:00:00');
require(dplyr)
require(ggplot2)
# make sure that purrr package is installed to use purrr::set_names
# aggregate data
df = mpg %>%
group_by(year, manufacturer) %>%
summarize(mixmpg = mean(cty + hwy)) %>%
# create dummy var which reflects order when sorted alphabetically
mutate(ord =sprintf("%02i", as.integer(rank(mixmpg))) )
@holgerbrandl
holgerbrandl / add_chr_prefix_to_bw.kts
Last active October 26, 2018 09:08
Rewrites a big-wig file while adding a 'chr' prefix to the chromosome names. Requires `kscript`.Usage `add_chr_prefix_to_bw.kts chrom_sizes.fai in.bw out.bw`
#!/usr/bin/env kscript
// kshell_kts.sh /Users/brandl/.kscript/kscript_tmp_project__adjust_bigwig_ids.kts_1540471113973/src/adjust_bigwig_ids.kts
@file:DependsOn("org.jetbrains.bio:big:0.8.3")
@file:DependsOn("com.xenomachina:kotlin-argparser:2.0.7")
import com.xenomachina.argparser.ArgParser
import com.xenomachina.argparser.DefaultHelpFormatter
import com.xenomachina.argparser.mainBody
import org.apache.log4j.ConsoleAppender
@holgerbrandl
holgerbrandl / RevisedTornadoFxSwingExample.kt
Last active September 14, 2018 07:48
Swing integration example without using unnecessary JFrame
import javafx.application.Platform
import javafx.beans.property.SimpleObjectProperty
import javafx.embed.swing.JFXPanel
import javafx.scene.image.Image
import javafx.stage.Stage
import tornadofx.*
import javax.swing.SwingUtilities
object SwingApp {
private fun createAndShowGUI() {
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@holgerbrandl
holgerbrandl / Univocity.kt
Created September 5, 2018 20:05
univocity as file reader backend for krangl
package krangl.experimental
import com.univocity.parsers.common.record.Record
import com.univocity.parsers.tsv.TsvParser
import com.univocity.parsers.tsv.TsvParserSettings
import krangl.*
import java.io.Reader
/**
* @author Holger Brandl
@holgerbrandl
holgerbrandl / mpg.txt
Created August 24, 2018 20:11
Fuel economy data from 1999 and 2008 for 38 popular models of car This dataset contains a subset of the fuel economy data that the EPA makes available on http://fueleconomy.gov. It contains only models which had a new release every year between 1999 and 2008 - this was used as a proxy for the popularity of the car. Exported from R with: readr::w…
manufacturer model displ year cyl trans drv cty hwy fl class
audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
audi a4 2 2008 4 manual(m6) f 20 31 p compact
audi a4 2 2008 4 auto(av) f 21 30 p compact
audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
audi a4 2.8 1999 6 manual(m5) f 18 26 p compact
audi a4 3.1 2008 6 auto(av) f 18 27 p compact
audi a4 quattro 1.8 1999 4 manual(m5) 4 18 26 p compact
audi a4 quattro 1.8 1999 4 auto(l5) 4 16 25 p compact