Skip to content

Instantly share code, notes, and snippets.

@pospi
pospi / font-list-bullets.css
Created September 24, 2013 01:18
List bullets using font characters (best used with icon fonts!). Supported in everything except IE6 & 7, with graceful fallback.
ul {
list-style:none;
padding: 0 0 0 2em; /* padding includes space for character and its margin */
/* IE7 and lower use default */
*list-style: disc;
*padding: 0 0 0 1em;
}
ul li:before {
content: '\25BA';
@pospi
pospi / escaped-implode-explode.php
Created September 24, 2013 01:54
Like PHP's implode() and explode(), but lets you escape the delimiters for splitting the strings with.
<?php
/**
* Same as implode, but escape the separator when it exists in the array elements being imploded
* If the separator is longer than 1 character, only the first character need be escaped (not every character of the delimiter).
*
* @param string $sep delimiter to stich the array together with
* @param array $arr array to combine
* @param char $escape escape character to escape any found delimiters with
* @return imploded string
@pospi
pospi / string-bytelen.php
Created September 24, 2013 01:56
Get reliable byte length of a string in PHP. Works around an issue where the multibyte string extension can be configured to shadow strlen().
<?php
/**
* Works around an issue where the multibyte string extension
* can be configured to shadow strlen(), and no longer returns pure
* bytelength.
* @param string $str string to get byte length of
* @return int
*/
function bytelen($str)
{
@pospi
pospi / detect-numeric-arrays.php
Created September 24, 2013 01:58
Determine if a PHP array is numeric in the quickest way available.
<?php
function isNumeric($arr)
{
return array_keys($arr) !== range(0, count($arr) - 1);
}
@pospi
pospi / get-file-ext.php
Created September 24, 2013 01:59
Snippet to get the extension of a file with PHP in the fastest manner possible.
<?php
function extname($path)
{
return substr($path, strrpos($path, '.') + 1);
}
@pospi
pospi / placeholder-shim.js
Created November 4, 2013 09:50
Simple placeholder shim for IE. Functions slightly unlike browser placeholders in that the placeholder is removed immedately upon focus. To re-apply or activate elements added to the DOM post-render, simply call `.blur()` on them.
function initPlaceholderCompat()
{
var test = document.createElement('input'),
placeholderSupport = 'placeholder' in test;
if (placeholderSupport) {
return;
}
$(document).on('focus', '[placeholder]', function() {
@pospi
pospi / fix-wpmu-permastruct.php
Created December 5, 2013 04:41
Remove forced `/blog/` prefix added to main site permastruct in Wordpress multisite environments
<?php
global $WPMUPermastructFix;
$WPMUPermastructFix = new MultisitePermastructFix();
class MultisitePermastructFix
{
public function __construct()
{
// start the checking process for main multisite blog. Will strip forced '/blog/' from the start.
@pospi
pospi / em-font-size.less
Last active January 4, 2016 04:49
Calculate sizes in EMs easily by converting from other units
@BASE_FONT_SIZE : 16px;
// translate units by parent element ratio
.emsize(@property, @desired, @base : @BASE_FONT_SIZE) {
@{property}: 1em * (unit(@desired) / unit(@base));
}
// a wrapper for setting font size
.emfz(@desired, @base : @BASE_FONT_SIZE) {
.emsize(font-size, @desired, @base);
@pospi
pospi / wordpress-hostchange.sql
Created January 30, 2014 23:04
Some SQL for quickly moving WordPress sites between servers.
SET @FROMDOMAIN = 'myolddomain.com';
SET @TODOMAIN = 'mynewdomain.com';
SET @FROMSCHEME = 'http';
SET @TOSCHEME = 'http';
#-------------- STANDARD TABLES -------------#
UPDATE wp_options
@pospi
pospi / git-post-receive-deployment.sh
Last active August 29, 2015 13:55
A generic git post-receive hook for auto-deploying applications when pushed to.
#!/bin/bash
#------------------------------------------------------------------------------#
# CONFIGURATION
# You will need the following variables set in the git repository to deploy from:
# git config --bool receive.denyCurrentBranch false
# git config --bool core.bare false
# git config --path core.worktree [DEPLOYMENT_DIR]