Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@kamermans
kamermans / fix_quotes.sh
Last active April 16, 2024 00:23
Replace fancy-quotes / curly-quotes / smart-quotes with standard ASCII single- and double-quotes in bash
#!/bin/bash
# Replaces annoying "fancy" quotes created by programs like Microsoft Word and everything in MacOS
# with normal ASCII single-quotes (') or double-quotes (")
# This script does NOT replace the GRAVE ACCENT (`) since it is commonly used in Markdown and as a bash command
# See: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
SINGLE=$(echo -ne '\u00B4\u2018\u2019')
DOUBLE=$(echo -ne '\u201C\u201D')
sed -i "s/[$SINGLE]/'/g; s/[$DOUBLE]/\"/g" $1
@kamermans
kamermans / generate_imei.py
Last active April 12, 2024 08:51
Generates a complete, valid IMEI from a TAC code or otherwise incomplete IMEI.
#!/usr/bin/env python2
from random import randint
def generate_imei(incomplete_imei):
luhn_sum = 0
imei_digits = []
for i in xrange(0,14):
# Pull each digit from the TAC, generate missing numbers with rand()
@kamermans
kamermans / fail2ban-allstatus.sh
Created July 11, 2011 17:06
Show status of all fail2ban jails at once
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
@kamermans
kamermans / install_jq.sh
Created January 22, 2015 17:21
Install jq (JSON Command Line processor)
#!/bin/bash -e
# This scripts installs jq: http://stedolan.github.io/jq/
JQ=/usr/bin/jq
curl https://stedolan.github.io/jq/download/linux64/jq > $JQ && chmod +x $JQ
ls -la $JQ
@kamermans
kamermans / configure_docker0.sh
Last active January 11, 2024 18:21
Change the IP subnet of Docker's docker0 interface
#!/bin/sh -e
#
# NOTE: Since Docker 1.10 (February 4, 2016), it has been possible to configure the
# Docker daemon using a JSON config file. On Linux, this file is normally located at
# /etc/docker/daemon.json. You should use this JSON config method if you are running
# a version of Docker that is at least 1.10!
# Here is an example configuration that sets the docker0 bridge IP to 192.168.254.1/24:
# {
# "bip": "192.168.254.1/24"
# }
@kamermans
kamermans / curl-timing
Created October 21, 2017 15:01
Curl helper that adds detailed timing information
#!/bin/bash -e
# Put this file in /usr/local/bin and use 'curl-timing' in place of 'curl'
# to get a detailed timing report with the response.
# You can customize the report below. For older versions of curl, some
# of the fields below will not be available.
TIMING_FORMAT=$(cat <<EOL
url_effective: %{url_effective}
remote_ip: %{remote_ip}
@kamermans
kamermans / php-error-logstash.conf
Last active July 31, 2023 11:31
Logstash parser for PHP's error_log to combine multline stack traces / errors into one event
input {
stdin {
codec => multiline {
pattern => "^\[%{MONTHDAY}-%{MONTH}-%{YEAR} %{TIME} %{TZ}\]"
negate => true
what => "previous"
auto_flush_interval => 10
}
type => "php-error"
}
@kamermans
kamermans / parse_identify.php
Last active July 29, 2023 17:34
ImageMagick identify -verbose JSON transformer
#!/usr/bin/env php
<?php namespace kamermans\ImageMagick;
/**
* Parser for the ImageMagick "identify" utility that takes "identify -verbose <file>"
* output on STDIN and outputs JSON on STDOUT.
*
* Example:
* identify -verbose foo.jpg | ./parse_identify.php
*/
@kamermans
kamermans / mysql_countries.sql
Created December 7, 2011 04:43
MySQL Dump - continents and countries with 2 and 3 char codes, names and full names - Braintree compatible as of Dec 2011
/**
* Continents and Countries MySQL Tables compiled from Wikipedia, Braintree Payments documentation
* and a couple other places I don't recall at the moment. This data is compatible with the Braintree
* Payment API as of Dec 2011
*
* Compiled by Steve Kamerman, 2011
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
@kamermans
kamermans / get_docker_host_ip.php
Created November 1, 2016 15:53
Example of retrieving the Docker host IP from within a container via PHP by parsing the Linux kernel's routing table
<?php
$gw = "Unknown";
// Get the Docker host IP from the routing table
$table = file("/proc/net/route");
foreach ($table as $row) {
// Split the fields out of the routing table
$fields = preg_split("/[\t ]+/", trim($row));