Skip to content

Instantly share code, notes, and snippets.

View pramoth's full-sized avatar

Pramoth Suwanpech pramoth

View GitHub Profile
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<!-- maven-compiler-plugin defaults to targeting Java 5, but our javac
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
package th.co.geniustree.demo;
import org.junit.Test;
public class OptionalTest {
@Test
public void no_optional() {
Home home = findHomeFromSomeWhere();
//print cc. of a car in my home
if (home != null) {
export class AppComponent implements OnDestroy {
private _onDestroy = new Subject<void>();
constructor(@Inject(DOCUMENT) document: any) {
fromEvent(document, 'mousedown').pipe(takeUntil(this._onDestroy))
.subscribe(() => { /*...*/ }));
fromEvent(document, 'mouseup').pipe(takeUntil(this._onDestroy))
.subscribe(() => { /*...*/ }));
import { Component, OnInit, OnDestroy } from '@angular/core';
import { MyServiceService } from '../my-service.service';
//import from gt-unsubscribe-on-detroy
import { unsubscribeOnDetroy } from 'gt-unsubscribe-on-detroy';
@Component({
selector: 'app-b',
templateUrl: './b.component.html',
styleUrls: ['./b.component.css']
})
LocalDate expectDate = LocalDate.of(2018,9,10);
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ofPattern("[yyyy M d]"))
.append(DateTimeFormatter.ofPattern("[d M yyyy]"))
.append(DateTimeFormatter.ofPattern("[d.M.yyyy]"))
.append(DateTimeFormatter.ofPattern("[d/M/yyyy]"))
.toFormatter();
assertThat(LocalDate.parse("2018 09 10",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10 9 2018",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10.09.2018",dateTimeFormatter)).isEqualTo(expectDate);
LocalDate expectDate = LocalDate.of(2018,9,10);
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
.appendOptional(DateTimeFormatter.ofPattern("yyyy M d"))
.appendOptional(DateTimeFormatter.ofPattern("d M yyyy"))
.appendOptional(DateTimeFormatter.ofPattern("d.M.yyyy"))
.appendOptional(DateTimeFormatter.ofPattern("d/M/yyyy"))
.toFormatter();
assertThat(LocalDate.parse("2018 09 10",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10 9 2018",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10.09.2018",dateTimeFormatter)).isEqualTo(expectDate);
export class Stack<T> {
items: T[] = []
index = 0
push(value: T) {
this.items[this.index++] = value
}
pop(): T {
return this.items[--this.index]
import {StackFrame} from "./stack-frame";
export class Opcode {
//code for part3
static ISTORE_1 = (satckFrame: StackFrame): void => {
satckFrame.localVariables[1] = satckFrame.operandStack.pop()
satckFrame.pc++
}
static ILOAD_1 = (satckFrame: StackFrame): void => {
satckFrame.operandStack.push(satckFrame.localVariables[1])
export class Thread {
...
constructor() {
let bytecode = [
Opcode.ICONST_0,
Opcode.ISTORE_1,
Opcode.ILOAD_1,
Opcode.BIPUSH,
10,
Opcode.IF_ICMPGE,