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 / 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 / Properties.kt
Last active January 15, 2018 10:31 — forked from pardom-zz/Properties.kt
Kotlin observable properties
/**
** 为KProperty0添加一个扩展函数addObserver(),用来监听当值发生变化的时候刷新observer代码块
**/
fun <T> KProperty0<T>.addObserver(observer: (T) -> Unit) {
(getDelegate(this) as ObservableProperty<T>?)?.addObserver(observer)
}
private fun <T> getDelegate(kProperty: KProperty0<T>) : Any? {
val owner = (kProperty as PropertyReference).owner

Image source

https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png

Try resize it!

  • ![](https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png | width=100)
@xingstarx
xingstarx / default.java
Created August 25, 2017 14:04 — forked from binjoo/default.java
JAVA:清除HTML标签
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HTMLSpirit{
public static String delHTMLTag(String htmlStr){
String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
@xingstarx
xingstarx / MainActivity.java
Created August 14, 2017 13:35 — forked from nickbutcher/MainActivity.java
A quick sample of the new physics-based animation library added in Support Library 25.3.0 docs: https://developer.android.com/reference/android/support/animation/package-summary.html output: https://twitter.com/crafty/status/842055117323026432
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@xingstarx
xingstarx / JSONUtil.java
Created August 4, 2017 10:25 — forked from jjfiv/JSONUtil.java
JSON escaping and unescaping that really works, no dependencies.
// BSD License (http://lemurproject.org/galago-license)
package org.lemurproject.galago.utility.json;
public class JSONUtil {
public static String escape(String input) {
StringBuilder output = new StringBuilder();
for(int i=0; i<input.length(); i++) {
char ch = input.charAt(i);
int chx = (int) ch;