Skip to content

Instantly share code, notes, and snippets.

@idev247
idev247 / php-tricks.php
Created Feb 28, 2013
Various PHP tricks: - Array - Find previous array element
View php-tricks.php
<?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')
@idev247
idev247 / defaults.php
Created Jan 25, 2013
Trick to get options from default values.
View defaults.php
<?php
class TestStuff {
private $defaults = array(
'color' => '#00ff00'
);
public function doIt() {
return $this->__request(array('color' => '#ff0000'));
View gist:1292741
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 / gist:1286862
Created Oct 14, 2011
Delete all tags git (remote and local)
View gist:1286862
# 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
View get_the_relative_time.php
<?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 / .bashrc
Created Feb 12, 2011
~/.bashrc tar extracting made easy
View .bashrc
# 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) ;;