Skip to content

Instantly share code, notes, and snippets.

@smilingpoplar
smilingpoplar / string_util.cpp
Last active October 7, 2015 12:18
string with format
string stringWithFormat(const char *fmt, ...) {
int desiredLength= 1024;
string str;
str.resize(desiredLength);
va_list ap;
while (true) {
va_start(ap, fmt);
int printedLength= vsnprintf((char *)str.c_str(), str.size()+1, fmt, ap);
va_end(ap);
// '-1' means the buffer was too small.
@smilingpoplar
smilingpoplar / ddns
Created April 30, 2019 15:27
ddns for dnspod
#!/bin/sh
token='<dnspod_id>,<dnspod_token>'
domain='<your_domain>'
sub_domain='<your_subdomain>'
new_ip=${3:-$(curl -s 'https://api.ip.sb/geoip/' | sed 's/.*"ip":"\([0-9.]*\)".*/\1/')}
api_call() {
local param="login_token=${token}&format=json&domain=${domain}&${2}"
curl -s -k -XPOST -o- -A'shdns/0.1(php@html.js.cn)' -d $param https://dnsapi.cn/${1}
}
/* quantumultx remove xueqiu launch ad, using Charles to analyze network activities
[rewrite_local]
^https?://(101\.201\.175\.228|182\.92\.251\.113)\/brand\/search\/v1.json* url script-response-body https://gist.githubusercontent.com/smilingpoplar/ab74f2e176b91a0ca597b4222971f5a2/raw/xxxxx/xq_launch.js
[mitm]
hostname = 101.201.175.228, 182.92.251.113
*/
$done(JSON.stringify({"data":{},"result_code":0,"message":""}));
@smilingpoplar
smilingpoplar / go-test-many.sh
Last active June 23, 2022 12:58
modified version for mac
# from: https://gist.github.com/jonhoo/f686cacb4b9fe716d5aa
# `brew install findutils` first, for `gfind`
#
#!/bin/bash
#
# Script for running `go test` a bunch of times, in parallel, storing the test
# output as you go, and showing a nice status output telling you how you're
# doing.
#
# Normally, you should be able to execute this script with