Skip to content

Instantly share code, notes, and snippets.

View corehello's full-sized avatar
🏠
Working from home

corehello corehello

🏠
Working from home
View GitHub Profile
# First the server
#!/usr/bin/env python
#!/usr/bin/env python
"""
A basic, multiclient 'chat server' using Python's select module
with interrupt handling.
Entering any line of input at the terminal will exit the server.
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
(LET ((server (SOCKET:SOCKET-SERVER)))
(FORMAT t "~&Waiting for a connection on ~S:~D~%"
(SOCKET:SOCKET-SERVER-HOST server) (SOCKET:SOCKET-SERVER-PORT server))
(UNWIND-PROTECT
;; infinite loop, terminate with Control+C
(LOOP (WITH-OPEN-STREAM (socket (SOCKET:SOCKET-ACCEPT server))
(MULTIPLE-VALUE-BIND (local-host local-port) (SOCKET:SOCKET-STREAM-LOCAL socket)
(MULTIPLE-VALUE-BIND (remote-host remote-port) (SOCKET:SOCKET-STREAM-PEER socket)
(FORMAT T "~&Connection: ~S:~D -- ~S:~D~%"
remote-host remote-port local-host local-port)))
@corehello
corehello / goserver_regexp.go
Created January 4, 2015 11:20
go http server with regex match router
package main
import (
"net/http"
"fmt"
"html"
"regexp"
"log"
"os"
"time"
@corehello
corehello / generage_certificate.sh
Last active August 29, 2015 14:12
Generate certificate with openssl
#generate CA self-signed certificate
openssl genrsa -out private\ca.key -rand private\.rnd -des 2048
openssl req -new -x509 -days 3650 -key private\ca.key -out private\ca.crt -config openssl.cnf
openssl x509 -in private\ca.crt -noout -text
#generate server certificate
openssl genrsa -out private\server.key 1024
openssl req -new -key private\server.key -out newcerts\server.csr -config openssl.cnf
openssl ca -in newcerts\server.csr -cert private\ca.crt -keyfile private\ca.key
-config openssl.cnf -policy policy_anything -out certs\server.crt
@corehello
corehello / bmp_structure.txt
Last active August 29, 2015 14:13
bmp image format file structure - http://www.digicamsoft.com/bmp/bmp.html
Graphics File Formats
This topic describes the graphics-file formats used by the Microsoft Windows
operating system. Graphics files include bitmap files, icon-resource files,
and cursor-resource files.
Bitmap-File Formats
Windows bitmap files are stored in a device-independent bitmap (DIB) format
that allows Windows to display the bitmap on any type of display device. The
(defun reproduce (population)
(let ((offspring nil)
(d (distribution population)))
(dotimes (i (/ (length population) 2))
(let ((x (selectone d))
(y (selectone d)))
(crossover x y)
(setq offspring (nconc (list x y) offspring))))
offspring))
; The code in this file was mechanically extracted from the TeX
; source files of _Ansi Common Lisp_, except for bst-remove and
; bst-delete and their subroutines, which replace broken versions
; in the book.
; If you have questions or comments about this code, or you want
; something I didn't include, send mail to lispcode@paulgraham.com.
; This code is copyright 1995 by Paul Graham, but anyone who wants
; to use it is free to do so.
@corehello
corehello / file_server.go
Last active March 3, 2021 10:53
The most simple http server in golang like `python -m SimHTTPServer 8000`
package main
import (
"log"
"net/http"
"os"
)
func Log(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@corehello
corehello / latency.txt
Created May 9, 2016 10:28 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD