Recursive directory merge
Problem: I have two directories that are similar in structure but different in content. Say one is an older snapshot of the other. I want to copy the stuff from the new directory into the old directory (recursively).
Copy:
rsync -a SOURCE/ DEST/ --ignore-existing --whole-file
Move (no clobber):
rsync -a SOURCE/ DEST/ --remove-sent-files --ignore-existing --whole-file
Move (and clobber):
rsync -a SOURCE/ DEST/ --remove-sent-files --whole-file
Move, but only update with newer:
rsync -a SOURCE/ DEST/ --remove-sent-files --update --whole-file
Git: Recovering a file that you deleted
You might be doing some spring cleaning to your source code, or you might move files around that you think are unnecessary. Later on, you realize that one of the files you removed was a dependency. Now what? For this, we use git checkout.
If this is you:
...edit files... git add edited-file git commit -m "made changed" git rm seemingly-useless-file git commit -m "removed unreferenced dependency" ... edit file ... realize you dynamically included that file elsewhere..
Then you can simply follow up with:
git checkout 0a323 // the previous revision (hash from `git log`) cp seemingly-useless-file seemingly-useless-file.1 git checkout master mv seemingly-useless-file.1 seemingly-useless-file git add seemingly-useless-file git commit -m "Restored seemingly-useless-file"
You may want to git blame yourself while you’re at it.
If you know of a better way, please let me know.
Untrack Files with Git
When I found this little gem, I couldn’t not (double negative for emphasis) store it for reference.
git rm --cached filename
Don’t worry, it won’t remove your local copy. It just stages it for removal from the history of tracked files.
Reference:
untrack files in git
PHP/GD Bug: imageFilledEllipse Centered on Y=0
I was drawing circles using PHP’s GD function imageFilledEllipse. I noticed that when I went to draw a circle having its center at $y=0,there would be a line missing at $y=1.
Here’s the work-around:
if( -1 <= $py && $py <= 1 ) { // Undocumented PHP bug when Y coordinate is zero. imageFilledEllipse($img,$px,$py,$X,$X,$color); imageFilledRectangle($img,$px-$halfX,$py-1,$px+$halfX,$py+1,$color); } else { imageFilledEllipse($img,$px,$py,$X,$X,$color); }
PHP Version:
PHP 4.3.9 (cgi) (built: Apr 1 2009 10:41:42) Copyright (c) 1997-2004 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
$ yum search php-gd
php-gd.i386 4.3.9-3.26 installed Matched from: php-gd The php-gd package contains a dynamic shared object that will add support for using the gd graphics library to PHP.
Wordpress Plugins – Playground
I just installed wp-syntax and wp-terminal and want to see a demo. Read more …
STDERR redirect into STDOUT redirect into file
When you want to redirect stderr to a file, you have choices. Either redirect only stderr to a file, or redirect both stderr and stdout to the same file.
The right way:
Redirect stderr and stdout to [[file]]:
[[command]] > [[file]] 2>&1
Redirect stderr to [[efile]] and stdout to [[file]]:
[[command]] 2> [[efile]] > [[file]]
The wrong way:
Doesn’t do anything useful:
[[command]] 2>&1 > [[file]]