Skip to content

Instantly share code, notes, and snippets.

View nomyfan's full-sized avatar
🍵
得閑飲茶

Kim Chan nomyfan

🍵
得閑飲茶
View GitHub Profile
@nomyfan
nomyfan / ConfigLoader.kt
Last active March 28, 2020 14:37
Spring Boot config loader
package com.example.conf
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import org.slf4j.LoggerFactory
import java.io.FileOutputStream
import java.lang.reflect.UndeclaredThrowableException
import java.nio.ByteBuffer
import java.nio.file.Paths
import java.time.Duration
@nomyfan
nomyfan / main.rs
Created March 23, 2020 14:50
WSL Broker
use std::io::Write;
use std::path::Path;
use std::process::Command;
fn main() {
let args: std::vec::Vec<String> = std::env::args().collect();
let bin_name = Path::new(&args[0]).file_stem().unwrap();
let mut cmd = Command::new("wsl");
@nomyfan
nomyfan / js_zip.js
Created May 16, 2020 14:02
JS zip iteration adapter
Array.prototype.zip = function(ano) {
return [...Array(Math.min(this.length, ano.length))].map((_, i) => [this[i], ano[i]]);
}
@nomyfan
nomyfan / zshrc.sh
Last active January 9, 2022 04:16
Exclude Windows env variables in WSL
export PATH=$(echo $PATH | tr ':' '\n' | grep -v '/mnt' | tr '\n' ':' | head -c-1)
# Then we can include any env variable we want, vscode for example
# export PATH=$PATH:'/mnt/c/Users/[username]/AppData/Local/Programs/Microsoft VS Code/bin'
@nomyfan
nomyfan / window.opener.sessionStorage.js
Created July 28, 2020 16:37
Read session storage value from another tab that is the opener
function getSessionItem(key, remove) {
if (!key) {
throw new Error(`invalid key: ${key}`);
}
if (remove === undefined) {
remove = true;
}
let o = window.sessionStorage.getItem(key);
if (!o && window.opener) {
o = window.opener.sessionStorage.getItem(key);
@nomyfan
nomyfan / example.vue
Created August 3, 2020 13:52
Combine async_validator with @hapi/joi
<el-form :model="formModel" :rules="rules" ref="form">
<el-form-item label="活动名" prop="activity_title">
<el-input v-model="formModel.activity_title" />
</el-form-item>
</el-form>
import Joi from "@hapi/joi";
import { validator } from "./validator.js";
export default {
@nomyfan
nomyfan / tab_indicator_transition.html
Last active November 9, 2020 15:52
Tab indicator with transition
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TagIndicator</title>
<style>
ul > li {
list-style: none;
display: inline-block;
padding: 5px 8px;
@nomyfan
nomyfan / spawn_validator_for_elform.ts
Last active November 9, 2020 16:01
spawn validator for ElForm
export function spawn<T>(
isValid: (value: T) => boolean,
msg: string,
options?: any,
) {
return {
required: true,
trigger: "blur",
...options,
validator: (_: any, val: T, callback: Function) => {
@nomyfan
nomyfan / sticky_overlap_title.html
Created December 13, 2020 14:44
Sticky overlap title example
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sticky overlap title example</title>
<style>
.sticky-title {
position: sticky;
top: 2em;
color: goldenrod;
@nomyfan
nomyfan / rotate-animation-play-state-polyfill.tsx
Last active December 22, 2020 15:26
Polyfill for toggling animation-play-state for iOS 11.0.3(maybe other versions or platforms also have this issue) when using rotate transform
import logo from "./logo.svg";
import "./App.css";
import { useEffect } from "react";
let prevTimestamp: null | number = null;
let duration = 0;
let animationID = -1;
function rotateLogo(timestamp: number) {
if (prevTimestamp === null) {