Skip to content

Instantly share code, notes, and snippets.

View shengjie's full-sized avatar
😉

Shengjie shengjie

😉
View GitHub Profile
@CodeNegar
CodeNegar / gist:3713606
Created September 13, 2012 11:06
php: fuzzy time ago
<?php
function prettyDate($date){
$time = strtotime($date);
$now = time();
$ago = $now - $time;
if($ago < 60){
$when = round($ago);
$s = ($when == 1)?"second":"seconds";
return "$when $s ago";
}elseif($ago < 3600){
@tentacode
tentacode / index.html.twig
Created October 27, 2014 13:51
Calling twig macro dynamically with twig "attribute" method
{% import 'macro.html.twig' as macro %}
{{ attribute(macro, 'type_1', 'Foobar') }} {# <p>Type One Foobar</p> #}
{{ attribute(macro, 'type_2', 'Barfoo') }} {# <p>Type Two Barfoo</p> #}