Skip to content

Instantly share code, notes, and snippets.

View katopz's full-sized avatar
🦀
Rust me if you can

Todsaporn Banjerdkit katopz

🦀
Rust me if you can
View GitHub Profile
@katopz
katopz / drop.sh
Last active July 2, 2017 14:13
To create DigitalOcean droplet
# Get name andcs image from arguments
NAME=$1
IMAGE=${2:-"ubuntu-16-04-x64"}
# Get droplet option
DO_OPTION=$(tr -d '\n' < ./droplets.json | tr -d ' ')
DO_OPTION=${DO_OPTION/'$NAME'/$NAME}
DO_OPTION=${DO_OPTION/'$IMAGE'/$IMAGE}
# Create droplet
@katopz
katopz / droplets.json
Created July 2, 2017 14:07
DigitalOcean template
{
"name": "$NAME",
"region": "sgp1",
"size": "512mb",
"image": "$IMAGE",
"backups": true,
"private_networking": true,
"ipv6": true,
"monitoring": true,
"ssh_keys": [
@katopz
katopz / snap.json
Created July 2, 2017 08:12
Packer example
{
"variables": {
"api_token": "{{env `DO_TOKEN`}}"
},
"builders": [
{
"api_token": "{{user `api_token`}}",
"type": "digitalocean",
"region": "sgp1",
"image": "ubuntu-16-04-x64",
@katopz
katopz / docker-alpine-bench.md
Created June 23, 2017 04:25
Docker Apache bench as pretty JSON

Grab only json result

docker run -it --rm -t devth/alpine-bench -n3 -v2 http://google.com/ | jq -R 'fromjson?' 1>./test/speed-https-jamplay-world.json
# Just for perf, you can skip this.
START_SEC=$(date +'%s')
# Creating network.
docker-machine ssh node-1 "docker network create --driver overlay proxy"
# Grab the source.
docker-machine ssh node-1 "curl -o docker-compose-stack.yml https://raw.githubusercontent.com/vfarcic/docker-flow-proxy/master/docker-compose-stack.yml"
# Create docker-flow-proxy and docker-flow-swarm-listener services.
@katopz
katopz / setup-swarm-stack.sh
Last active March 3, 2017 08:52
How to deploy Docker 1.13 swarm mode stack
# Ref : https://docs.docker.com/engine/getstarted-voting-app/deploy-app/
# Just for perf, you can skip this.
START_SEC=$(date +'%s')
# Cleaning old manager and worker, you can skip this
docker-machine rm -f manager && docker-machine rm -f worker
# Create manager.
docker-machine create --driver virtualbox manager
@katopz
katopz / setup-do-foo.sh
Last active May 5, 2019 23:30
How to create DigitalOcean's droplet with docker-machine
# Required DIGITALOCEAN_ACCESS_TOKEN from DigitalOcean's dashboard.
# https://cloud.digitalocean.com/settings/api/tokens
#
# Required DIGITALOCEAN_SSH_KEY_FINGERPRINT
# $ ssh-keygen -l -E md5 -f ~/.ssh/id_rsa.pub
#
docker-machine create \
--driver digitalocean \
--digitalocean-access-token=$DIGITALOCEAN_ACCESS_TOKEN \
--digitalocean-image ubuntu-16-04-x64 \
@katopz
katopz / extract-svg.js
Last active December 12, 2016 15:06
Get element inside svg by xpath or string
// By XPATH
// https://github.com/facebook/react/graphs/participation?h=28&type=sparkline&w=155
$x("//*[local-name() = 'polyline']/@points")[0].value.split(',')
// By String
fetch('https://github.com/facebook/react/graphs/participation?h=28&type=sparkline&w=155').then((res) => {
return (res.text())
}).then((text) => {
// x0, y0, x1, y1, ...
console.log(text.match(/points=\"(.*?)"/)[1].trim().split(' ').join(',').split(',').map(s => Number(s)))
@katopz
katopz / recers.sh
Created December 11, 2016 11:04
reccers
#!/bin/sh
# https://github.com/certbot/certbot/issues/1833
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
# Ensure script is call
echo $(date)'|Renewal' >> /var/log/letsencrypt/daily.log
# This script renews all the Let's Encrypt certificates with a validity < 30 days
if ! /opt/letsencrypt/letsencrypt-auto renew > /var/log/letsencrypt/renew.log 2>&1 ; then
echo Automated renewal failed:
@katopz
katopz / dom-graphql.gql
Created December 2, 2016 09:37
How to query gdom
// try this at https://github.com/syrusakbary/gdom
{
page(url: "https://preactjs.com") {
title
html
items: query(selector:"link") {
url: attr(name:"href")
}
}
}