Skip to content

Instantly share code, notes, and snippets.

View andrewbrg's full-sized avatar

Andrew Borg andrewbrg

View GitHub Profile
@andrewbrg
andrewbrg / bot.detect.inc.php
Last active August 22, 2018 21:05 — forked from geerlingguy/crawler_detect.php
Detect crawlers/bots/spiders in PHP (simple and fast)
<?php
/**
* Check if a request originated from a crawler, spider, or bot.
*
* @param null|string $userAgent
* @param array $identifiers
* @return bool
*/
if (!function_exists('isBot')) {
function isBot($userAgent = null, $identifiers = array())
@andrewbrg
andrewbrg / loader.js
Last active November 27, 2018 22:30
Load remote JavaScript files programatically at runtime
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Allows you to load JavaScript files programatically from within other JavaScript files in your project.
//
// Instructions:
// 1. Include this file before all other scripts in your project.
// 2. Call jsLoader.load() or jsLoader.loadAsync() from within your scripts passing a single JS file path or
// array of multiple JS paths to load into your script at runtime.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const jsLoader = {
@samsamm777
samsamm777 / gist:7230159
Last active April 26, 2024 13:24
PHP set private property value using reflection. This allows you to set a private property value from outside the object, great for PHPUnit testing.
<?php
$a = new A();
$reflection = new \ReflectionClass($a);
$property = $reflection->getProperty('privateProperty');
$property->setAccessible(true);
$property->setValue($a, 'new-value');
echo $a->getPrivateProperty();
//outputs: