Skip to content

Instantly share code, notes, and snippets.

@l0co
l0co / template.sh
Last active September 17, 2020 10:39
Bash script with arguments template
#!/bin/bash
CWD=`pwd`
SCRIPT_PATH=`readlink -f "$0"`
SCRIPT_DIR=`dirname "$SCRIPT_PATH"`
cd "$SCRIPT_DIR"
# parse options
QUIET=false
OPT_C=false
@l0co
l0co / cors-test.html
Created April 23, 2020 10:40
Simple script to test if CORS works from the browser
<script>
for (let method of ['GET', 'POST']) {
fetch('http://example.com', {method}).then(e => {
document.write('<p>' + method + ' succeded with result: ' + e + '</p>')
console.log(e)
}).catch(e => {
document.write('<p>' + method + ' failed due to: ' + e + '</p>')
});
}
@l0co
l0co / card-dialog.component.html
Last active March 5, 2020 15:27
Angular material dialog component.
<div class="mat-card-dialog">
<h2 mat-dialog-title class="mat-card-dialog-title" *ngIf="title">{{title}}</h2>
<mat-icon mat-dialog-close class="mat-card-dialog-close pointer">close</mat-icon>
<ng-content></ng-content>
</div>
@l0co
l0co / custom-component.directive.ts
Created March 4, 2020 16:22
Angular 9 custom component directive
import {ComponentFactoryResolver, ComponentRef, Directive, Type, ViewContainerRef} from '@angular/core';
/**
* Allows to embed custom components into views.
*
* ## Usage in template
*
* ```html
* <ng-template appCustomComponent></ng-template>
* ```
@l0co
l0co / JavaConstructor.java
Created August 20, 2019 08:13
Java constructor calling rules
class JavaConstrcutor {
public static class A {
public A() {
System.out.println("A");
}
public A(String message) {
System.out.println("A:"+message);
}
@l0co
l0co / behavior-subject-test.ts
Created July 10, 2019 14:54
RxJs BehaviorSubject used as the pipe in TypeScirpt
let subject = new BehaviorSubject<string>('0');
subject.subscribe(it => console.log('@@@@@@@@@@@@', 'A', it));
console.log('@@@@@@@@@@@@', 'emit', '1');
subject.next('1');
subject.subscribe(it => console.log('@@@@@@@@@@@@', 'B', it));
console.log('@@@@@@@@@@@@', 'emit', '2');
subject.next('2');
subject.subscribe(it => console.log('@@@@@@@@@@@@', 'C', it));
// @@@@@@@@@@@@ A 0
@l0co
l0co / Java8DataTimeCheatSheet.java
Created June 7, 2019 11:59
Cheatsheet of using Java 8 date time
/**
* Here is the jdk8 datetime cheatsheet and explanation why we use ZonedDateTime and Instant in TimeService.
*/
// this is the 01.03.2016 00:00 in server timezone (Europe/Warsaw) == EXACTLY THE SAME AS THE SYSTEM TIME
ZonedDateTime zonedDateTime = ZonedDateTime.of(2016, 3, 1, 0, 0, 0, 0, ZoneId.systemDefault());
System.out.println(zonedDateTime); // 2016-03-01T00:00+01:00[Europe/Warsaw]
// this is the same 01.03.2016 00:00 but doesn't carry timezone information
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
abstract class BaseProcessTest {
fun startProcess(variables: Map<String, Any> = mapOf()): ProcessAssertions {
logger.debug("Starting process: ${processName()}")
val processTestEnvironment = ProcessTestEnvironment()
runtimeService.addEventListener(processTestEnvironment)
try {
runtimeService.startProcessInstanceByKey(processName(), variables)
class ProcessAssertions(protected val processTestEnvironment: ProcessTestEnvironment) {
/**
* Checks whether the process variable is set
**/
fun assertVariable(name: String, value: Any) {
assertThat((processTestEnvironment.processInstance as VariableScopeImpl).getVariable(name)).isEqualTo(value)
}
/**
class ProcessTestEnvironment: EventLogger(DefaultClockImpl(), ObjectMapper()) {
var processInstance: ProcessInstance? = null
var exception: Throwable? = null // [1] the exception thrown by the process, if any
set(value) {
logger.debug("Exception thrown", value)
field = value
}
val events: List<Map<String, Any>> = mutableListOf()