Skip to content

Instantly share code, notes, and snippets.

View hastebrot's full-sized avatar

Benjamin Gudehus hastebrot

  • Freiheit.com
  • Hamburg, Germany
  • 07:01 (UTC +01:00)
View GitHub Profile

Mini Guide: Verbs for Method Names

  • Attribute: get set is has can
  • Daten: add insert put remove delete replace purge prune move view write read

  • Objekte erstellen: generate create make build assemble evoke produce construct
  • Objekte vorbereiten: initiate configure prepare provide install require publish enable establish
  • Objekte zerstören: cleanup destroy dispose release discard abort revoke
#!/bin/bash
# FILE: record-gif.sh
# DEPS: sudo apt install byzanz gifsicle
# SOURCE: http://askubuntu.com/questions/107726/how-to-create-animated-gif-images-of-a-screencast
# delay in seconds before recording (defaults to 2s).
DELAY=2
# duration in seconds of recording (defaults to 10s).
@hastebrot
hastebrot / MonadicNullSafety.kt
Created January 13, 2017 07:12 — forked from janojanahan/MonadicNullSafety.kt
Kotlin Nullable can behave like a monad
/**
* A Gist proving that Kotlin's nullable type can be made into a monad without wrapping into another
* object and satisfy the Monadic laws
*
* Kotlin has comprehensive null safety built into the language enforced at compile time, using its
* nullable type.
*
* Its language structure makes dealing with nullable values simple and succinct. Unlike other language
* monadic constructs such as Option (scala), Optional(Java8+) and Maybe(Haskell), it is enforced at
* compile time and is compatible with existing non monad aware API (for example,
@hastebrot
hastebrot / tmux.conf
Created January 7, 2017 12:51 — forked from spicycode/tmux.conf
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@hastebrot
hastebrot / fp.py
Last active December 17, 2016 17:23
# side effects, mutable object, impure functions
sprites = ["inky", "blinky", "pinky", "clyde"]
print(sprites)
print(sprites.append("pacman"))
print(sprites)
print(sprites + ["pacman"])
print(sprites)
@hastebrot
hastebrot / partition.md
Last active April 12, 2022 10:22
Algorithm: Fixed and Sliding Windows in Kotlin
  • partitionRanges.kt: partition() implements a function for fixed and sliding windows suited for lists (not sequences) using indices/ranges.

  • partitionRecursion.kt: partitionRec() and partitionTailrec() implement such functions suited for lists using recursion and tail recursion (very inefficient). The concatenation of a lot of sequences using .plus() (or .flatten()) results in a StackOverflowException.

  • partitionIterator.kt: batch() and slide() implement such functions suited for lists and sequences (similar to the prototype implementation). Small "problem" here is that source.iterator() introduces mutual state. Does not use RingBuffer or LinkedList, instead replaces the whole List.

  • partitionZipDrop.kt: A sliding window for pairs with an offset of one, can be implemented ad hoc with this simple variant which uses zip(). This however does not work with sequenceOf(...).constrainOnce():

@hastebrot
hastebrot / Permutations.kt
Created July 1, 2016 20:12 — forked from voddan/Permutations.kt
code for "A handful of Kotlin permutations"
package permutations
import java.util.*
interface Circular<T> : Iterable<T> {
fun state(): T
fun inc()
fun isZero(): Boolean // `true` in exactly one state
fun hasNext(): Boolean // `false` if the next state `isZero()`
package es4j.example
//compile "com.eventsourcing:eventsourcing-core:0.4.0-SNAPSHOT"
//compile "com.eventsourcing:eventsourcing-inmem:0.4.0-SNAPSHOT"
//compile "com.eventsourcing:eventsourcing-h2:0.4.0-SNAPSHOT"
import com.eventsourcing.Event
import com.eventsourcing.Model
import com.eventsourcing.Repository
import com.eventsourcing.StandardCommand
@hastebrot
hastebrot / MathExtensions.kt
Created June 24, 2016 16:36 — forked from MichaelRocks/MathExtensions.kt
Math extension functions and float-math functions for Kotlin
/*
* Copyright 2015 Michael Rozumyanskiy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software