Skip to content

Instantly share code, notes, and snippets.

@justforuse
justforuse / animation.js
Created February 13, 2024 15:15
Animation js
// refer: https://github.com/antfu/plum-demo/blob/main/src/App.vue
function frame() {
const tasks: Function[] = []
pendingTasks = pendingTasks.filter((i) => {
if (Math.random() > 0.4) {
tasks.push(i)
return false
}
return true
})
@justforuse
justforuse / safeAwait.js
Last active November 27, 2023 05:45
safe await
export function safeAwait(promise, finallyFunc) {
return promise.then(data => {
return [ undefined, data ]
}).catch(error => {
return [ error, undefined ]
})
}
@justforuse
justforuse / nanika.zsh-theme
Created August 23, 2022 10:28
A theme for oh my zsh. (extends from robbyrussell)
PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info) ⌚ %{$fg_bold[magenta]%}%*%{$reset_color%}
%(?:%{$fg_bold[green]%}$ :%{$fg_bold[red]%}$ )'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[yellow]%})"
@justforuse
justforuse / .zshrc
Last active December 5, 2023 09:59
Alias for oh my zsh
alias ni="npm install"
alias ns="npm run serve"
alias nd="npm run dev"
alias nt="npm run test"
alias nb="npm run build"
alias rnm="rm -rf ./node_modules"
alias nvp="npm version patch"
alias nvm="npm version minor"
alias nvma="npm version major"
@justforuse
justforuse / .prettierrc.js
Created December 20, 2021 14:20
Prettier configuration
module.exports = {
// Default: 80
printWidth: 120,
// Default: 2
tabWidth: 4,
// Default: false
useTabs: false,
// Default: true
semi: true,
// Default: false
@justforuse
justforuse / shutdown.bat
Created November 15, 2021 14:29
Shutdown your windows computer by .bat file
shutdown -s -t 5
@justforuse
justforuse / lock.bat
Created November 15, 2021 14:27
Lock your windows computer by .bat file
rundll32.exe user32.dll LockWorkStation
@justforuse
justforuse / promise-limit-all.js
Last active September 8, 2021 14:22
Promise async pool with limit
Promise.limitAll = function(promises, limit) {
return new Promise(resolve => {
let resolvedCount = 0;
let count = 0;
let res = [];
const len = promises.length;
function next(p, index) {
p().then(r => {
res[index] = r;
@justforuse
justforuse / main.js
Created May 25, 2021 09:04
Detect whether element scroll to the end
function detectWhetherElementScrollToEnd(element) {
const { scrollLeft, scrollTop, offsetWidth, offsetHeight, scrollWidth, scrollHeight } = element;
if (scrollTop === 0) {
return 'scroll to top';
}
if (scrollTop + offsetHeight >= scrollHeight) {
return 'scroll to end';
}
if (scrollLeft === 0) {
return 'scroll to left';
@justforuse
justforuse / .gitconfig
Created May 24, 2021 09:09
Git global alias config
[user]
name = xxxx
email = xxxx@example.com
[alias]
co = checkout
st = status
ci = commit
br = branch
ps = push
pl = pull