Skip to content

Instantly share code, notes, and snippets.

@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 / 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
*
//语言和编码
<?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 / 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 / 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 {
@xingstarx
xingstarx / dotted.xml
Created May 17, 2018 10:31
使用布局创建一个虚线view
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#C7B299"
android:dashWidth="10px"
android:dashGap="10px"
android:width="1dp"/>
</shape>
@xingstarx
xingstarx / NetWorkUtils.java
Created May 10, 2018 08:21
NetWorkUtils 获取客户端真实ip
public class NetWorkUtils {
public static String getIPAddress(boolean useIPv4) {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface intf : interfaces) {
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
for (InetAddress addr : addrs) {
if (!addr.isLoopbackAddress()) {
String sAddr = addr.getHostAddress();
//boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
boolean isIPv4 = sAddr.indexOf(':')<0;