Skip to content

Instantly share code, notes, and snippets.

View franklinkim's full-sized avatar

Kevin Franklin Kim franklinkim

View GitHub Profile
@franklinkim
franklinkim / foomo-find-newer-files.php
Created September 25, 2012 10:00
Using find to find files newer than a specific one
# array of files to be compared to
$sources = array('/some/path/to/files', '/some/single/file.txt');
# the compared file
$filename = '/the/file/that/should/be/newer.txt';
# run find to check for newer files
$cmd = \Foomo\CliCall\Find::create($sources)->type('f')->newer($filename)->execute();
if (empty($cmd->stdOut)) {
\trigger_error('$filename is newer than the other files');
} else {
\trigger_error('some files are newer than $filename');
@franklinkim
franklinkim / gist:3706494
Created September 12, 2012 13:08
Git clone svn repository
# @see http://www.viget.com/extend/effectively-using-git-with-subversion/
git-svn clone -s http://example.com/my_subversion_repo local_dir
git-svn show-ignore > .gitignore
@franklinkim
franklinkim / foomo-remove-older-files.php
Created September 10, 2012 13:44
Using find to remove old temporary files
# find & remove files which modification date is older than 3*24 hours
\Foomo\CliCall\Find::create('/path/to/folder')-type('f')->mtime('+3')->delete()->execute();
# remove empty folders
\Foomo\CliCall\Find::create('/path/to/folder')-type('d')->addEmpty()->delete()->execute();
@franklinkim
franklinkim / server-chroot-environment.sh
Created September 10, 2012 13:14
Simple chroot without the need of jail or other packages
# Add a group for sftp only
$ addgroup sftponly
# Add a new user
# Note: We are using public key authentification, so leave the password blank
$ adduser USERNAME
# Add the user to the sftp only group
$ adduser USERNAME sftponly
@franklinkim
franklinkim / commands.sh
Created January 26, 2011 11:06
Permanently remove files and folders from a git repository
$ git filter-branch -f --tree-filter 'rm -rf <file>' HEAD
@franklinkim
franklinkim / commands.sh
Created January 26, 2011 09:49
Change permissions only for folders
$ find . -type d -exec chmod g+s {} \;
@franklinkim
franklinkim / gist:793688
Created January 24, 2011 18:41
Applying a patch
# move into correct folder
$ cd /path/to/base/dir
# apply patch with dry run
$ patch -p0 < PATCH_FILE.txt --dry-run
# apply patch
$ patch -p0 < PATCH_FILE.txt
# for more info
@franklinkim
franklinkim / Debug port forwarding
Created January 24, 2011 15:00
Debug port forwarding
$ ssh -R 9000:localhost:9000 you@server.com