Skip to content

Instantly share code, notes, and snippets.

<?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!");
<?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, '-');
@jrivero
jrivero / SimpleHTTPServerWithUpload.py
Created September 7, 2015 10:27
This module builds on BaseHTTPServer by implementing the standard GET and HEAD requests in a fairly straightforward manner.
#!/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.
"""
#!/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'
@jrivero
jrivero / JsonHandler.php
Created May 7, 2013 13:09
Handling JSON like a boss in PHP
<?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',
@jrivero
jrivero / var_dump.php
Created May 7, 2013 13:04
My personal minimalistic var_dump function
<?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;
@jrivero
jrivero / konami.js
Created April 2, 2013 10:42
Konami code with jquery
$(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")
@jrivero
jrivero / cachedHTMLForURL.php
Created September 24, 2012 11:12
Retrieve Google Cached HTML
<?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);
@jrivero
jrivero / hack.sh
Created March 31, 2012 13:32 — forked from erikh/hack.sh
OSX For Hackers
#!/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
#
@jrivero
jrivero / make_pretty.php
Last active February 21, 2024 11:34
Human redable sizes
<?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)));