Skip to content

Instantly share code, notes, and snippets.

View askz's full-sized avatar
🎯
Focusing

Max: askz

🎯
Focusing
View GitHub Profile
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
██████╗██╗ ██╗ ██████╗██╗ ██╗███╗ ███╗██████╗ ███████╗██████╗
██╔════╝██║ ██║██╔════╝██║ ██║████╗ ████║██╔══██╗██╔════╝██╔══██╗
██║ ██║ ██║██║ ██║ ██║██╔████╔██║██████╔╝█████╗ ██████╔╝
██║ ██║ ██║██║ ██║ ██║██║╚██╔╝██║██╔══██╗██╔══╝ ██╔══██╗
╚██████╗╚██████╔╝╚██████╗╚██████╔╝██║ ╚═╝ ██║██████╔╝███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝ ╚═╝
@askz
askz / beaudev_docker_nginx_proxy_host.sh
Created May 16, 2016 10:41 — forked from jmeyo/beaudev_docker_nginx_proxy_host.sh
Beaudev simple script to add a nginx vhost reverse proxying to a docker instance
#!/bin/bash
# add vhost reverse proxy for new docker instance for nginx and restart nginx
# use like this : do_nginx_proxy_vhost subdir.example.com http://192.168.0.20:8080
function do_nginx_proxy_vhost() {
[ -z $1 -o -z $2 ] && echo "Give host and address" && return
host=$1
address=$2
[ -f /etc/nginx/sites-available/proxy_reverse_$host ] && (echo "Updating proxy for host: $host" && sudo rm /etc/nginx/sites-enabled/proxy_reverse_$host) || echo "Creating proxy for host: $host"
@askz
askz / cli-mysql-to-innodb.php
Created April 5, 2017 16:29
Convert MyISAM to InnoDB - shell script
<?php
/*
* Use this version if you are NOT a Pantheon customer.
*/
$db = array();
/*
* Change these to match your database connection information
*/
$db['host'] = "localhost";
#Setup UID filter limit
export UGIDLIMIT=500
#copy /etc/passwd accounts to /opt/move/passwd.mig using awk to filter out system account
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /opt/move/passwd.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /opt/move/group.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd \
@askz
askz / add-user.sh
Last active July 4, 2018 02:59 — forked from floudet/ssh-chroot-jail.sh
Chroot Jail for SSH/SFTP Access toolkit
#!/bin/bash
# add "prisoner" in the jail you created before !!
# USAGE : ./add-user.sh <username> <password> <type>
# Type 1 : sftp jailed user ; Type 2 ssh jailed user
# A password will be auto-generated with pwgen (sudo apt install pwgen)
# Set your jail path wherever you want.
JAIL_PATH=/home/www/
@askz
askz / create-mysql.bash
Created May 16, 2017 17:58 — forked from omeinusch/create-mysql.bash
Simple bash script to create mysql db, user with generated password
#!/bin/bash
# The script will fail at the first error encountered
set -e
PASS=`pwgen -s 40 1`
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $1;
CREATE USER '$1'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $1.* TO '$1'@'localhost';
@askz
askz / bitcoin-monitor.md
Created May 11, 2018 10:04 — forked from ageis/bitcoin-monitor.md
Prometheus exporter for monitoring statistics of Bitcoin daemon

bitcoind-monitor.py

This is a script written in Python intended to run alongside a Bitcoin node and export statistics for monitoring purposes. It assumes the existence of bitcoin-cli in the PATH and access to the RPC interface over localhost.

It tracks stuff like: block height, difficulty, number of peers, network hash rate, errors, uptime in seconds, mempool size, size of recent blocks, number of transactions within blocks, chaintips, total bytes received and sent, and transaction inputs and outputs. These Bitcoin metrics are refreshed once every 5 minutes.

How it works

Prometheus is a monitoring system and time-series database.