Skip to content

Instantly share code, notes, and snippets.

// 1. oldstring element is not in new : abandon(delete)
// 2. new element is not in oldstring : add(add)
func Difference(oldstring []string, newstring []string) map[string]string {
var diff = make(map[string]string)
// Loop two times, first to find oldstring strings not in newstring,
// second loop to find newstring strings not in oldstring
for i := 0; i < 2; i++ {
for _, s1 := range oldstring {
found := false
@SLonger
SLonger / client.go
Last active May 13, 2019 02:37
tcp 粘包处理 client
// 参考链接https://feixiao.github.io/2016/05/08/bufio/
package main
import (
"bufio"
"bytes"
"encoding/binary"
"flag"
"fmt"
"io"
@SLonger
SLonger / server.go
Last active May 13, 2019 02:43
tcp 粘包处理 server
// 参考链接https://feixiao.github.io/2016/05/08/bufio/
package main
import (
"bytes"
"encoding/binary"
"flag"
"fmt"
"io"
"net"
@SLonger
SLonger / progress.html
Last active June 21, 2017 03:00
To make the propgress.html work well you should make server load the html .
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<progress id="progressBar" value="0" max="100" style="width: 300px;"></progress>
<span id="percentage"></span>
<html>
<head>
<title>WebSocket demo</title>
</head>
<body>
<div>
<form>
<label for="numberfield">Number</label>
<input type="text" id="numberfield" placeholder="12"/><br />
@SLonger
SLonger / udpbuffer.go
Last active April 21, 2017 02:31
golang test udp socket buffer after set it value.
package main
import (
"fmt"
"net"
// "os"
"syscall"
)
const (
the function the follow utility:
1. inquire socket buffer before set socket buffer
2. set socket buffer
3. get the info after set buffer
conclusion: a. the get value of socket buffer is double of the set value.
b. if set value > the max of os max value , the value we get is double *maxsocketbuffer of os
for example
if max of os socket buffer is 200000 bytes and we set value is 3000000 ,
then we get the value is 400000 not 600000.
@SLonger
SLonger / multipart_upload.go
Last active December 27, 2023 16:27 — forked from mattetti/multipart_upload.go
Example of doing a multipart upload in Go (golang) , client create http request instead of html form.
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
@SLonger
SLonger / createDir
Last active February 9, 2017 01:52
create file contain directory , create parent directories as needed
#include <io.h>
#include <direct.h>
#define MAX_PATH 256
void CreateDir(const char* pPath)
{
const char *lastpoint;