Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / example.php
Last active February 10, 2021 21:01
PHP reading of sub directories for files using recursion and generators.
<?php
// using generators (yield) to recursively read files from a source path
// more: http://www.php.net/manual/en/language.generators.php
foreach (readFileSubDir('~/testdir') as $fileItem) {
echo($fileItem . "\n");
}
function readFileSubDir($scanDir) {
@magnetikonline
magnetikonline / README.md
Last active December 14, 2023 06:45
Nginx FastCGI cache configuration example.

Nginx FastCGI cache

Example /etc/nginx/nginx.conf using FastCGI (e.g. to PHP-FPM) with FastCGI cache enabled. This will capture returned data and persist it to a disk based cache store for a configurable amount of time, great for robust full page caching.

Will need to create a directory to hold cache files, for the example given here that would be:

$ sudo mkdir -p /var/cache/nginxfastcgi
$ chown www-data: /var/cache/nginxfastcgi
@magnetikonline
magnetikonline / test.php
Created March 28, 2014 03:33
Enabling PHP PCRE case insensitive searching for specific sections of your regular expression.
<?php
$testExpression = '/(?i)te(?-i)st/';
testPCRESectionOnly($testExpression,'test');
testPCRESectionOnly($testExpression,'TEst');
testPCRESectionOnly($testExpression,'teST');
testPCRESectionOnly($testExpression,'TEST');
/*
Should return:
@magnetikonline
magnetikonline / README.md
Last active August 29, 2015 13:57
Update WordPress database dump URL paths.

Update WordPress URL paths

PHP script that takes a mysqldump file and brute force replaces URLs into an output dump file.

Ensure to dump the source SQL database using the --skip-extended-insert switch to ensure INSERT INTO() statements don't end up on singular and very long lines, which won't help the script crunch all the replacements.

E.g.

$ mysqldump \
	-hlocalhost -uUSERNAME -p \
@magnetikonline
magnetikonline / gistreset.sh
Last active November 23, 2020 04:14
Truncate all previous history of a GitHub Gist.
#!/bin/bash -e
if [[ -z $1 ]]; then
echo "Usage: $(basename "$0") [Gist ID/SHA1]"
exit 1
fi
# create temp directory, clone Gist
gitTempDir=$(mktemp --directory "/tmp/gistreset.XXXXX")
git clone "[email protected]:$1" "$gitTempDir"
@magnetikonline
magnetikonline / gist:9497941
Last active August 29, 2015 13:57
Webalizer IgnoreAgent/SearchEngine rule sets conf - 2014-03
IgnoreAgent +http://www.baidu.com/search/spider.html)
IgnoreAgent ; 360Spider
IgnoreAgent ; Claritybot)
IgnoreAgent ; Google Web Preview)
IgnoreAgent ; Googlebot
IgnoreAgent Aboundex/*
IgnoreAgent Apache-HttpAsyncClient/*
IgnoreAgent Apache-HttpClient/*
IgnoreAgent AppEngine-Google*
IgnoreAgent Baiduspider*
@magnetikonline
magnetikonline / README.md
Last active August 17, 2016 22:54
Installing Sass 3.3.5 on Ubuntu 12.04LTS and above.

Installing Sass 3.3.5 on Ubuntu 12.04LTS

Uninstall anything ruby related

$ dpkg --list | grep ruby
$ sudo apt-get purge [ruby-package]
$ sudo apt-get purge [ruby-package]
$ sudo apt-get purge [ruby-package]
# etc...
@magnetikonline
magnetikonline / nexttick.js
Created March 9, 2014 10:04
Emulate Node.js's process.nextTick() method for the browser.
// creates a window.nextTick(handler) method with support for IE8+
// emulating Node.js process.nextTick() method
// http://nodejs.org/api/process.html#process_process_nexttick_callback
// note: IE8 will use a zero time setTimeout, which should fire within 4-10ms
(function(win) {
var NEXT_TICK_MESSAGE_NAME = 'next-tick',
nextTickHandlerList = [];
if (win.addEventListener) {
@magnetikonline
magnetikonline / README.md
Last active March 8, 2022 14:48
Check Linux filesystem for bad blocks.

Check Linux filesystem for bad blocks

List filesystem(s) to check

$ df -h

Will be listed as /dev/sdX1.