Skip to content

Instantly share code, notes, and snippets.

@xmaihh
xmaihh / ByteArray.kt
Created Jun 30, 2020 — forked from fabiomsr/ByteArray.kt
ByteArray and String extension to add hexadecimal methods in Kotlin
View ByteArray.kt
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])
@xmaihh
xmaihh / SendEmailUtils.md
Last active Jul 23, 2019
Java邮件发送程序
View SendEmailUtils.md
public class SendEmailUtils {

    /**
     * 邮件发送程序
     *
     *           接收邮件的address
     * @param subject
     *            邮件主题
     * @param content
View 中国节气计算.md
/**
 * 节气计算类
 */
public final class SolarTerm {
    // 提供定位的年份
    private static final int baseYear = 1901;

    /**
     * 计算公历年当月的中气,公历月从0起始!
View git常用操作.md

git设置和取消代理

git config --global https.proxy http://127.0.0.1:1080

git config --global https.proxy https://127.0.0.1:1080

git config --global --unset http.proxy

git config --global --unset https.proxy
View QRCodeUtil.java
package xmaihh.pay.zxing;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PointF;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
@xmaihh
xmaihh / fake-useragent.md
Last active Nov 2, 2018
python之构造随机请求头
View fake-useragent.md

Installation

pip install fake-useragent

Usage

from fake_useragent import UserAgent
ua = UserAgent()

ua.ie
View Java-base64util.md

Android中ImageView加载Base64图片其实非常简单,并不需要引入第三方库,方法如下:

import android.util.Base64;

代码片段

String base64 = "data:image/png;base64, x.xx.x.xx..."
byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);
@xmaihh
xmaihh / keyboardheightobserver.md
Last active Nov 2, 2018
监听布局的变化来计算输入法的高度
View keyboardheightobserver.md

监听布局的变化来计算输入法的高度,这种方式在Activity的配置中配置为"android:windowSoftInputMode="adjustResize""时没有问题,可以正确获取输入法的高度,因为布局此时确实会动态的调整。 但是当Activity配置为"android:windowSoftInputMode="adjustNothing""时,布局不会在输入法弹出时进行调整

KeyboardHeightObserver.java

/**
 * The observer that will be notified when the height of 
 * the keyboard has changed
 */
public interface KeyboardHeightObserver {