Skip to content

Instantly share code, notes, and snippets.

Understanding Your Google Cloud Costs
# Analyzing Billing Data with BigQuery
SELECT * FROM `billing_dataset.enterprise_billing` WHERE Cost > 0
SELECT Line_Item FROM `billing_dataset.enterprise_billing` GROUP BY Line_Item
SELECT Line_Item, COUNT(*) as NUM FROM `billing_dataset.enterprise_billing` GROUP BY Line_Item
SELECT Project_ID, COUNT(*) as num FROM `billing_dataset.enterprise_billing` GROUP BY Project_ID
SELECT SUM(cost) as Cost, Project_Name FROM `billing_dataset.enterprise_billing` GROUP BY Project_Name
# Visualizing Billing Data with Data Studio
@melinite
melinite / systemd_service_hardening.md
Created April 14, 2024 17:22 — forked from ageis/systemd_service_hardening.md
Options for hardening systemd service units

security and hardening options for systemd service units

A common and reliable pattern in service unit files is thus:

NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
DevicePolicy=closed
ProtectSystem=strict
@melinite
melinite / cors-nginx.conf
Created January 25, 2024 13:18 — forked from michiel/cors-nginx.conf
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@melinite
melinite / xtrabackup_runner.sh
Created August 1, 2018 21:17 — forked from sveesible/xtrabackup_runner.sh
A fancier mysql backup script for Xtrabackup:
#!/bin/bash
#
# Script to create full and incremental backups (for all databases on server) using innobackupex from Percona.
# http://www.percona.com/doc/percona-xtrabackup/innobackupex/innobackupex_script.html
#
# Every time it runs will generate an incremental backup except for the first time (full backup).
# FULLBACKUPLIFE variable will define your full backups schedule.
#
# 2012 Brad Svee modified to try to use xbstream
# (C)2012 Atha Kouroussis @ Vurbia Technologies International Inc.
@melinite
melinite / Documentation.md
Created June 27, 2018 13:33 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@melinite
melinite / install-java-8-on-ubuntu-14.04-auto-accept-licence-agreement.sh Install oracle Java 8 on Ubuntu 14.04 and automatically accept the licence agreement. 100% hands-free install.
#! /bin/bash
sudo apt-get update
sudo apt-get install -y software-properties-common debconf-utils
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer
@melinite
melinite / sendgrid.bash
Created April 26, 2018 14:16 — forked from velizarn/sendgrid.bash
Send email from bash script by using SendGrid API
#!/bin/bash
SENDGRID_API_KEY=""
EMAIL_TO=""
FROM_EMAIL=""
FROM_NAME=""
SUBJECT=""
bodyHTML="<p>Email body goes here</p>"
@melinite
melinite / Howto convert a PFX to a seperate .key & .crt file
Created April 12, 2018 02:05 — forked from TemporaryJam/Howto convert a PFX to a seperate .key & .crt file
How to convert a .pfx SSL certificate to .crt/key (pem) formats. Useful for NGINX
source: http://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/
`openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]`
What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file. This is the password that you used to protect your keypair when you created your .pfx file. If you cannot remember it anymore you can just throw your .pfx file away, cause you won’t be able to import it again, anywhere!. Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.
Now let’s extract the certificate:
`openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]`
@melinite
melinite / MySQL Replication Check
Created September 25, 2017 23:18 — forked from ssimpson89/MySQL Replication Check
Just a simple Mysql Replication Health Check script I wrote. You can put this in a cron.
#!/bin/bash
### VARIABLES ### \
EMAIL=""
SERVER=$(hostname)
MYSQL_CHECK=$(mysql -e "SHOW VARIABLES LIKE '%version%';" || echo 1)
LAST_ERRNO=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Last_Errno" | awk '{ print $2 }')
SECONDS_BEHIND_MASTER=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G"| grep "Seconds_Behind_Master" | awk '{ print $2 }')
IO_IS_RUNNING=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Slave_IO_Running" | awk '{ print $2 }')
SQL_IS_RUNNING=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Slave_SQL_Running" | awk '{ print $2 }')
@melinite
melinite / redis_rdb_backup.sh
Last active July 8, 2017 09:30
redis rdb backup script
#!/bin/bash
## simple redis rdb backup script
## usage
## rdb-backup.sh rdb.path backup.dir bgsave.wait.seconds
SRCPATH=${1:-"/var/lib/redis/"}
DESTPATH=${2:-"/opt/redisbackups"}
DESTFILE=${3:-"`date '+%Y-%m-%d-%H%M%S'`-redis.rdb.tar.gz"}
WAIT=${4:-10} ## default wait for 10 seconds