Skip to content

Instantly share code, notes, and snippets.

@mrclay
mrclay / elgg_bootstrap_messages.css
Created July 4, 2012 02:45
Elgg system messages based on Twitter Bootstrap
.elgg-system-messages {
position: absolute; top: 0; left: 10px; right: 10px;
padding: 0;
max-width: none;
}
/* some styles borrowed from Twitter Bootstrap */
.elgg-message {
background: #D9EDF7;
color: #3A87AD;
@mrclay
mrclay / .gitignore
Created July 12, 2012 19:46
Gitignore PHP Starter
# ignore IDE/hidden/OS cache files
.*
*~
nbproject
nb-configuration.xml
Session.vim
*.tmproj
*.tmproject
tmtags
Thumbs.db
@mrclay
mrclay / README.md
Last active October 8, 2015 17:08
Starter README file for new projects

Name

Name is ...

Requirements

  • PHP 5.3

Installation & Deployment

@mrclay
mrclay / .htaccess
Created August 22, 2012 13:44
Shibboleth auth Apache config
#### Shib auth provides access control, attributes in $_SERVER
#
AuthType shibboleth
ShibRequireSession On
Require attrname VALUE1
Require attrname VALUE2
# optional
#ShibRedirectToSSL 443
@mrclay
mrclay / TypedArray.php
Created October 22, 2012 13:27
Generics in PHP experiment
<?php
namespace MrClay\Generics;
use Exception;
use InvalidArgumentException;
class TypedList extends \SplDoublyLinkedList
{
/**
@mrclay
mrclay / index.php
Created November 1, 2012 21:06
Generate a string for testing truncation by bytes/characters
<?php
/**
* Generate strings for testing truncation by bytes/characters
*
* E.g. paste this into a form field:
* "€€€€€.... 10....... 20....... 30....... 40....... 50....... 60....... 70....... 80......."
*
* If this is returned: "€€€€€.... 10....... 20...." you'll know the system is truncating to either
* 26 UTF-8 characters or 36 bytes (the five Euros comprise 15 bytes).
*/
@mrclay
mrclay / river_bump.php
Last active December 12, 2015 01:48
On an Elgg comment, bump the original "create" river item to the top instead of adding a separate river item.
<?php
elgg_register_plugin_hook_handler('creating', 'river', function ($h, $t, $v, $p) {
$time = time();
// Bump "create" river item to top
// @todo should bump other action_types?
$dbprefix = elgg_get_config('dbprefix');
update_data("
UPDATE {$dbprefix}river
<?php
/**
* This has been moved to a GitHub project:
*
* @link https://github.com/mrclay/elgg-url-sniffer
*/
@mrclay
mrclay / HttpTitleSniffer.php
Created February 22, 2013 21:49
Crudely sniff the title of a web page reading as few bytes as possible
<?php
namespace UFCOE;
/**
* Sniff the title of a web page by reading as few bytes as possible.
*
* Warning, this is blissfully unaware of character encodings so that it can be fast. It only returns a string
* if the markup appears ASCII compatible, but you could get back UTF-8, Windows-125*, ISO-8859-*, etc.
*/
@mrclay
mrclay / LocationValidator.php
Created March 18, 2013 17:34
Validate a user-given URL for use in a Location HTTP header (to avoid be abused as an open redirect)
<?php
namespace UFCOE;
/**
* Validate a Location HTTP header value. By default this allows
* most URLs that are in the same origin, but allows switching between HTTP/HTTPS.
*
* @todo tests, dummy!
*/