Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
¯\_(ツ)_/¯

Ali Najafizadeh alinz

🎯
¯\_(ツ)_/¯
View GitHub Profile
View gist:1d67908ccff03ca2d80b86260cb82aef
type Claims struct {
AccountID string `json:"account_id"`
GroupID string `json:"group_id"`
jwtgo.StandardClaims
}
// Encode
func (c *Claims) Encode(secretKey []byte) (string, error) {
const op = errors.Op("jwt.Claims.Encode")
View gist:92fd7b56d400b59bc584935ae0ce15b6
package config
import (
"os"
"strings"
"github.com/spf13/viper"
)
type Config struct {
@alinz
alinz / Certificates.go
Created Nov 12, 2019 — forked from Mattemagikern/Certificates.go
Create x509 certificate chain using Golang. Root CA, Designated CA, server CA
View Certificates.go
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
@alinz
alinz / sample.sh
Created Nov 12, 2019
OPENSSL encrypt decrypt
View sample.sh
openssl aes-256-cbc -in plain.txt -out plain.enc -k cool
openssl aes-256-cbc -d -in plain.enc -out plain.txt -k cool
@alinz
alinz / PROFILE.MD
Created Nov 7, 2019
Golang Profiling commands
View PROFILE.MD

Prfile

Generate Prfile data

go test -cpuprofile cpu.prof -memprofile mem.prof -bench .

Visual Profile data

View model.ts
export class Model {
constructor(obj: any) {
for (let key in obj) {
this.unmarshal(toCamelCase(key), obj[key])
}
}
marshal(): any {
return Object.keys(this).reduce((obj: any, key: string) => {
obj[toSnakeCase(key)] = toJS(this[key])
@alinz
alinz / Makefile
Created Sep 25, 2019
Compile Zig to WebAssembly and run it in Node.js
View Makefile
build:
zig build-exe --name test.wasm -target wasm32-freestanding --release-small test.zig
View setup react project
// babel js
{
"plugins": [
["react-hot-loader/babel"],
["babel-plugin-root-import"],
[
"import", {
"libraryName": "antd",
"libraryDirectory": "es",
@alinz
alinz / golang_tls_http.go
Created Jul 11, 2019
Share tls config with server and client in golang
View golang_tls_http.go
package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"io"
"io/ioutil"
"log"
"net/http"
@alinz
alinz / router.go
Created Jul 7, 2019
router with cors
View router.go
import (
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/goware/cors"
)
func New() chi.Router {
cors := cors.New(cors.Options{
You can’t perform that action at this time.