Skip to content

Instantly share code, notes, and snippets.

@mdpuma
mdpuma / sleep_until.sh
Last active February 2, 2016 18:53 — forked from p0c/sleep_until.sh
shell function sleep until
#!/bin/bash
current_time=$(date +%s)
target_time=$(date -d "$*" +%s)
seconds=$(( $target_time - $current_time ))
echo "sleeping $seconds (`date -d "$*"`)"
sleep $seconds
# Usage:
@mdpuma
mdpuma / post-mortem.md
Created February 20, 2016 19:53 — forked from joewiz/post-mortem.md
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1
@mdpuma
mdpuma / ipmitool-sdr.py
Last active January 29, 2017 13:10 — forked from varesa/gist:2c473b70ffd771e6ffa071654c970aaa
ipmitool sdr for collectd
#!/bin/env python
import os
import subprocess
import time
# subprocess.check_output is not exist in python 2.6 which is on centos6
# hostname = os.getenv("COLLECTD_HOSTNAME", subprocess.check_output(["hostname", "-f"]).strip())
p = subprocess.Popen(["hostname", "-f"], stdout=subprocess.PIPE)
@mdpuma
mdpuma / extensions.lua
Created May 11, 2017 18:02 — forked from igmar/extensions.lua
Asterisk LUA dialplan
require("lsqlite3")
-- Igmar: Wanneer closen we dat DB object eigenlijk ?
db = sqlite3.open('/etc/asterisk/users.sqlite')
--CONSOLE = "Console/dsp" -- Console interface for demo
--CONSOLE = "DAHDI/1"
--CONSOLE = "Phone/phone0"
TRUNK = "DAHDI/G1"
@mdpuma
mdpuma / lftp.conf
Last active May 26, 2017 04:42 — forked from fxthomas/lftp.conf
Lftp Configuration & mirror including all dot/hidden files
## some useful aliases
alias ls "ls -h"
alias dir ls
alias less more
alias zless zmore
alias bzless bzmore
alias mirror "mirror -v"
alias sync "mirror -R -v -n"
alias reconnect "close; cache flush; cd ."
alias edit "eval -f \"get $0 -o ~/.lftp/edit.tmp.$$ && shell \\\"cp -p ~/.lftp/edit.tmp.$$ ~/.lftp/edit.tmp.$$.orig && $EDITOR ~/.lftp/edit.tmp.$$ && test ~/.lftp/edit.tmp.$$ -nt ~/.lftp/edit.tmp.$$.orig\\\" && put ~/.lftp/edit.tmp.$$ -o $0; shell rm -f ~/.lftp/edit.tmp.$$*\""
@mdpuma
mdpuma / kill_long_queries.sh
Created June 4, 2017 09:41 — forked from julcap/kill_long_queries.sh
Kill long MySQL queries
##################################################
# Kill long queries #
# This shell script will kill queries that have #
# passed the $MAX execution time. #
# Julian Capilla-krumbak #
# lyhan_jr@hotmail.com #
# 21-05-2014 #
##################################################
#!/bin/bash
@mdpuma
mdpuma / root-ro
Created December 9, 2017 17:40 — forked from kidapu/root-ro
Read-only Root-FS with overlayfs for Raspian
#!/bin/sh
#
# Read-only Root-FS for Raspian
#
# Modified 2016 by Stefan Bonfert to make it compatible with Raspbian
# Jessie (vanilla).
#
# Modified 2015 by Pascal Rosin to work on raspian-ua-netinst with
# overlayfs integrated in Linux Kernel >= 3.18.
#
/interface wireless channels
add band=2ghz-b/g/n width=20 list=2GHz/20MHz frequency=2412 name=ch1
add band=2ghz-b/g/n width=20 list=2GHz/20MHz frequency=2437 name=ch6
add band=2ghz-b/g/n width=20 list=2GHz/20MHz frequency=2462 name=ch11
add band=5ghz-onlyac width=20 list=5GHz/80MHz extension-channel=Ceee frequency=5180 name=ch36/38/42
add band=5ghz-onlyac width=20 list=5GHz/80MHz extension-channel=eCee frequency=5200 name=ch40/38/42
add band=5ghz-onlyac width=20 list=5GHz/80MHz extension-channel=eeCe frequency=5220 name=ch44/46/42
add band=5ghz-onlyac width=20 list=5GHz/80MHz extension-channel=eeeC frequency=5240 name=ch48/46/42
@mdpuma
mdpuma / WHMCSDecryptor.php
Created February 23, 2024 18:43 — forked from Wruczek/WHMCSDecryptor.php
Simple PHP script to decrypt WHMCS hashed strings
<?php
$encoded_string = "JATa2iUqVdzCkBP5RiyitlQlUiACl8UrpJOeGUJO";
$cc_encryption_hash = "SOmECRAZYLONGHASHROFLCOPTERBBQKTHX";
echo decrypt_whmcs($encoded_string, $cc_encryption_hash);
function decrypt_whmcs($encoded_string, $cc_encryption_hash) {
$key = md5(md5($cc_encryption_hash)) . md5($cc_encryption_hash);
$hash_key = _hash($key);
$hash_length = strlen($hash_key);