Skip to content

Instantly share code, notes, and snippets.

View Yapcheekian's full-sized avatar

Yap Yapcheekian

View GitHub Profile
@Yapcheekian
Yapcheekian / handlerFuncWrapper.go
Last active May 22, 2021 09:24
go http middleware
func errorHandler(fn http.HandleFunc) http.HandleFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer func() {
if e, of := recover().(os.Error); ok {
w.WriteHeader(500)
errorTemplate.Execute(w, e)
}
}()
fn(w, r)
}
@Yapcheekian
Yapcheekian / tree.go
Created May 22, 2021 08:17
Tree command implemented in go
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
)
@Yapcheekian
Yapcheekian / nil_channel.go
Created May 22, 2021 09:25
why nil channel is important
package main
import (
"fmt"
"log"
"math/rand"
"time"
)
func main() {
@Yapcheekian
Yapcheekian / elastiscearch
Last active May 22, 2021 09:28
How to check established connection on elasticsearch server
curl localhost:9200/_nodes/stats/http?filter_path=nodes.*.name,nodes.*.http | jq .
@Yapcheekian
Yapcheekian / 2_ways_merge_channel.go
Created May 22, 2021 13:20
How to merge N channels into single one
package main
import (
"fmt"
"math/rand"
"reflect"
"sync"
"time"
)
@Yapcheekian
Yapcheekian / aws_assume_role.json
Created May 24, 2021 07:16
Restrict who can assume role in another AWS account
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::xxx:root"
},
"Action": "sts:AssumeRole",
"Condition": {
@Yapcheekian
Yapcheekian / tcp-server.go
Created May 25, 2021 01:19
example server in go
package main
import "net"
import "fmt"
import "bufio"
import "strings" // only needed below for sample processing
func main() {
fmt.Println("Launching server...")
@Yapcheekian
Yapcheekian / tcp-client.go
Created May 25, 2021 01:19
Example client in go
package main
import "net"
import "fmt"
import "bufio"
import "os"
func main() {
// connect to this socket
@Yapcheekian
Yapcheekian / auth.js
Created May 25, 2021 07:36
Basic auth simple implementation in js
const express = require("express");
const app = express();
const PORT = process.env.PORT || 5000;
app.get("/", (req, res) => {
res.send("Hello World!");
});
const authMiddleware = (req, res, next) => {
@Yapcheekian
Yapcheekian / openssl.txt
Created May 27, 2021 06:19
Use openssl to read certificate
openssl x509 -in certificate.crt -text -noout