Skip to content

Instantly share code, notes, and snippets.

@idev247
idev247 / .bashrc
Created February 12, 2011 03:19
~/.bashrc tar extracting made easy
# found here http://ubuntuforums.org/showthread.php?t=1116012
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 && cd $(basename "$1" .tar.bz2) ;;
*.tar.gz) tar xvzf $1 && cd $(basename "$1" .tar.gz) ;;
*.tar.xz) tar Jxvf $1 && cd $(basename "$1" .tar.xz) ;;
*.bz2) bunzip2 $1 && cd $(basename "$1" /bz2) ;;
*.rar) unrar x $1 && cd $(basename "$1" .rar) ;;
<?php
// This function will return "now", "3 seconds ago", "1 month ago" etc ...
// example: echo 'posted ' . get_the_relative_time(mktime(date("H"), date("i"), date("s"), date("m")-1, date("d"), date("Y")));
function get_the_relative_time($time = null, $now = 20) {
if(is_null($time)) $time = date('U');
$time_diff = date("U") - $time; // difference in seconds
$second = 1;
@idev247
idev247 / gist:1286862
Created October 14, 2011 11:29
Delete all tags git (remote and local)
# Remove
for c in $(git for-each-ref refs/tags/ --format='%(refname)'); do echo $c; git push origin :$c; echo; done
# Local
for c in $(git for-each-ref refs/tags/ --format='%(refname:short)'); do echo $c; git tag -d $c; echo; done
@idev247
idev247 / gist:1292741
Created October 17, 2011 14:38
Git Tricks
Replace master by a branch
http://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch
Pull branch from different repo
http://help.github.com/fork-a-repo/
@idev247
idev247 / defaults.php
Created January 25, 2013 13:21
Trick to get options from default values.
<?php
class TestStuff {
private $defaults = array(
'color' => '#00ff00'
);
public function doIt() {
return $this->__request(array('color' => '#ff0000'));
@idev247
idev247 / php-tricks.php
Created February 28, 2013 23:18
Various PHP tricks: - Array - Find previous array element
<?php
/**
* Array: Find previous element (method 1)
* @source http://stackoverflow.com/questions/4792673/php-get-previous-array-element-knowing-current-array-key
*/
$array = array(
12 => array('a','b'),
34 => array('c','d'),
56 => array('e','f')