Skip to content

Instantly share code, notes, and snippets.

View jordiclariana's full-sized avatar

Jordi Clariana jordiclariana

View GitHub Profile
@jordiclariana
jordiclariana / lawssh.sh
Created December 22, 2017 10:08
Function to ssh to AWS hosts via laws
lawssh ()
{
while [[ "$1" =~ ^- ]]; do
laws_opts="${laws_opts} $1";
shift;
done;
pattern="$1";
shift;
for i in $(laws ${laws_opts} "${pattern}");
do
@jordiclariana
jordiclariana / btrfs-lz4-v4.9.24.patch
Created August 31, 2017 10:07
Add LZ4 compression support to BTRFS
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 84d71482bf08..42f6da112054 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1608,6 +1608,23 @@ config CRYPTO_LZ4HC
help
This is the LZ4 high compression mode algorithm.
+
+config CRYPTO_LZ4
@jordiclariana
jordiclariana / aws_internal_dns.sh
Created May 2, 2017 11:33
Create a /etc/awshosts file that dnsmasq uses to resolve hosts on AWS
_aws_internal_dns ()
{
ip ro show | grep --color=auto default > /dev/null || return 0;
local TMPFILE="/tmp/_aws_internal_dns";
local LOCK="${TMPFILE}.lock";
if [ -e "${LOCK}" ]; then
local now="$(date +%s)";
local lock_time="$(stat -c "%Y" "${LOCK}")";
if [ $((${now}-${lock_time})) -gt 30 ]; then
rm -f "${LOCK}";
@jordiclariana
jordiclariana / locked_tables.sh
Last active April 18, 2017 14:10
Show transactions blocking other tables for more than 300 seconds
#!/usr/bin/env bash
# Minimum seconds the lock existed for. Default 300 seconds
MINSECONDS="${1:-300}"
# If stdin is not a pipe, exec 'mysql', else 'cat' to read stdin from the pipe
{ [ -t 0 ] && mysql -e "SHOW ENGINE INNODB STATUS\G" || cat; } | \
awk -v MINSECONDS=$MINSECONDS '$0 ~ /^(RECORD LOCKS space id|MySQL thread id |---TRANSACTION)/ {
if ($1 == "---TRANSACTION" && $4 != "started") {
if ($4>=MINSECONDS) {
#!/usr/bin/env python3
import argparse
import boto3
import os
import time
import json
import re
instance_filters = {
2017/01/31 17:35:31 [INFO] Terraform version: 0.8.5 b4d477660b5abd20f2a70175460c9603797fada0
2017/01/31 17:35:31 [INFO] CLI args: []string{"/opt/hashicorp/bin/terraform", "apply"}
2017/01/31 17:35:31 [DEBUG] Detected home directory from env var: /home/jordi
2017/01/31 17:35:31 [DEBUG] Detected home directory from env var: /home/jordi
2017/01/31 17:35:31 [DEBUG] Attempting to open CLI config file: /home/jordi/.terraformrc
2017/01/31 17:35:31 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2017/01/31 17:35:31 [DEBUG] Detected home directory from env var: /home/jordi
2017/01/31 17:35:31 [DEBUG] vertex "module.asg_module": static expanding
2017/01/31 17:35:31 [DEBUG] DestroyEdgeInclude: Checking: module.asg_module.aws_autoscaling_group.asg
2017/01/31 17:35:31 [DEBUG] DestroyEdgeInclude: Checking: module.asg_module.aws_autoscaling_group.asg
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<END
RUBY_VERSION="2.2.5"
sudo apt-get -y update
sudo apt-get -y install git nodejs
# Install ruby environment
if ! type rvm >/dev/null 2>&1; then
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
@jordiclariana
jordiclariana / authorized_keys
Created April 19, 2016 19:20
Enable transparent sudo through authorized_keys, also for scp, rsync, etc.
command="if [ -n \"$SSH_ORIGINAL_COMMAND\" ]; then sudo /bin/bash -c \"$SSH_ORIGINAL_COMMAND\"; else sudo -i; fi" ssh-rsa AAAA...WXYZ myname
@jordiclariana
jordiclariana / push_terraform.sh
Created March 24, 2016 14:37
Sync terraform state from/to s3 bucket
#!/bin/bash
TERRAFORM_DIR="TERRAFORM_DIRECTORY"
find ${TERRAFORM_DIR} -name "*.tfstate" | while read lfile; do
rfile="$(jq '.remote.config | select (.key != null) | "s3://" + .bucket + "/" + .key' ${lfile} -r)"
if [ -n "${rfile}" ]; then
if ! diff -q ${lfile} <(s3cmd --no-progress get ${rfile} -) > /dev/null; then
echo "${lfile} differs, syncing ..."
cd "$(dirname "${lfile}")/.."
terraform remote pull && \
@jordiclariana
jordiclariana / pre-commit.sh
Last active January 22, 2016 11:53
Pre commit for scala projects (sergigp review)
#!/bin/bash
declare -A COLORS
COLORS[RED]='\033[0;31m'
COLORS[GREEN]='\033[0;32m'
COLORS[NC]='\033[0m'
COLORS[WHITE]='\033[1m'
# Print a string using colors
# $1 The color