Skip to content

Instantly share code, notes, and snippets.

@xingstarx
xingstarx / ReflectionUtils.java
Created September 5, 2018 08:30
ReflectionUtils反射工具类,包含java和kotlin版本
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* 方法类
* @author syh
*
*/
@xingstarx
xingstarx / xmlToJson.js
Created September 7, 2023 02:39 — forked from chinchang/xmlToJson.js
Function to convert XML to JSON
/**
* Changes XML to JSON
* Modified version from here: http://davidwalsh.name/convert-xml-json
* @param {string} xml XML DOM tree
*/
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) {
@xingstarx
xingstarx / nonebot_zhipuai.py
Created July 26, 2023 06:22 — forked from hzhangxyz/nonebot_zhipuai.py
nonebot_zhipuai_bot
from nonebot.adapters import Event, Message
from nonebot.params import EventPlainText, CommandArg
from nonebot.plugin.on import on_message, on_command
from nonebot.adapters.onebot.v11.message import MessageSegment
import os
import ast
import json
import shelve
import aiohttp
@xingstarx
xingstarx / MapDeserializerDoubleAsIntFix.java
Last active March 21, 2022 02:21
处理Gson中,json转换map造成的int变double的问题
/**
*最近在研究网络请求数据解析的问题,发现json数据被强制转换为map结构的时候,会出现int变成double的问题
*在stackoverflow上看到了一个这个How can I prevent gson from converting integers to doubles 的问题,采用了这个答案
*https://stackoverflow.com/a/36529534/5279354答案
*/
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
@xingstarx
xingstarx / Android: get CountryCode from TelephonyManager
Last active October 5, 2020 03:34 — forked from rinav/Android: get CountryCode from TelephonyManager
Android: Get CountryCode and Locale from TelephonyManager
public static int getCurrentCountryCode(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String countryIso = telephonyManager.getSimCountryIso().toUpperCase();
return PhoneNumberUtil.getInstance().getCountryCodeForRegion(countryIso);
}
PhoneNumberUtil 引用自
compile 'com.googlecode.libphonenumber:libphonenumber:8.3.1'
//语言和编码
<?php language_attributes(); ?> //语言属性
//根据不同情况来读取 title
<?php
global $page, $pages;
wp_title( '|', true, 'right'); //在标题的左方或右方
bloginfo( 'name' ); //博客的名称
$site_description = get_bloginfo( 'description', 'Display' ); //博客的描述
if( $site_description && ( is_home() || is_front_page() ) ) //如果是首页,则输出博客名称和描述
@xingstarx
xingstarx / Default Taxonomy Term for CPT
Created May 1, 2019 10:02 — forked from mayeenulislam/Default Taxonomy Term for CPT
Make Default taxonomy term for Custom Post Type - WordPress
/**
* Author: Michael Fields
* Source: http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/
* Thanks a lot for the nice tweak
*/
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
@xingstarx
xingstarx / custom-mysql-config.cnf
Created August 13, 2018 03:36
docker下启动MySQL,解决内存占用过大的问题
[mysqld]
# /etc/my.cnf
performance_schema = 0
innodb_buffer_pool_size=5M
innodb_log_buffer_size=256K
query_cache_size=0
max_connections=10
key_buffer_size=8
thread_cache_size=0
host_cache_size=0
@xingstarx
xingstarx / CopyBytes.kt
Created June 15, 2018 10:00 — forked from Nikaoto/CopyBytes.kt
A method that copies data from input to output (in Kotlin and Java)
//A Kotlin object (singleton) that handles the copying with mulitple different arguments
object CopyBytes {
@Throws(IOException::class)
fun copy(input: InputStream, output: OutputStream) {
//Creating byte array
val buffer = ByteArray(1024)
var length = input.read(buffer)
//Transferring data
@xingstarx
xingstarx / OkHttpUtils.java
Created June 3, 2018 10:36
使用Retrofit OkHTTP不校验https自签名证书(全部不校验)
// copy from https://stackoverflow.com/a/49063199/5279354
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(YOUR_BASE_URL)
.client(getUnsafeOkHttpClient().build())
.build();
public static OkHttpClient.Builder getUnsafeOkHttpClient() {
try {