Skip to content

Instantly share code, notes, and snippets.

View phlego's full-sized avatar
🏠
Working from home

Phuong Le phlego

🏠
Working from home
View GitHub Profile
@phlego
phlego / idea.properties
Created January 11, 2023 11:18
Fix frozen `Open File or Project` dialog
# Help > Edit Custom Properties...
ide.ui.new.file.chooser=true
@phlego
phlego / StateMachineMermaidGenerator.java
Created November 18, 2022 06:41
Generate Mermaid Diagram from Spring State Machine
package com.phl.statemachine;
import org.springframework.statemachine.StateMachine;
public class StateMachineMermaidGenerator {
public static <S, E> String generate(StateMachine<S, E> stateMachine) {
System.out.println("Generating mermaid 🧜\n");
StringBuilder mmBuilder = new StringBuilder();
@phlego
phlego / java.util.function.md
Last active March 27, 2022 12:17
Java Functional Interfaces Cheat Sheet
Supplier       ()     -> x
Consumer       x      -> ()
BiConsumer     x, y   -> ()
Callable       ()     -> x throws ex
Runnable       ()     -> ()
Function       x      -> y
BiFunction     x, y   -> z
Predicate x -&gt; boolean
function serializeCSS(cssProperties: CSSProperties | undefined): string {
if (!cssProperties) return '';
let cssString = '';
for (const [key, value] of Object.entries(cssProperties)) {
cssString += key.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) + ':' + value + ';';
}
return cssString;
}
@phlego
phlego / strictEquals.js
Last active August 7, 2020 12:53
Reinvent ===
/**
* Reinvent ===
* @ref [Equality comparisons and sameness](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)
* @ref [JavaScript Equality Table](https://dorey.github.io/JavaScript-Equality-Table/)
*/
export const strictEquals = (a, b) => {
if (typeof a == 'number' && typeof b == 'number') {
if (isNaN(a) && isNaN(b)) {
return false;
} else if ((Object.is(a, 0) && Object.is(b, -0)) || (Object.is(a, -0) && Object.is(b, 0))) {