Skip to content

Instantly share code, notes, and snippets.

@sumpygump
Last active December 14, 2015 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumpygump/5108529 to your computer and use it in GitHub Desktop.
Save sumpygump/5108529 to your computer and use it in GitHub Desktop.

Remember

PHP

strpos(haystack, needle)
$leadingZero = sprintf("%02d", $string);
$currency = sprintf("%01.2f", $n);
error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1);

JavaScript

$(function() { ... }); // on pageload (jQuery)
if ($("#myid").length > 0) { /*element exists*/ }
window.location = "http://redirect.com"
history.go(-1);

*nix

create tar: tar czf <blah.tar> *
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
find . type f -name '*.php' -print0 | xargs -0 grep {pattern}
egrep -r -include=\*.php -h '@copyright' . | uniq -c | sort -nr
egrep -r -include=\*.php -L '@copyright' .
sdiff -stW file.ext.merge-left.rxx file.ext.merge-right.rxx
scp <filename> <user>@<domain>:<filepath> # Copies a file from local machine to server
scp <user>@<domain>:<filepath> <filename> # Copies a file from server to local machine
patch -p0 -i <patch-filename>
xmllint --format <filename> > <newfile>

git

Instead of using git pull --rebase, use a git fetch origin and git rebase -p origin/master

Subversion

svn propset svn:keywords "Id" filename.php
svn copy http://svn.example.com/trunk http://svn.example.com/branches/new-branch -m "Creating a private branch of trunk."
svn merge --ignore-ancestry
svn switch --force

Apache/htaccess

php_flag xdebug.profiler_enable on
php_flag xdebug.profiler_enable_trigger on
    (URL should have ?XDEBUG_PROFILE=1)
php_value xdebug.profiler_output_dir /home/xxx/public_html/log

lvh.me virtualhost setup (in /etc/apache2/sites-enabled/*):

RewriteCond %{HTTP_HOST} ^([^.]+)\.web\.lvh.me$
RewriteRule ^(.*)$     /var/www/%1/web/$1 [NC,L]

RewriteCond %{HTTP_HOST} ^([^.]+)\.public\.lvh.me$
RewriteRule ^(.*)$     /var/www/%1/public/$1 [NC,L]

RewriteCond %{HTTP_HOST} ^([^.]+)\.lvh.me$
RewriteRule ^(.*)$       /var/www/%1/$1 [NC]

Mysql

SET names utf8
show variables
mysql --default-character-set=utf8
show create table <tablename>

Server

To disable screen blanking on Ubuntu Server

sudo vim /etc/default/grub
# make sure that GRUB_CMDLINE_LINUX_DEFAULT contains "consoleblank=0"
sudo update-grub
# reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment