Skip to content

Instantly share code, notes, and snippets.

View astockwell's full-sized avatar

Alex Stockwell astockwell

View GitHub Profile
astockwell /
Last active June 14, 2024 13:17
PHP Video Url Parser

Youtube/Vimeo Video Url Parser

Parses URLs from major cloud video providers. Capable of extracting keys from various video embed and link urls to manipulate and access videos in various ways.


astockwell /
Last active December 30, 2023 22:39
PHP Serialization Fix. For use after a find/replace/sed on MySQL dump, to repair String lengths in serialized PHP objects. Optimized and refactored for memory-safe production use in Python (~7s for 250MB dump, ~400K replacements). Written also in Perl (~7s for 250MB), Ruby (~8s for 250MB) and Go (~20s for 250MB) for benchmark comparison. Python …
astockwell /
Last active June 8, 2020 10:09
Decoding Oracle Raw(16), in Python 3 and Ruby 2
def split_into_chunks(string, chunk_length=2):
chunks = []
while len(string) > 0:
string = string[chunk_length:]
return chunks
def to_oracle_raw16(string, strip_dashes=True, dashify_result=False):
oracle_format_indices = [3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15]
if strip_dashes:
astockwell / wp-config.php
Last active May 19, 2019 23:03
One wp-config.php file to rule them all (multiple environments)
// One wp-config.php file for multiple environments setup from
if ($_SERVER['REMOTE_ADDR']=='' || $_SERVER['REMOTE_ADDR']=='localhost' || preg_match('/^192\.168\.5\./', $_SERVER['REMOTE_ADDR'])) {
define('WP_ENV', 'local');
} elseif ($_SERVER['HTTP_HOST']=='') {
define('WP_ENV', 'staging');
} else {
define('WP_ENV', 'production');
if ( WP_ENV == 'local' ) {
astockwell /
Last active April 30, 2019 14:59
Golang Worker (Toy) Example

Golang Worker (Toy) Example

Demonstrates an example of a work queue fanning-out work items to multiple concurrent workers (goroutines).

The work queue source is lines from a log file in this example, but can be anything. The number of workers is variable and can be adjusted from 1 to 100,000's. As of Go 1.5, the runtime uses all visible CPUs (whatever your operating system considers to be a CPU) to schedule concurrent goroutine execution.

In this example, "work" done on each log file line is simulated by the worker sleeping for a randomized # of seconds from 0-5. When running, you can observe that the workers pull "work" items in an unpredictable order (e.g. you never know which worker will get the next item) and they operate in parallel.

This example also includes 2 variables (dateDict and ipsToInvestigate) that multiple goroutines share and write to (potentially simultaneously), and thus must be protected by a mutex/semaphore (mu).

astockwell / index.php
Last active July 27, 2016 17:21
Teaching PHP: Basic principles to use PHP in Wordpress (with ACF)
* Discovering variables:
echo "string";
astockwell /
Last active March 28, 2016 22:49
The power of Trie's -- list search: 0.436379 seconds, trie search: 0.0003269999999999662 seconds.
import re
import string
import time
pattern_words_only = re.compile('[^A-Za-z0-9 ]+', re.UNICODE)
dictionary_words = [line.rstrip('\n') for line in open('/usr/share/dict/words')]
# print(len(dictionary_words))
two_cities = 'It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way - in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only. There were a king with a large jaw and a queen with a plain face, on the throne of England; there were a king with a large jaw and a queen with a fair face, on the throne of France. I
astockwell / index.html
Last active February 4, 2016 05:23
AddThis implementation (that actually works!) (add your AddThis analytics profile ID!)
<a class="addthis_button_facebook" target="_blank" href="<?php the_permalink(); ?>">Facebook</a>
<a class="addthis_button_twitter" target="_blank" href="<?php the_permalink(); ?>">Twitter</a>
<a href="" class="addthis_button">Share this</a>
<script type="text/javascript">
var addthis_config = addthis_config || {};
addthis_config.data_track_clickback = false; //tracking codes added to URLs after a share event
addthis_config.data_track_addressbar = false; //tracking codes added to URL in the address bar using JavaScript
addthis_config.ui_click = true; //open share panel on click (not hover)
<script type="text/javascript" src="//"></script>
astockwell /
Last active December 26, 2015 13:59
The following is an extraction of depricated methods from jQuery UI v1.9.2 as a quick-fix monkey-patch for the Wordpress Bannerize plugin to enable compatibility with the new jQuery UI v1.10 included in Wordpress v3.6. USE AT YOUR OWN RISK, BACK UP YOUR FILES & DATABASE. I do not advocate modifying core plugin files unless it is an emergency. NO…

Two files must be modified for this fix to work:

#	modified:   wp-content/plugins/wp-bannerize/js/jquery-ui.min.js
#	modified:   wp-content/plugins/wp-bannerize/js/jquery.timepicker.min.js
  1. Save everything else, ensure you are using source control, and backup your files and database!
  2. Replace the entire contents of wp-content/plugins/wp-bannerize/js/jquery.timepicker.min.js with the contents of the latest version.
  3. Replace the entire contents of wp-content/plugins/wp-bannerize/js/jquery-ui.min.js with the contents of jquery-ui.min.js from this gist.
astockwell / script.js
Created October 24, 2013 20:03
Enquire! "True" on line 46 activates this breakpoint for non-supporting browsers (IE!!!).
// ========================================================================== //
// Media Query JS support
// ========================================================================== //
mq_desktop = 620;
// Initial setup (all breakpoints)
$(document).ready(function() {
// Setup learnmore blocks