Skip to content

Instantly share code, notes, and snippets.

@flacodirt
flacodirt / App.config
Created September 26, 2013 22:09
/// Updates a .wxs or other text file containing a /// <?define version="..."?> preprocessor directive /// and increments the least-significant version /// grouping present and applicable to Major Upgrades.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
@flacodirt
flacodirt / keyup.php
Created June 24, 2013 14:44
Trigger only on word characters, backspace or delete and an entry size of at least 3 characters
// Search
$('#categoryFilter').on('keyup', function(event) {
var searchText = $(this).val();
var c = String.fromCharCode(event.keyCode);
var isWordCharacter = c.match(/\w/);
var isBackspaceOrDelete = (event.keyCode == 8 || event.keyCode == 46);
// Trigger only on word characters, backspace or delete and an entry size of at least 3 characters
if((isWordCharacter || isBackspaceOrDelete) && searchText.length > 2) {
console.debug('Searching for ' + searchText);
}
@flacodirt
flacodirt / getFileNameExt.php
Created May 31, 2013 13:06
Separate name and extension of given file
// Separate name and extension of given file
$fullFileName = 'my.example.file.ext';
$fileExt = substr($fullFileName, strrpos($fullFileName, '.') + 1);
$fileName = str_replace("." . $fileExt, "", $fullFileName);
/**
* Results:
*
* $fileExt = ext
* $fileName = my.example.file
@flacodirt
flacodirt / readme.md
Last active December 17, 2015 14:49 — forked from RaVbaker/readme.md

Redirect All Requests To Index.php Using .htaccess

In one of my pet projects, I redirect all requests to index.php, which then decides what to do with it:

Simple Example

This snippet in your .htaccess will ensure that all requests for files and folders that does not exists will be redirected to index.php:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

@flacodirt
flacodirt / post-receive.sh
Last active December 17, 2015 09:59
Git post-receive to publish website
#!/bin/bash
# @author brockhensley.com
# @url git clone https://gist.github.com/5591938.git
# store the arguments given to the script
read oldrev newrev refname
# Set Parameters
PROJECT=AWOMS
LOGFILE=./post-receive.log
@flacodirt
flacodirt / sendEmail.php
Created April 23, 2013 16:00
Send email in PHP using the mail function. Note the envelop wrapper includes the -f from address to ensure delivery.
/**
* sendEmail
*
* @param string $to
* @param string $from
* @param string $replyto
* @param string $cc
* @param string $bcc
* @param string $subject
* @param string $body
@flacodirt
flacodirt / clearhistory.sh
Created April 19, 2013 00:16
Clear bash history of any lines matching keyword
#!/bin/bash
#
echo '# @author brockhensley'
echo '# @version 1.0.0'
echo '# @date Last updated April 18th 2013'
echo '# @link brockhensley.com'
if [ -z "$@" ]
then
echo '#'
@flacodirt
flacodirt / provision_iptables.sh
Last active December 16, 2015 05:19
iptables provisioning script
#!/bin/bash
clear
clear
echo '#'
echo '# iptables Provisioning Script'
echo '#'
echo '# This script will guide you through the initial iptables firewall provisioning for a standard server.'
echo '#'
echo '# @author brockhensley'
echo '# @version 1.0.0'
@flacodirt
flacodirt / randomPassphrase.php
Created April 12, 2013 14:38
Random passphrase generator will return random characters 33 - 126
/**
* randomPassphrase
*/
function randomPassphrase ($len = 12) {
$r = '';
for ($i=0; $i<$len; $i++) {
$r .= chr(mt_rand(33,126));
}
return $r;
}
@flacodirt
flacodirt / PDO.php
Created April 7, 2013 16:47
PDO Database class in PHP
<?php
/*
* PDO Database class
*
* Usage:
* $db = Database::getInstance();
* Return array of query results, normal statement: $results = $db->query("SELECT * FROM test WHERE name = 'Bob'");
* Return array of query results, prepared statement (named params): $results = $db->query("SELECT * FROM test WHERE name = :name", array(":name" => "matthew"));
* Return int of last insert result row id: $db->lastInsertId()
* Return int of last query result row count: $db->lastQueryRowCount()