Skip to content

Instantly share code, notes, and snippets.

View hjhjw1991's full-sized avatar
🛴

hjhjw1991 hjhjw1991

🛴
View GitHub Profile
@hjhjw1991
hjhjw1991 / HJGradientAlphaImageView.kt
Last active July 19, 2023 06:54
透明度渐变、线性渐变的 ImageView
package com.huangjun.barney.views
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import kotlin.math.max
import kotlin.math.min
/**
package com.hjhjw1991
/**
* 带参数单例实现, 可复用
* 定义
* class ToSingle(arg: Any){
* companion object: SingletonHolder<ToSingle, Any> ({arg -> doInit(arg)})
* }
* 使用
* ToSingle.getInstance(arg).xxx
@hjhjw1991
hjhjw1991 / MethodProxy.kt
Created June 15, 2020 08:36 — forked from crowjdh/MethodProxy.kt
Method proxy for Kotlin(verification necessary)
inline fun <reified T : Record> T.proxy(): T {
return Proxy.newProxyInstance(javaClass.classLoader,
arrayOf(Record::class.java),
RecordInvocationHandler(this)) as T
}
class RecordInvocationHandler<T: Record>(private val caller: T) : InvocationHandler {
override fun invoke(proxy: Any, method: Method, args: Array<Any>): Any? {
var result: Any? = null
#!/bin/zsh
ifconfig | sed -n -e '/127.0.0.1/d' -e '/inet /p' | awk '{print $2}'
[user]
name = ${username}
email = ${email}
[filter "lfs"]
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
[alias]
co = checkout
@hjhjw1991
hjhjw1991 / execAt.py
Created April 14, 2017 04:11
execute any method at a specific directory
def execAt(targetdir):
"""
execute the decorated method at specified directory
"""
def wrapper(method):
import os
def func(*args, **kvargs):
old = os.getcwd()
os.chdir(os.path.abspath(targetdir))
ret = method(*args, **kvargs)
@hjhjw1991
hjhjw1991 / uppertolower.bat
Created August 27, 2016 04:33
change upper name to lower one on Windows platforms
@echo off
title 更改文件名大写为小写
::放在目标文件夹下执行
set dir=%~dp0&call:cdto
for /f "delims=" %%i in ('dir/s/b/ad') do set dir=%%i&call:cdto
pause
exit/b
:cdto
cd /d %dir%
for /f "delims=" %%i in ('dir/b/a-d/l') do ren "%%i" "%%i"
@hjhjw1991
hjhjw1991 / .bash_aliases
Created August 1, 2016 01:45
bash aliases for ubuntu
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(d ircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
@hjhjw1991
hjhjw1991 / .vimrc
Last active December 7, 2017 07:48
config your own vim
set number
" set <F5> to compile and run c/cpp/java/python/shell
" map <f5> :call CompileRunGcc()<cr>
" func! CompileRunGcc()
" exec "w"
" exec "!gcc % -o %<"
" exec "! ./%<"
" endfunc
" set <F5> to run javac and java
@hjhjw1991
hjhjw1991 / .inputrc
Last active August 28, 2018 02:14
let completion ignore case and search command by leading string
# user defined inputrc
find_git_branch () {
local dir=. head
git_branch=''
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head = ref:\ refs/heads/* ]]; then
git_branch=" (${head#*/*/})"