Skip to content

Instantly share code, notes, and snippets.

@leslie-wang
leslie-wang / TrueColour.md
Created December 22, 2019 21:10 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals

Terminal Colors

There exists common confusion about terminal colors. This is what we have right now:

  • Plain ASCII
  • ANSI escape codes: 16 color codes with bold/italic and background
  • 256 color palette: 216 colors + 16 ANSI + 24 gray (colors are 24-bit)
  • 24-bit true color: "888" colors (aka 16 milion)
@leslie-wang
leslie-wang / golang-tls.md
Created May 10, 2019 05:08 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples
Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
@leslie-wang
leslie-wang / atoi_test.go
Created May 10, 2019 04:43 — forked from evalphobia/atoi_test.go
golang benchmark: String and Int conversions
package bench
import (
"strconv"
"testing"
)
var smallStr = "35"
var bigStr = "999999999999999"
@leslie-wang
leslie-wang / SimpleHTTPSServer.py
Created August 18, 2017 18:46
SimpleHTTPSServer to serve HTTPS request
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('localhost', 4443),
SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket,
keyfile="server.key",
certfile='server.crt', server_side=True)
@leslie-wang
leslie-wang / SimpleHTTPServer1.1.py
Last active August 17, 2017 22:19
Simple HTTP Server for HTTP 1.1
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.1"
if sys.argv[1:]:
@leslie-wang
leslie-wang / gist:10fe63f95f66c5947cac6208c411efc2
Created August 5, 2017 02:55
Dump buffer in hex and dec mode as vi hex mode
void buffer_dump(char *data, int length) {
int row, col, idx = 0;
for (row = 0; row <= length / 16; row++) {
int len = row == length / 16 ? length % 16 : 16;
printf("%d: ", row);
//print hex
for (col = 0; col < len; col++) {
printf("%02X ", (unsigned char) data[idx + col]);
}
for (; col < 16; col++)