Skip to content

Instantly share code, notes, and snippets.

@wjx0912
wjx0912 / golang_split_string.go
Created May 2, 2018 12:27
golang split string
https://medium.com/@mlowicki/strings-fieldsfunc-vs-strings-split-96c667912f78
fmt.Printf("%#v\n", strings.Split("/a/b/c", "/"))
// []string{"", "a", "b", "c"}
fmt.Printf("%#v\n", strings.FieldsFunc("/a/b/c", func(c rune) bool { return c == ‘/’ }))
// []string{"a", "b", "c"}
@wjx0912
wjx0912 / find_error.go
Last active April 24, 2018 07:35
why not output?
package main
import (
"bytes"
"fmt"
"os/exec"
"time"
)
func main() {
@wjx0912
wjx0912 / nodejs_client_test.js
Created April 17, 2018 07:20
node.js client test
var net = require('net');
var port = 9922;
var host = '192.168.7.160';
var client= new net.Socket();
//创建socket客户端
client.setEncoding('binary');
//连接到服务端
client.connect(port,host,function(){
client.write('hello server');
@wjx0912
wjx0912 / boost_split_demo.cpp
Last active May 18, 2018 03:33
boost split demo
std::string src = " aa |b \t ccc[gg] ";
std::vector<std::string> list;
boost::split(list, std::string(src), boost::is_any_of(" \t,;\r\n|[]"), boost::token_compress_on);
if (list.size() <= 0)
return;
@wjx0912
wjx0912 / golang_timer_demo.go
Created April 11, 2018 13:35
golang: three way use timer
// (A)
time.AfterFunc(5 * time.Minute, func() {
fmt.Printf("expired")
}
// (B) create a Timer object
timer := time.NewTimer(5 * time.Minute)
<-timer.C
fmt.Printf("expired")
@wjx0912
wjx0912 / hello.cpp
Created April 8, 2018 03:16
hello world example: c++ language
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello, world." << endl;
return 0;
}
@wjx0912
wjx0912 / hello.c
Created April 8, 2018 03:16
hello world example: c language
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
printf("Hello world!\n");
return 0;
}
@wjx0912
wjx0912 / depolyment.yml
Created April 4, 2018 01:36
kubernetes service demo
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: httpd
spec:
replicas: 3
template:
metadata:
labels:
app: httpd
@wjx0912
wjx0912 / kubernetes_test_cronjob.yml
Created April 3, 2018 14:55
kubernetes test cronjob
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
@wjx0912
wjx0912 / kubernetes_test_job.yml
Created April 3, 2018 14:46
kubernetes test job
apiVersion: batch/v1
kind: Job
metadata:
name: myjob
spec:
template:
metadata:
name: myjob
spec:
containers: