Skip to content

Instantly share code, notes, and snippets.

View dreampuf's full-sized avatar

Dreampuf dreampuf

View GitHub Profile
@dreampuf
dreampuf / launch.sh
Created July 8, 2020 02:36
How to create a vuejs3 project
vue create PROJECT_NAME
# select features you need
cd PROJECT_NAME
vue add vue-next
rm src/shims-tsx.d.ts
sed -i '' 's/RouteConfig/RouteRecordRaw/g' src/router/index.ts # https://github.com/vuejs/vue-router-next/commit/fd49bbd085e9df7804994ea188f94384ac22e048
patch -p1 <<'EOF'
diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue
index dc773ba..01a7286 100644
--- a/src/components/HelloWorld.vue
@dreampuf
dreampuf / install_openjdk8.sh
Last active July 2, 2020 07:55
Install JDK8 on Jessie in 2020
cat > /etc/apt/sources.list.d/openjdk.list <<"EOF"
deb [check-valid-until=no] http://archive.debian.org/debian jessie-backports main
EOF
apt-get update
apt install -t jessie-backports openjdk-8-jdk
update-alternatives --config java # select java1.8
@dreampuf
dreampuf / bash
Last active March 21, 2020 22:35
How to get the golang package version of the latest git repo commit
# Credit: https://stackoverflow.com/a/59440771/398634
TZ=UTC git --no-pager show \
--quiet \
--abbrev=12 \
--date='format-local:%Y%m%d%H%M%S' \
--format="%cd-%h"
@dreampuf
dreampuf / chicken_soup.ipynb
Last active November 19, 2019 23:19
Greasy Chiken Soup
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dreampuf
dreampuf / ssh_test.go
Created August 27, 2019 22:01
Golang SSH Interactively shell show case
package main
import (
"bytes"
"context"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"io/ioutil"
"net"
"os"
@dreampuf
dreampuf / calc.y
Last active August 22, 2019 19:00
hostlist generate by goyacc
%{
package main
import(
"fmt"
"bufio"
"os"
"strconv"
"unicode"
"unicode/utf8"
)
@dreampuf
dreampuf / build_node_exporter.sh
Created August 7, 2019 15:45
Build a Node Exporter RPM package
# Extract Node Exporter RPM package
# Download the official tar package
# https://prometheus.io/download/#node_exporter
VERSION=${VERSION:-0.18.1}
URL=https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz
FILENAME=${URL##*/}
ROOT_PATH=$PWD/pkg
APP_ROOT_PATH=$ROOT_PATH/opt/node_exporter
ITERATION=${ITERATION:-1}
@dreampuf
dreampuf / instructions.sh
Created April 8, 2019 19:50
How to enable admission-pulgins in kubernetes of docker-desktop
# Install docker and kubernetes first
# Helpful link: https://www.docker.com/products/docker-desktop
# Then you need to get into the virtual machine by (it may change in the future, but the path should be similar)
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
# Change the line in /etc/kubernetes/manifests/kube-apiserver.yaml
# - --enable-admission-plugins=Initializers,NodeRestriction
# to
# - --enable-admission-plugins=Initializers,NodeRestriction,ValidatingAdmissionWebhook,MutatingAdmissionWebhook
@dreampuf
dreampuf / gateway_hook.sh
Created December 4, 2018 19:28
Add a posthook to prometheus pushgateway
# cat simple_posthook.sh
#/usr/bin/bash
PUSHGATEWAY_SERVER=_YOUR_PUSHGATEWAY_SERVER_ADDRESS_WITH_PORT
JOB_NAME=_YOUR_JOB_NAME
while true; do
echo -e "HTTP/1.1 200 OK\n\n# $(date)" | nc -l 0.0.0.0 9092 &> /dev/null;
sleep 3;
curl -s "http://${PUSHGATEWAY_SERVER}/metrics" | sed -ne "s/push_time_seconds{instance=\"\([[:alnum:].]*\)\",job=\"${JOB_NAME}\".*/\1/p" | xargs -I INSNAME curl -X DELETE http://${PUSHGATEWAY_SERVER}/metrics/job/${JOB_NAME}/instance/INSNAME &> /dev/null;
done
@dreampuf
dreampuf / cronjob_state_convert.py
Created November 27, 2018 16:59
Convert cronjob file to SaltStack state
import re
cronjob_content = """ PAST YOUR CRONJOB HERE """
cronjob_regex = re.compile(r'^([^#]\S*?) (\S+) (\S+) (\S+) (\S+)\s+(.+)$')
for n, (minute, hour, daymonth, month, dayweek, exp) in enumerate([i.groups() for i in map(cronjob_regex.search, d.splitlines()) if i], 1):
print "cronjob-%02d:" % n
print " cronjob.present:"
for k, v in {"minute": minute, "hour": hour, "daymonth": daymonth, "month": month, "dayweek": dayweek}.items():
if v != "*":