Skip to content

Instantly share code, notes, and snippets.

View RandomArray's full-sized avatar

Mike Johanning RandomArray

View GitHub Profile
@RandomArray
RandomArray / ucm-archive-bookmarklet.js
Created November 9, 2016 18:36
Bookmarklet javascript for Ultimate Client Manager. It triggers a click event on all "Archive" buttons. Avoid clicking every button individually as there is not an "Archive All" button in UCM.
javascript:(function()%7B%24('.socialtwitter_message_action').click()%7D)()
@RandomArray
RandomArray / select-state-v1.php
Last active November 9, 2016 09:55 — forked from solepixel/select-state-v1.php
PHP States Select
<?php
$selected = ' selected="selected"';
?>
<select name="state" id="state" class="form-control">
<option value=""<?php if(!isset($contact['state']) || empty($contact['state']))echo $selected; ?> disabled>State</option>
<option value="AL"<?php if($contact['state'] == 'AL')echo $selected; ?>>Alabama</option>
<option value="AK"<?php if($contact['state'] == 'AK')echo $selected; ?>>Alaska</option>
@RandomArray
RandomArray / update-url-titles.php
Created October 25, 2016 08:51
Updates / Refreshes all URL titles in YOURLS database.
<?php
// Updates all YOURLS' URL Page Titles
// 1) Change the database connection details below.
// 2) Update page titles from command line with: php -f update-url-titles.php
$db_host = 'localhost';
$db_name = 'database_name';
$db_user = 'username';
@RandomArray
RandomArray / testupload.php
Created October 7, 2016 21:32
Simple test for multiple file uploads.
<!DOCTYPE html>
<html>
<body>
<meta charset="utf-8">
<title>Test Multiple File Upload POST Request</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=1">
<form method="POST" enctype="multipart/form-data">
<!--<input type=file name="files[]" multiple>-->
<input type="file" name="uploads[]" multiple="multiple" accept="image/*">
<input type=submit value=Upload>
@RandomArray
RandomArray / stringContainsOnlyZeros.inc.php
Created October 2, 2016 21:17
Function returns true if string contains only zeros. Used to check for invalid serial numbers consisting of only zeros.
<?php
function stringContainsOnlyZeros($s){
return (is_numeric($s) && (int)$s===0);
}
@RandomArray
RandomArray / criticalcss.html
Created August 31, 2016 03:50 — forked from PaulKinlan/criticalcss.html
Detect Critical CSS
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<h2>Original CSS</h2>
<style style="display: block; white-space: pre; font-family: monospace">
h2 { margin:0; }
@RandomArray
RandomArray / ucm-archive-tweets.js
Created July 25, 2016 19:50
A quick script to run from the JavaScript console. Archives/clears the all tweets in UCM - Ultimate Client Manager, waits 3 seconds and reloads the current page. This is to avoid clicking on each individual `Archive` button.
function clearAllTweets(){
$('.socialtwitter_message_action').each(function(i) {
$(this).click();
$(this).remove();
});
}
var xx;
xx = setInterval(function(){
if($('.socialtwitter_message_action').length<=0){
clearInterval(xx);
@RandomArray
RandomArray / person_height.php
Created July 20, 2016 06:36
Generates HTML Select box for person's height in inches.
<?php
function personHeightOptions(){
$itotal = 95; $r = '';
for($foot=7;$foot>=3;$foot--){
for($inches=11;$inches>=0;$inches--){
if($inches==0){
$r .= "<option value='$itotal'> $foot' 0\" </option>";
}else{
$r .= "<option value='$itotal'> $foot' $inches\" </option>";
@RandomArray
RandomArray / import_csv_to_mysql_pdo.php
Last active June 22, 2021 23:23
Imports a CSV file into a MySQL database line-by-line. Displays output timer, a count, and ok/fail status. This was created to import a 200mb CSV file with over 200,000 rows. After many failed attempts to import (Out of Memory errors), I wrote this script.
<?php
ini_set('max_execution_time', 0);
header( 'Content-type: text/html; charset=utf-8' ); // Stream output
echo '<div id="o"></div>
<script> function u(m){var e = document.getElementById("o");e.innerHTML=m;} </script>';
$startTime = time();
define('DB_HOST','localhost');
define('DB_NAME','mytestdb');
define('DB_USER','username');
@RandomArray
RandomArray / random_delay_next_run.php
Last active February 15, 2016 00:33
Delays the next execution of the script by storing the next execution time in file and checking against it before continuing.
<?php
// Random time delay before next execution.
// Stores the next time in a file.
// Time is read from this file and compared against current time.
// If time has passed, perform another random delay between 1-59 seconds before execution.
$timeFile = 'nexttime.txt';
// $timeFile = dirname(__FILE__).'/nexttime.txt'; // Use this line for when running from CRON.
$minDelayMins = 1;
$maxDelayMins = 5;