Skip to content

Instantly share code, notes, and snippets.

View Soontao's full-sized avatar
😊
I may be slow to respond.

Theo Sun Soontao

😊
I may be slow to respond.
View GitHub Profile
@Soontao
Soontao / kmp_search.py
Created October 22, 2019 01:45 — forked from m00nlight/gist:daa6786cc503fde12a77
Python KMP algorithm
class KMP:
def partial(self, pattern):
""" Calculate partial match table: String -> [Int]"""
ret = [0]
for i in range(1, len(pattern)):
j = ret[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = ret[j - 1]
ret.append(j + 1 if pattern[j] == pattern[i] else j)
const kmp_partial = (pattern = "") => {
const ret = [0]
for (let i = 1; i < pattern.length; i++) {
var j = ret[i - 1];
while (j > 0 && pattern[j] != pattern[i]) {
j = ret[j - 1]
@Soontao
Soontao / trimSuffix.groovy
Last active March 16, 2020 07:08
Groovy Trim Suffix Code
def trimSuffix(String original, String suffix) {
if(original.endsWith(suffix)) {
return original.substring(0, original.length() - suffix.length())
}
return original
}
println(trimSuffix("www.qq.com",".com")) // www.qq
println(trimSuffix("www.qq.com","")) // www.qq.com
println(trimSuffix("www.qq.com","abc")) // www.qq.com
package corp.sap.hana.datav.controllers.api.v1
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import corp.sap.hana.datav.repository.rate.ExchangeRateHistoryRepo
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/NodeTrainingConfiguration",
"definitions": {
"NodeTrainingConfiguration": {
"type": "object",
"additionalProperties": false,
"properties": {
"author": {
"type": "string"
@Soontao
Soontao / hana_metadata.sql
Created May 7, 2020 04:41
Query HANA database metadata
SELECT * FROM sys.schemas; -- select schemas
SELECT * FROM sys.tables; -- select tables
SELECT * FROM sys.table_columns; -- select columns of table
@Soontao
Soontao / check_java_crypto_max_key_len.js
Last active May 12, 2020 06:12
Check current jvm max supported key length of crypto algorithms
// run with jjs
print("crypt provider: " + javax.crypto.Cipher.getInstance("AES").getProvider());
var methods = ["AES","DES","RSA"];
for (var idx in methods) {
var method = methods[idx]
print(method + " key max length: " + javax.crypto.Cipher.getMaxAllowedKeyLength(method))
}
@Soontao
Soontao / jjs_aes_cipher_check.js
Last active May 12, 2020 09:13
AES Cipher Check
// please run with jjs
var Cipher = javax.crypto.Cipher;
var KeyGenerator = javax.crypto.KeyGenerator;
var String = java.lang.String;
var Arrays = java.util.Arrays;
var SecureRandom = java.security.SecureRandom;
var SecretKeySpec = javax.crypto.spec.SecretKeySpec;
var share_secret_seed = "share_secret_seed";
@Soontao
Soontao / weibo_search.js
Created May 13, 2020 05:24
Search Content on Weibo
const fetch = require("node-fetch")
const { flatten, range } = require("lodash")
const { URLSearchParams } = require("url")
const weibo_search = async (text, page = 1) => {
const query = new URLSearchParams();
query.append("containerid", `100103type=61&q=${text}&t=0`)
query.append("page_type", "searchall")
query.append("page", `${page}`)
@Soontao
Soontao / cpi_log_file.groovy
Created May 19, 2020 04:10
CPI Log Content
MessageLog ml = messageLogFactory.getMessageLog(m)
ml.addAttachmentAsString(
"aiib_acc_content.csv",
content,
"plain/text"
);