Skip to content

Instantly share code, notes, and snippets.

View gokusenz's full-sized avatar
🎯
Focusing

Nattawut Ruangvivattanaroj gokusenz

🎯
Focusing
View GitHub Profile
@gokusenz
gokusenz / ssh.md
Last active February 13, 2019 23:13

Home directory on the server should not be writable by others: chmod go-w /home/$USER

SSH folder on the server needs 700 permissions: chmod 700 /home/$USER/.ssh

Authorized_keys file needs 644 permissions: chmod 644 /home/$USER/.ssh/authorized_keys

Make sure that user owns the files/folders and not root: chown user:user authorized_keys and chown user:user /home/$USER/.ssh

Put the generated public key (from ssh-keygen) in the user's authorized_keys file on the server

@gokusenz
gokusenz / logger.go
Last active October 16, 2018 16:19
It's the only was we can get Stackdriver to display logs correctly when running as a Kubernetes app in Google's cloud.
type OutputSplitter struct{}
func (splitter *OutputSplitter) Write(p []byte) (n int, err error) {
if bytes.Contains(p, []byte("error")) {
return os.Stderr.Write(p)
}
return os.Stdout.Write(p)
}
logrus.SetOutput(&OutputSplitter{})
@gokusenz
gokusenz / Git.sh
Created October 12, 2018 02:31
GIT CRUD
git add file // Stage
git reset HEAD file // Unstage
git checkout -- file // Reset
git diff file // Diff Unstage
git diff --cached file // Diff Staged
git commit -m "Message" // Commit
git push // Push
@gokusenz
gokusenz / max_concurrent.go
Created October 8, 2018 04:42
Set max concurrent
const maxConcurrency = 10
var throttle = make(chan int, maxConcurrency)
var wg sync.WaitGroup
listGroup = GetList()
for _, e := range listGroup {
throttle <- 1
wg.Add(1)
@gokusenz
gokusenz / line.go
Created August 16, 2018 06:07
Golang line flexbox
import "github.com/line/line-bot-sdk-go/linebot"
func reply(replyToken string) error {
container := &linebot.BubbleContainer{
Type: linebot.FlexContainerTypeBubble,
Body: &linebot.BoxComponent{
Type: linebot.FlexComponentTypeBox,
Layout: linebot.FlexBoxLayoutTypeHorizontal,
Contents: []linebot.FlexComponent{
&linebot.TextComponent{
@gokusenz
gokusenz / redirect-ingress.yml
Created August 7, 2018 16:57 — forked from sandcastle/redirect-ingress.yml
An example of a ingress redirect using kubernetes and nginx `configuration-snippet`
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: redirect-ingress
annotations:
ingress.kubernetes.io/configuration-snippet: |
if ($host ~ ^(.+)\.somedomain\.io$) {
return 301 https://$1.domain.io$request_uri;
}
spec:
@gokusenz
gokusenz / wp-config.php
Created August 5, 2018 18:20
WordPress, nginx proxy and subdirectory: wp-login.php redirects to domain
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/", $_SERVER['REQUEST_URI']);
# https://stackoverflow.com/questions/34090577/wordpress-nginx-proxy-and-subdirectory-wp-login-php-redirects-to-domain
@gokusenz
gokusenz / permission.sh
Last active July 19, 2018 11:29
edit permission pvc
kubectl create --filename=- <<'EOF'
apiVersion: batch/v1
kind: Job
metadata: {name: grafana-chown, namespace: monitoring}
spec:
template:
spec:
restartPolicy: Never
containers:
- name: grafana-chown
# Kubernetes API version
apiVersion: v1
# Type of "request"
kind: Pod
# Metadata of the "object"
metadata:
# Name of the "object"
name: phpmyadmin
namespace: default
# Labels of the "object"
@gokusenz
gokusenz / Dockerfile
Created May 16, 2018 13:48
docker golang for build
FROM golang:1.10-alpine
RUN apk add --no-cache curl git
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
WORKDIR /go/src