Skip to content

Instantly share code, notes, and snippets.

Install for pantheon (elementary os):
1. sudo apt install fcitx fcitx-googlepinyin fcitx-mozc im-config
2. im-config -> select: fcitx
3. reboot
4. fcitx configure
@fbaierl
fbaierl / FirstMissingPositive
Last active August 14, 2018 09:34
first_missing_positive
/*
https://leetcode.com/problems/first-missing-positive/description/
Given an unsorted integer array, find the smallest missing positive integer.
Example 1:
Input: [1,2,0]
Output: 3
Example 2:
@fbaierl
fbaierl / NumberOfIslands.scala
Last active August 14, 2018 08:29
NumberOfIslands
/*
https://leetcode.com/problems/number-of-islands/description/
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Example 1:
Input:
11110
11010
/**
* A toggle switch with two labels. Modeled after: https://codemyui.com/toggle-switch-with-lables/
*/
object ToggleSwitchWithLabels {
private var toggled = true
def apply(labelOn: String, labelOff: String) = {
def onClick = {
println("on click: " + toggled)
toggled = !toggled
@fbaierl
fbaierl / Format
Created October 25, 2018 07:59
Scala.js string interpolation like java.text.MessageFormat
object Format {
/**
* String interpolation [[java.text.MessageFormat]] style:
* {{{
* format("{1} {0}", "world", "hello") // result: "hello world"
* format("{0} + {1} = {2}", 1, 2, "three") // result: "1 + 2 = three"
* format("{0} + {0} = {0}", 0) // throws MissingFormatArgumentException
* }}}
* @return
@fbaierl
fbaierl / I18n.java
Last active October 26, 2018 13:49
Java I18n wrapper for scaposer lib (Scala)
// dependencies:
// https://mvnrepository.com/artifact/tv.cntt/scaposer
// compile group: 'tv.cntt', name: 'scaposer_2.12', version: '1.11.0'
package internationalization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.collection.Seq;
import scala.util.Either;
import scaposer.ParseFailure;
@fbaierl
fbaierl / TarjanRecursive.scala
Last active January 31, 2021 21:19
Tarjan's algorithm for Scala
package tarjan
import scala.collection.mutable
// See python version: https://github.com/bwesterb/py-tarjan
/**
* Tarjan's algorithm is an algorithm in graph theory for finding the strongly connected components of a directed graph. It runs in linear time,
* matching the time bound for alternative methods including Kosaraju's algorithm and the path-based strong component algorithm.
*/
class TarjanRecursive {
@fbaierl
fbaierl / ForkMITLicensedProject.md
Created November 6, 2018 14:17
HOWTO fork a MIT licensed project

No, you are not allowed to change the copyright notice. Indeed, the license text states pretty clearly:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

But you are allowed to add a copyright notice.

If you want to keep the MIT license, which is what I would advise you to do, you only need to add a single line to the license file, before or after Copyright (c) 2012 Some Name with your own copyright notice. The final LICENSE file will look like this:

The MIT License (MIT)

@fbaierl
fbaierl / Puppeteer_todo.md
Last active November 8, 2018 13:14
Puppeteer Library TODOs

1. Trigger more than one recalc()

x ~~~> y z w

2. Trigger with condition

x ~~ onfyIf (() => false) ~~~> y

3. Execute before and after

x ~~ before { println("before") } after { println("after") } ~~~> y

4. Trigger multiple times