Skip to content

Instantly share code, notes, and snippets.

function slugify($s, $replacement = '-', $locale = null, $lower = false, $trim = true) {
$charMap = json_decode('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I",
@lutzissler
lutzissler / func.waitForWebfonts.js
Created October 15, 2013 13:34
Fire a callback when all provided webfonts have been loaded. Based on work by Thomas Bachem (http://stackoverflow.com/questions/4383226/using-jquery-to-know-when-font-face-fonts-are-loaded#11689060).
function waitForWebfonts(fonts, callback) {
var loadedFonts = 0;
for(var i = 0, l = fonts.length; i < l; ++i) {
(function(font) {
var node = document.createElement('span');
// Characters that vary significantly among different fonts
node.innerHTML = 'giItT1WQy@!-/#';
// Visible - so we can measure it - but not on the screen
node.style.position = 'absolute';
node.style.left = '-10000px';
@lutzissler
lutzissler / jquery.realwidth.js
Created October 14, 2013 12:50
jQuery realWidth plugin. Returns the real (sub-pixel, non-rounded) width of an element as stored internally in the browser. Thanks to ssorallen for the hint. See http://stackoverflow.com/questions/3603065/do-not-round-width-in-jquery#16072668 for context.
(function ($) {
$.fn.realWidth = function () {
var els = $(this);
return els.length ? els[0].getBoundingClientRect().width : null;
}
})(jQuery);
$.fn.reduce = function(fnReduce, initialValue) {
var values = this,
previousValue = initialValue;
values.each(function(index, currentValue) {
previousValue = fnReduce.call(currentValue, previousValue, currentValue, index, values);
});
return previousValue;
};
@lutzissler
lutzissler / jquery.layoutchanged.css
Created September 13, 2013 10:26
Watch responsive layout changes with the help of an additional element in the body and an appropriate color setting.
@media screen and (min-width: ...) {
// Adjust the breakpoint identifier so that jQuery knows about it
#bp {
color: rgb(1, 1, 1);
}
}
@media screen and (min-width: ...) {
// Adjust the breakpoint identifier so that jQuery knows about it
#bp {
@lutzissler
lutzissler / func.curl_file_get_contents.php
Created August 8, 2013 16:05
file_get_contents() replacement if HTTP fopen wrappers are not working.
// Grabbed from http://de3.php.net/manual/de/function.file-get-contents.php
function curl_file_get_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, str_replace(' ', '%20', $URL));
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
@lutzissler
lutzissler / func.listify.php
Created August 7, 2013 09:26
Smarty function to convert a list of arguments into a delimited output. Usage: {", "|listify:"Item 1":"Item 2":"Item 3"}
function listify($delimiter) {
return implode($delimiter, array_filter(array_slice(func_get_args(), 1)));
}
@lutzissler
lutzissler / jquery.findAndSelf.js
Created August 6, 2013 07:30
Filter() and find() combined.
// From http://forum.jquery.com/topic/jquery-jquery-way-for-filtering-self-all-children
$.fn.findAndSelf = function(selector) {
return this.find(selector).andSelf().filter(selector);
}
@lutzissler
lutzissler / jquery.fittext.js
Last active December 18, 2015 16:59
Shorten text to fit into a container.
(function ($) {
$.fn.fitText = function(options) {
var els = $(this),
options = $.extend({
ellipsis : "..."
}, options || {});
els.each(function () {
var el = $(this),
h = el.height(),
@lutzissler
lutzissler / close_all_files.sublime-keymap
Created June 3, 2013 11:33
Sublime Text 2 key binding for "File > Close All Files", bound to Ctrl+Cmd+W.
[
{ "keys": ["super+ctrl+w"], "command": "close_all", "args": {} }
]