Skip to content

Instantly share code, notes, and snippets.

View abcarroll's full-sized avatar

A.B. Carroll III abcarroll

View GitHub Profile
@abcarroll
abcarroll / create_class.php
Created September 13, 2013 03:54
A simple one-time use function to generate the inside part of a PHP class based on functions from a text file. Pulls and uses the function's prototype/synopsis from the PHP manual, as well as adds the full prototype/synopsis and description in a comment. This makes it easy to convert procedural style PHP extensions into classes. Written specific…
<?php
/*
* Copyright (c) 2013, Armond B. Carroll III, ben@hl9.net
* This 'gist' (file) is distributed under the BSD 2-Clause License.
*
* This code will turn a function list into the inside part of a class, with
* the synopsis, and each member calling the original procedural style function.
* It was written to turn ncurses_* functions into a class.
*
* TO USE, load a text file into a file (ncurses.txt in this revision), with
@abcarroll
abcarroll / predis-dump-into-php
Created May 15, 2014 18:40
Dumps contents of a redis database relatively well into a text file via predis
<?php
/* Load predis object into $redis
here */
$out_file = 'REDIS-DUMP.txt';
$fp = fopen($out_file, 'w+');
echo "Starting... \n";
echo "KEYS... ";
$objects = $redis->keys("*");
Array functions:
array_search $needle, $haystack
in_array $needle, $haystack
String functions:
strchr $haystack, $needle
stripos $haystack, $needle
stristr $haystack, $needle
strpos $haystack, $needle
strrchr $haystack, $needle
@abcarroll
abcarroll / gist:23495fb510148fec1900
Last active August 29, 2015 14:02
.htaccess for gtmetrix (yslow/page speed)
# Expiration and compression
# This will generally improve gtmetrix (yslow/page speed) score at no expense.
ExpiresActive On
ExpiresByType image/x-icon "access plus 6 weeks"
ExpiresByType image/png "access plus 6 weeks"
ExpiresByType image/jpg "access plus 6 weeks"
ExpiresByType image/gif "access plus 6 weeks"
ExpiresByType image/jpeg "access plus 6 weeks"
ExpiresByType application/x-shockwave-flash "access 6 weeks"
@abcarroll
abcarroll / backup-rsync
Created June 7, 2014 13:49
Simple BTRFS Incremental
# A.B. Carroll ben@hl9.net
# File location in my setup:
# /media/zebra/launch-zebra-backup
# chmod +x /media/launch-zebra-backup
date > /media/zebra/last-backup.start
date >> /media/zebra/all-backup.start
rsync -avh --delete --progress /svn-migrate /media/zebra/
rsync -avh --delete --progress --exclude=/apps/php_errors.log /apps /media/zebra/
@abcarroll
abcarroll / popwindow.js
Last active August 29, 2015 14:03
Perform a window.open, centering it (even for dual monitor setups), and only allow one open instance of each identifier at a time
/*
Pops open a new window given the identifier (name), url, width, height, and
optional additional options (as normally passed to window.open()), centered
on the screen. Additionally, it will not open more than one instance of each
identifier.
Amalgamation of:
https://developer.mozilla.org/en-US/docs/Web/API/Window.open "Best Practices"
http://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen
"Single/Dual Monitor Function"
/*
* This clears the LESS.js cache, since it aggressively caches @import statements.
* Credit: Attaboy, https://gist.github.com/attaboy/1346280
* Additional key checks and debugging output by A.B. Carroll. (http://github.com/nezzario)
* License: Assumed MIT/BSD-like license, please give credit where credit is due.
*/
less.env = 'development';
console.log("If you are seeing this in a production environment you are likely doing something wrong or forgot to remove the destroyLessCache() script.");
@abcarroll
abcarroll / str_distance_array.php
Last active August 29, 2015 14:19
str_distance_array()
<?php
/* A.B. Carroll, public domain */
function str_distance_array($needle, $haystack) {
$confidence_map = [];
foreach ($haystack as $h) {
if(strlen($needle) < strlen($h)) {
$normalize = strlen($needle);
} else {
$normalize = strlen($h);
@abcarroll
abcarroll / go-lemp
Last active August 29, 2015 14:20
Install LEMP, Postfix, and PowerDNS
#!/bin/bash
packages=(
# > > System utilities
netselect-apt sudo rcconf parted
# > > Internet Services, Programming
nginx
php5-fpm php5-cli
mysql-server
# Beginnger
sudo apt-get install vim netselect-apt
# Basics
sudo apache2-utils autossh bc beep btrfs-tools cryptsetup curl dnsutils dos2unix e2fsprogs file ftp git hexedit hfsprogs htop iftop iotop iptraf less links lrzsz lvm2 md5deep mercurial nmap ntp parted patch pax putty-tools pv rsync screen sudo sysstat tmux tree vim wget whois xz-utils
# Paritioning, File System & FS Encryption
sudo apt-get install lvm2 cryptsetup e2fsprogs hfsprogs btrfs-tools
# Monitoring