Skip to content

Instantly share code, notes, and snippets.

@iforwms
iforwms / PHP: Escape HTML
Last active August 29, 2015 14:12
PHP: Escape HTML
// ESCAPE HTML CHRACTERS WHEN OUTPUTTING DATA FROM DB
function html_escape($raw_input)
{
return htmlspecialchars($raw_input, ENT_QUOTES, 'UTF-8');
}
@iforwms
iforwms / PHP: Create Secret Token
Last active August 29, 2015 14:12
PHP: Create Secret Token
// CREATE SECRET TOKEN
function generate_secure_token($length = 16)
{
return bin2hex(openssl_random_pseudo_bytes($length));
}
@iforwms
iforwms / PHP: Get 2D Array From CSV
Last active August 29, 2015 14:12
PHP: Get 2D Array From CSV
// PRODUCE A 2D ARRAY FROM CSV
function get2DArrayFromCsv($file, $delimiter)
{
if (($handle = fopen($file, "r")) !== false) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== false) {
for ($j = 0; $j < count($lineArray); $j++) {
$data2DArray[$i][$j] = $lineArray[$j];
}
$i++;
@iforwms
iforwms / PHP: Calculate Difference Between Timestamps
Created December 28, 2014 05:19
PHP: Calculate Difference Between Timestamps
// DIFFERENCE BETWEEN TWO TIMESTAMPS
// Time format is UNIX timestamp or PHP strtotime compatible strings
function dateDiff($time1, $time2, $precision = 6)
{
// If not numeric then convert texts to unix timestamps
if (!is_int($time1)) {
// $time1 = strtotime($time1);
}
if (!is_int($time2)) {
// $time2 = strtotime($time2);
@iforwms
iforwms / PHP: Remove Empty Values From Array
Created December 28, 2014 05:20
PHP: Remove Empty Values From Array
//RMEOVE ALL EMPTY VALUES FROM ARRAY
function arrayNonEmptyItems($input)
{
// If it is an element, then just return it
if (!is_array($input)) {
return $input;
}
$non_empty_items = array();
foreach ($input as $key => $value) {
@iforwms
iforwms / PHP: Replace CURL's Default exec_follow
Created December 28, 2014 05:36
PHP: Replace CURL's Default exec_follow
// REPLACE CURL'S DEFAULT exec_follow
function curlExecFollow($ch, &$maxredirect = null)
{
// we emulate a browser here since some websites detect
// us as a bot and don't let us do our job
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)"." Gecko/20041107 Firefox/1.0";
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$mr = $maxredirect === null ? 5 : intval($maxredirect);
@iforwms
iforwms / PHP: PHPmyAdmin Timeout
Created January 1, 2015 14:04
PHP: PHPmyAdmin Timeout
Set phpmyadmin timeout
add line to config.inc.php
$cfg['LoginCookieValidity'] = 28800;
@iforwms
iforwms / CapsLock-to-Escape
Created May 10, 2015 02:34
Remap the CapsLock key to the Escape
Capslock::Esc ; Remap Capslock to Esc and shift + CapsLock for normal CapsLock
+Capslock::
if GetKeyState("CapsLock", "T") = 1
{
SetCapsLockState, off
}
else if GetKeyState("CapsLock", "F") = 0
{
SetCapsLockState, on
}
var didScroll = false;
var html = document.body.parentNode;
var scrollOffset = 500;
var scrollingClass = 'scrolling';
window.onscroll = addClassToHtml;
function addClassToHtml() {
didScroll = true;
@echo off
setlocal EnableExtensions EnableDelayedExpansion
echo.
echo ============================================================
echo.
echo RANDOM FILE RENAMER
echo.
echo by Ifor Waldo Williams ^<ifor@designedbywaldo.com^>
echo.
echo.