Skip to content

Instantly share code, notes, and snippets.

View cbruegg's full-sized avatar

Christian Brüggemann cbruegg

View GitHub Profile
@cbruegg
cbruegg / rewe-lieferservice-verfuegbarkeit.js
Last active January 26, 2024 19:19
Scriptable REWE Lieferservice Verfügbarkeit
let zipCode = "33100"
let widget = new ListWidget()
widget.setPadding(8, 8, 8, 8)
widget.url = "https://shop.rewe.de/"
await createWidget()
Script.setWidget(widget)
Script.complete()

Using Kotlin in Android projects

What is Kotlin?

Kotlin is a programming language backed by JetBrains, the company that develops IntelliJ IDEA, which is the backend of Android Studio. After five years of development, version 1.0 was released in February, 2016. Kotlin compiles to JVM bytecode that is fully compatible with the Android platform. The developers even pay special attention to it by providing libraries (for example Anko), tooling and more.

It is a language designed for interoperability with Java code, which allows for a gradual migration from Java to Kotlin. The tooling is great and aids usability much. Additionally, picking up the language is very easy if you already know Java, since the syntax and concepts are similar, while still providing a lot of value for developers held back by the bad Java support on Android. Most developers are currently limited to Java 7 or even Java 6 and it will take a long time before we'll be able to properly use features like lambda expressions to make code mo

interface SootEvent { }
class SomeSootEvent implements SootEvent { ... }
class Foo {
PublishSubject<SootEvent> eventSubject = PublishSubject.create();
void modifyState() {
// ... modify some state ...
eventSubject.onNext(new SomeSootEvent(...));
}
fun main(args: Array<String>) {
println(fib().take(5).toList())
}
fun fib() = sequence<Int> {
yield(1)
yield(1)
var prev = 1
var prevPrev = 1
package de.maxisma.allaboutsamsung
import android.content.Intent
import android.support.design.widget.Snackbar
import android.support.v4.app.Fragment
import com.squareup.moshi.JsonDataException
import com.squareup.moshi.JsonEncodingException
import kotlinx.coroutines.experimental.CancellationException
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Job
@cbruegg
cbruegg / calccorr.kt
Created September 2, 2017 11:06
Plot cryptocurrency difficulty correlations (quick and dirty)
package diffchecker
import org.jsoup.Jsoup
import java.net.URL
import java.util.*
private val currencies = arrayOf("bitcoin", "xmr", "ltc", "eth", "etc", "dash")
private fun urlFor(currency: String) = "https://bitinfocharts.com/comparison/$currency-difficulty.html"
private val dataRegex = Regex("\\[new Date\\(\"([0-9/]*)\"\\),([0-9.E+]*)]")
package edu.brown.cs.paneclient;
import java.io.IOException;
import java.net.InetAddress;
public class PaneSample {
private static final String PANE_CONTROLLER_HOSTNAME = "localhost";
private static final int PANE_CONTROLLER_PORT = 9000;
private static final String PANE_USERNAME = "username";
import psutil
import time
import collections
###
### Simply pipe the output of this program into a file
### to obtain CSV formatted data about the CPU, memory,
### network and disk. Press CTRL-C to stop writing.
###
@cbruegg
cbruegg / KnuthMorrisPratt.kt
Last active October 27, 2016 19:53
An implementation of the Knuth-Morris-Pratt String matching algorithm in Kotlin.
/**
* For each i in [0, length), this function computes
* the length of the longest suffix of a substring of pattern from 0 to i
* that is also a prefix of the pattern itself.
*/
private fun computePrefixFunction(pattern: CharSequence): IntArray {
val resultTable = IntArray(pattern.length)
var matches = 0
for (i in 1..pattern.length - 1) {
Iteration 149
HashSkipNode{skipNode=SkipNode{running=true, id=2, bitstring='001000', neighbors=0:{[7, 10]}1:{[]}2:{[]}3:{[]}4:{[]}5:{[]}, internalMap={2=3, 4=5, 6=20}}
HashSkipNode{skipNode=SkipNode{running=true, id=7, bitstring='111010', neighbors=0:{[2, 10, 20]}1:{[10]}2:{[10]}3:{[]}4:{[]}5:{[]}, internalMap={8=4}}
HashSkipNode{skipNode=SkipNode{running=true, id=10, bitstring='110011', neighbors=0:{[2, 7]}1:{[7]}2:{[7]}3:{[]}4:{[]}5:{[]}, internalMap={1=2}}
HashSkipNode{skipNode=SkipNode{running=false, id=20, bitstring='001101', neighbors=0:{[2, 10]}1:{[2]}2:{[2]}3:{[2]}4:{[]}5:{[]}, internalMap={1=2}}
-----------------------------
Iteration 150
TEST: Join node 25 at node 2
HashSkipNode{skipNode=SkipNode{running=true, id=2, bitstring='001000', neighbors=0:{[7, 10]}1:{[]}2:{[]}3:{[]}4:{[]}5:{[]}, internalMap={2=3, 4=5, 6=20}}
HashSkipNode{skipNode=SkipNode{running=true, id=7, bitstring='111010', neighbors=0:{[2, 10, 20]}1:{[10]}2:{[10]}3:{[]}4:{[]}5:{[]}, internalMap={8=4}}