Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am micalm on github.
  • I am micalm (https://keybase.io/micalm) on keybase.
  • I have a public key whose fingerprint is 9615 C3E4 BFAC F0DF 5763 57E4 E594 58D5 57BF 5E7F

To claim this, I am signing this object:

@micalm
micalm / ProsodyCakeAuth.php
Created March 26, 2015 09:37
PHP script designed to be used with mod_external_auth.
#!/usr/bin/php
<?php
error_reporting(0);
// Prosody log file path
$logFile = "/var/log/prosody/prosody.log";
$debug = false;
// CakePHP database config
$db = array(
'driver' => 'mysql',
@micalm
micalm / mysql-backup.sh
Created May 26, 2015 08:23
Dumps all mysql databases and emails them
#!/bin/sh
DIR=/root/mysql-backups/
DATESTAMP=$(date +%Y-%m-%d)
DB_USER=user
DB_PASS=password
find ${DIR} -type f -mtime +5 -exec rm -rf {} \;
DB_LIST=`mysql -u $DB_USER -p"$DB_PASS" -e'show databases;'`
@micalm
micalm / fixperms.sh
Last active October 3, 2018 07:25
Fix (most) file permissions
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
@micalm
micalm / .htaccess
Last active September 22, 2015 09:01 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@micalm
micalm / xhrdl.js
Last active October 3, 2018 07:29
XHR Download file
$("#saveAndDownload").click(function() {
var invoiceData = getJsonData();
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'SOME_URL', true);
xhr.responseType = 'arraybuffer';
xhr.setRequestHeader('X-CSRFToken', getCookie('csrftoken'));
xhr.send(JSON.stringify(invoiceData));
xhr.onload = function(e) {
var arr = new Uint8Array(this.response);
var raw = String.fromCharCode.apply(null,arr);
@micalm
micalm / iptables-block-by-country.sh
Last active October 3, 2018 07:26
Block IPs by country
#!/bin/bash
# Purpose: Block all traffic from RUSSIA (ru) and BELARUS (by). Use ISO code. #
# See url for more info - http://www.cyberciti.biz/faq/?p=3402
# Author: nixCraft <www.cyberciti.biz> under GPL v.2.0+
# -------------------------------------------------------------------------------
ISO="ru by"
### Set PATH ###
IPT=/sbin/iptables
WGET=/usr/bin/wget
@micalm
micalm / gist:eb58699a7d759625c5acfaa5455c4d16
Created December 20, 2016 08:45
Allow non-root program to run on ports < 1024
# Run as root or with sudo
$ sudo setcap 'cap_net_bind_service=+ep' /usr/bin/executable
@micalm
micalm / .htaccess
Created January 16, 2017 12:00
Cache/GZIP/DEFLATE .htaccess rules
Header unset Pragma
FileETag None
Header unset ETag
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"
@micalm
micalm / colors.sh
Created February 5, 2017 15:37
Shell Color Escape Code Variables
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHTGRAY='\033[0;37m'
DARKGRAY='\033[1;30m'
LIGHTRED='\033[1;31m'