Skip to content

Instantly share code, notes, and snippets.

@hz2
hz2 / gitclone.sh
Created August 15, 2023 05:34
clone repo from gitlab
#!/bin/bash
# clone repo from gitlab
# 1. copy link form the website
# a = [...document.querySelectorAll('.projects-list>li h2 a')].map(x=>x.href).join('\n')
# copy(a)
# 2. save to repo.txt
# 3. run the shell
# set curent directory
export interface FormItem {
[k: string]: string | number | boolean;
}
export type NestFormItem =
& FormItem
& {
[k : string]: FormItem[];
};
@hz2
hz2 / genCommonClassName.less
Last active April 20, 2021 06:40
Generate class names like inline styles
@sizes: 0, 5, 8, 10, 15, 20, 25, 30, 45;
@sides: {
l: -left;
r: -right;
t: -top;
b: -bottom
}
@hz2
hz2 / genCommonClassName.scss
Last active April 20, 2021 07:15
Generate class names like inline styles
$sizes: (5, 8, 10, 15, 20, 25, 30, 45);
$sides: ("l": "-left", "r": "-right", "t": "-top", "b": "-bottom");
@each $size in $sizes {
.m#{$size} {
margin:#{$size}px;
}
@echo off
color 02
for %%I in (.) do title sync %%~nxI
:: set charset
git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
set LESSCHARSET=utf-8
@hz2
hz2 / downloadImage.js
Created May 27, 2020 08:28
downloadImage
fetch(url, { mode: "cors" })
.then(function(response) {
return response.blob();
})
.then(r => {
let file = new FileReader();
file.onload = function(e) {
let el = document.createElement("a");
el.setAttribute("href", e.target.result);
el.setAttribute("download", x.urlbase.split("=")[1] + ".jpg");
@hz2
hz2 / 1-line-code.js
Last active August 16, 2020 15:14
1-line-code-convert-color
// Convert hex color to RGBA color
// x => current item
// i => index
// o => origin value
const hex2rgba = h => h.replace('#','').split('').map((x,i,o)=>o.length< 6 ? [x,x]: x).flat().reduce((str,x,i,orig)=>i%2 ? str.replace("x", parseInt( orig[i-1]+ x , 16) ) + ([',',','].concat(orig.length < 7 ? [',1)']:[',',')']))[(i-1)/2] : str + 'x','rgba(')
// View Results
hex2rgba('#eeff00')
// > "rgba(238,255,0,1)"