Skip to content

Instantly share code, notes, and snippets.

@daniellowtw
daniellowtw / index.md
Created June 12, 2019 18:48
Try finally java

Finally

The finally clause is generally used to clean up after the code in the try clause (e.g., close files and shut down network connections). The finally clause is useful because it is guaranteed to be executed if any portion of the try block is executed, regardless of how the code in the try block completes. In fact, the only way a try clause can exit without allowing the finally clause to be executed is by invoking the System.exit() method, which causes the Java interpreter to stop running.

In the normal case, control reaches the end of the try block and then proceeds to the finally block, which performs any necessary cleanup. If control leaves the try block because of a return, continue, or break statement, the finally block is executed before control transfers to its new destination.

If an exception occurs in the try block and there is an associated catch block to handle the exception, control transfers first to the catch block and then to the finally block. If there is

@daniellowtw
daniellowtw / RearrangingLinkedList.scala
Created August 1, 2018 07:45
Ordering xml attributes/Reordering linked list
import scala.annotation.tailrec
import scala.xml.{Elem, MetaData, Null}
object OrderedAttr {
def main(args: Array[String]): Unit = {
val content: Elem = <something b="blah" c="today" a="321"></something>
val attr = content.attributes
println(attr.moveToFront("d")) // b="blah" c="today" a="321"
println(attr.moveToFront("a")) // a="321" b="blah" c="today"
println(attr.moveToFront("c").moveToFront("a")) // a="321" c="today" b="blah"
@daniellowtw
daniellowtw / timeformat.md
Last active January 8, 2023 08:05
Time format
format e.g
dd/MMM/yyyy:HH:mm:ss ZZZZ 19/Apr/2010:06:36:15 -0700
dd/MMM/yyyy HH:mm:ss 09/Mar/2004 22:02:40 08691
MMM dd, yyyy hh:mm:ss a Dec 2, 2010 2:39:58 AM
MMM dd yyyy HH:mm:ss Jun 09 2011 15:28:14
MMM dd HH:mm:ss yyyy Apr 20 00:00:35 2010
MMM dd HH:mm:ss ZZZZ yyyy Feb 07 15:22:31 -0700 2016
MMM dd HH:mm:ss ZZZZ Sep 28 19:00:00 +0000
MMM dd HH:mm:ss Mar 16 08:12:04
@daniellowtw
daniellowtw / tmux-cheatsheet.markdown
Created April 11, 2018 21:09 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
// Easier to just refer than to programatically retrieve it
Scala> ZoneId.getAvailableZoneIds.toArray(Array[String]()).sorted.foreach(println)
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@daniellowtw
daniellowtw / main.go
Created March 28, 2017 12:39
lazy-typechecking
package main
type A interface {
Bar() int
}
type AMaker func() A
type AImpl struct{}
@daniellowtw
daniellowtw / fn.js
Created May 21, 2016 23:15
Extract javascript function name and body
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /,/;
var FN_ARG = /^\s*(_?)(.+?)\1\s*$/;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
// annotate returns arguments and body, that can be passed into Function
function annotate(fn) {
var res,
fnText,
argDecl
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestName(t *testing.T) {
err := f()
assert.Error(t, err)
// Inside inner/inner.go
package inner
type A interface {
foo() string
}
type B interface {
Bar() string