Skip to content

Instantly share code, notes, and snippets.

@iMega
iMega / rs256.rsa.md
Last active May 19, 2021 09:50
How to generate RS256 Key Pair for Mac & Linux with passphrase

Without passphrase

Generate rsa keys pair and don't add passphrase

ssh-keygen -t rsa -b 4096 -f rs256.rsa
openssl rsa -in rs256.rsa -pubout -outform PEM -out rs256.rsa.pub
cat rs256.rsa
cat rs256.rsa.pub
@iMega
iMega / README.md
Created February 22, 2021 11:37
New release app from Github repo with webhook on VPS

Install webhook on VPS

wget https://github.com/adnanh/webhook/releases/download/2.8.0/webhook-linux-amd64.tar.gz
tar -zxf webhook-linux-amd64.tar.gz
mv webhook-linux-amd64/webhook /usr/bin/webhook
chmod +x /usr/bin/webhook

Copy webhook.service to /usr/lib/systemd/system/webhook.service

@iMega
iMega / format.sh
Last active September 11, 2020 12:40
Golang: format code (all project) with gofumpt
go list -f '{{ .Dir }}' ./... | grep -v 'vendor' | tail -n +2 | xargs gofumports -w
@iMega
iMega / git-cmds.md
Last active April 28, 2020 11:46
Special commands git for manage big repo

To update the local list of remote branches

git remote update origin --prune

Listing branches with their latest author

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)'
@iMega
iMega / main_test.go
Created December 9, 2019 06:49
The fastest and simplest way generate a random string
//
// https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
//
package main
import (
"math/rand"
"strings"
"testing"
"time"
@iMega
iMega / index.js
Created April 20, 2019 18:44
Using Class Components (>= [email protected])
class Parent extends Component {
constructor(props) {
super(props);
this.child = React.createRef();
}
onClick = () => {
this.child.current.getAlert();
};
@iMega
iMega / index.js
Created April 20, 2019 18:42
Using Hooks and Function Components (>= [email protected])
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
// We need to wrap component in `forwardRef` in order to gain
// access to the ref object that is assigned using the `ref` prop.
// This ref is passed as the second parameter to the function component.
const Child = forwardRef((props, ref) => {
// The component instance will be extended
// with whatever you return from the callback passed
// as the second argument
@iMega
iMega / note.txt
Created April 2, 2019 10:39
Install node with brew on El Capitan
OS X El Capitan 10.11.6 (15G1011)
Homebrew 2.0.6
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/6d98155ab46f61482f16f8bcffb378a0a71e0d15/Formula/icu4c.rb
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/bb43eb1cf32ae14fc6df77c3b92adbe9a779338b/Formula/node.rb
node v9.11.1
icu4c 61.1
npm 5.6.0
@iMega
iMega / Dockerfile
Created September 24, 2018 06:08
grpc_php_plugin
FROM grpc/php
RUN apt-get update && \
apt-get install --yes build-essential autoconf libtool zlib1g-dev zip unzip automake libtool pkg-config && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN git clone -q --depth 1 --recursive -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc /root/grpc \
&& cd /root/grpc \
&& make grpc_php_plugin \
@iMega
iMega / main.go
Created August 30, 2018 15:19
best practice append
// A constructor for a piece of middleware.
// Some middleware use this constructor out of the box,
// so in most cases you can just pass somepackage.New
type Constructor func(http.Handler) http.Handler
// Chain acts as a list of http.Handler constructors.
// Chain is effectively immutable:
// once created, it will always hold
// the same set of constructors in the same order.
type Chain struct {