This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function slugify($string) { | |
$string = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $string); | |
$string = preg_replace('/[-\s]+/', '-', $string); | |
return trim($string, '-'); | |
} | |
echo slugify("Я люблю PHP!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Credit: http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php | |
function slugify($text) | |
{ | |
// replace non letter or digits by - | |
$text = preg_replace('~[^\\pL\d]+~u', '-', $text); | |
// trim | |
$text = trim($text, '-'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Simple HTTP Server With Upload. | |
This module builds on BaseHTTPServer by implementing the standard GET | |
and HEAD requests in a fairly straightforward manner. | |
""" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Alot of these configs have been taken from the various places | |
# on the web, most from here | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# Set the colours you can use | |
black='\033[0;30m' | |
white='\033[0;37m' | |
red='\033[0;31m' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://nitschinger.at/Handling-JSON-like-a-boss-in-PHP | |
class JsonHandler | |
{ | |
protected static $_messages = array( | |
JSON_ERROR_NONE => 'No error has occurred', | |
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', | |
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function vd($var, $return=false) | |
{ | |
$s = var_export($var, true); | |
$s = preg_replace( '/[^[:print:]]/', '',$s); | |
$s = preg_replace('#[ ]+#', '', $s); | |
$s = str_replace(array('array(', ')', '=>', ',]'), array('[', ']', ':', ']'), $s); | |
if ($return) return $s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var keys = []; | |
var konami = '38,38,40,40,37,39,37,39,66,65'; | |
$(document) | |
.keydown( | |
function(e) { | |
keys.push( e.keyCode ); | |
if ( keys.toString().indexOf( konami ) >= 0 ){ | |
console.log("konami code") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://hactheplanet.com/blog/11 | |
function cachedHTMLForURL($url) | |
{ | |
// Request the cache from Google. | |
$googleRequestURL = "http://webcache.googleusercontent.com/search?q=" . urlencode("cache:" . $url); | |
$googleResponse = file_get_contents($googleRequestURL); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://www.geekality.net/2010/11/17/php-output-a-number-of-bytes-in-a-human-readable-way/ | |
function make_pretty($bytes) | |
{ | |
$symbols = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); | |
$exp = floor(log($bytes) / log(1024)); | |
return sprintf('%.2f '.$symbols[$exp], $bytes/pow(1024, floor($exp))); |