Skip to content

Instantly share code, notes, and snippets.

View tassoevan's full-sized avatar
🏠
Working from home

Tasso Evangelista tassoevan

🏠
Working from home
View GitHub Profile
@tassoevan
tassoevan / slug-fn.php
Created March 26, 2014 17:10
Slugs in PHP
<?php
function slug($string)
{
$string = utf8_decode($string);
$string = html_entity_decode($string);
$string = strip_tags($string);
$string = strtr($string, utf8_decode('ÀÁÃÂÉÊÍÓÕÔÚÜÇàáãâéêíóõôúüç'), 'AAAAEEIOOOUUCaaaaeeiooouuc');
$string = preg_replace('/[^\\w\\d_\\s-]/si', '', $string);
$string = preg_replace('/\\s/', '-', $string);
$string = strtolower($string);
@tassoevan
tassoevan / interval-fn.php
Created March 26, 2014 17:11
Format time intervals in PHP
<?php
function interval($seconds, $granularity = 2)
{
$units = array(
'1 year|:count years' => 31536000,
'1 week|:count weeks' => 604800,
'1 day|:count days' => 86400,
'1 hour|:count hours' => 3600,
'1 min|:count min' => 60,
'1 sec|:count sec' => 1
@tassoevan
tassoevan / progress-fn.php
Created March 26, 2014 17:11
Show console progress bar
<?php
function progress($current, $total = null, $extra = null)
{
static $width = null;
static $startTime = null;
if ( $width === null ) {
if ( strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' )
$width = 80;
else
<?php
function galvao(array $a) {
$b = array('e', array_pop($a));
echo implode(', ', $a) . ' ' . implode(' ', $b);
}
function tassoevan(array $times) {
echo implode(', ', array_slice($times, 0, -1)), ' e ', end($times);
}
@tassoevan
tassoevan / composer.json
Last active August 29, 2015 14:06
Running Newman (Postman) as a Composer script for REST tests
{
...
"scripts": {
"newman": "php -S 127.0.0.1:8080 -t public_html public_html/index.php & newman -c tests.json.postman_collection -e environment.json && kill $!"
}
}
@tassoevan
tassoevan / teste.php
Created September 11, 2014 18:46
Tests on shorthand ternary operator in PHP
<?php
function first()
{
echo "#1\n";
return false;
}
function second()
{
echo "#2\n";
@tassoevan
tassoevan / detect-upload-errors.php
Last active August 29, 2015 14:06
How to detect uploads exceeding POST maximum size in Slim framework
<?php
$env = $app->environment();
if ($env['REQUEST_METHOD'] == 'POST') {
$contentLength = intval($env['CONTENT_LENGTH']);
$postMaxSize = ini_get('post_max_size');
if (preg_match('/^(\\d+)([PTGMK])$/iu', $postMaxSize, $matches)) {
$postMaxSize = intval($matches[1]);
switch (strtoupper($matches[2])) {
@tassoevan
tassoevan / post.html
Created October 16, 2014 15:59
Sculpin and inline markdown
<!-- I have this -->
<hgroup class="page-header">
<h1><a href="{{ site.url }}{{ page.url }}">{{ 'Using `DateTime` class' }}</a></h1>
</hgroup>
<!-- Rendering as -->
<hgroup class="page-header">
<h1><a href="/posts/using-datetime-class">Using `DateTime` class</a></h1>
</hgroup>
<!-- I want this -->
@tassoevan
tassoevan / jogo-do-guaiba.md
Last active August 29, 2015 14:17
Jogo do Guaíba

Jogo do Guaíba

Enquete

Vote | Resultados

Os títulos mais votados (até dez) formarão uma nova enquete, onde o autor do título vencedor ganhará um incrível prêmio!

@tassoevan
tassoevan / wma2mp3.sh
Created June 6, 2015 16:17
A script to convert a file in Windows Media Audio format to MP3
#!/bin/bash
# We need mplayer
if [ -z `which mplayer` ]; then
sudo apt-get install mplayer
fi
# We need lame
if [ -z `which lame` ]; then
sudo apt-get install lame