Skip to content

Instantly share code, notes, and snippets.

View yinchunxiang's full-sized avatar
💭
coding

yinchunxiang yinchunxiang

💭
coding
View GitHub Profile
@yinchunxiang
yinchunxiang / gist:5edb12b6a8d836d0075866ca7e6a3d71
Created April 14, 2020 07:14
{python} read from stdin and write to stdout
echo hallo | python -c "import sys;[sys.stdout.write(line) for line in sys.stdin]"
@yinchunxiang
yinchunxiang / Config.java
Last active June 20, 2017 11:25
java configuration
package com.sophon.search;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* Created by yinchunxiang on 05/06/2017.
*/
public class Config {
@yinchunxiang
yinchunxiang / chunked_request.go
Last active September 24, 2023 08:04
send chunked request by golang
package main
import (
"fmt"
"io"
"io/ioutil"
"net/url"
"github.com/benburkert/http"
//"net/http"
@yinchunxiang
yinchunxiang / chunked_request.py
Created February 8, 2017 11:22
send chunked http request by python
import httplib
import time
chunk1 = "custname=bob&custtel=11111&custemail=bob%40email.com&si"
chunk2 = "ze=medium&topping=bacon&delivery=11%3A00&comments=if+you%27re+late+we+get+it+free"
if __name__ == "__main__":
#conn = httplib.HTTPConnection('httpbin.org')
#conn = httplib.HTTPConnection('requestb.in')
conn = httplib.HTTPConnection('ros.roobo.net')
func trace() {
pc := make([]uintptr, 10) // at least 1 entry needed
runtime.Callers(2, pc)
f := runtime.FuncForPC(pc[0])
file, line := f.FileLine(pc[0])
fmt.Printf("%s:%d %s\n", file, line, f.Name())
}
map "ctrl+f" scrollFullPageDown
map "ctrl+b" scrollFullPageUp
@yinchunxiang
yinchunxiang / ThreadPool.cc
Created January 10, 2016 14:58
C++ ThreadPool
class ThreadPool {
public:
ThreadPool(int num_threads) : stop_(0) {
for (int i = 0; i < num_threads; ++i) {
threads_.push_back(std::thread(&ThreadPool::run, this));
}
}
void AddTask(const std::function<void()> &task) {
{
std::unique_lock<std::mutex> lock(mutex_);
@yinchunxiang
yinchunxiang / disable_allocation
Created July 23, 2014 13:17
让Elasticsearch集群不做数据迁移
curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.disable_allocation": true}}'
Can be used without specifying an index against one of the many built in analyzers:
curl -XGET 'localhost:9200/_analyze?analyzer=standard' -d 'this is a test'
Or by building a custom transient analyzer out of tokenizers, token filters and char filters. Token filters can use the shorter filters parameter name:
curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&filters=lowercase' -d 'this is a test'
curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&token_filters=lowercase&char_filters=html_strip' -d 'this is a <b>test</b>'
It can also run against a specific index:
# SELECT COUNT(*) from bank GROUP BY state ORDER BY COUNT(*) DESC
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state"
}