Add a user to .htpasswd

echo -e “myuser:`perl -le ‘print crypt(“mypassword”,”abc12345abc”)’`” > ./.htpasswd

Comments

Delete all files matching a pattern within a directory recursively

find . | grep -r -e “SomeFilePrefix.*\.php” | xargs rm

Comments

yet another ~./vimrc

set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab number
nnoremap <F7> :tabp<Enter>
nnoremap <F8> :tabn<Enter>
nnoremap <F6> :bd<Enter>
nnoremap <F5> :tabnew<Enter>

set sessionoptions=blank,buffers,curdir,folds,globals,help,localoptions,options,resize,tabpages,winsize,winpos



Create Session:
:mksession /path/to/session/file.vim

Restore Session:
$ vim -S /path/to/session/file.vim

http://code.google.com/p/conque/
:source %

Comments

Mount remote system locally over ssh

with certificate authentication or password prompt
sshfs my_username@example.com:/home/my_user /mnt/my_remote_system  -o reconnect -o follow_symlinks -o allow_other

 

or with plain text password:

echo “my_password” | sshfs my_username@example.com:/home/my_user /mnt/my_remote_system  -o reconnect -o follow_symlinks -o allow_other -o password_stdin

Comments

Possible interview questions for a Senior PHP Web Developer

Below is just an informal list of possible questions to ask a more advanced PHP web developer. Please feel free to add more.
dns port?
SSL port?
what does the linux command dd do?
what does the linux command df do?
how many bits is an IPV6 address?
how many bits is an IPV4 address?
what's a factory?
what's a fascade? can you please give an example of when you would use one?
can you please explain, in simple terms using the whiteboard if necessary, what a reverse proxy is?
what are the four contexts in an nginx configuration file?
what git command would I use to remove all untracked files, ignored files and modified changes?
what git command would I use to update all submodules referenced in a project?
in php, please give two examples of methods that can be used to compensate for multiple inheritence
what is dependency injection? why would it be used? what are its advantages and disadvantages? 
please explain to us, in simple terms, what a IP bit mask is
what are four http headers used for caching?
can you name some alternative methods for caching?
can you please explain to me, as if I were an intermediate programmer, some of the gotchas of developing for web applications with more than one web server?



what is your preferred php library for image manipulation?
have you ever configured a load balancer?
have you ever written a php extension?
how many times have you compiled php from scratch?
how you used redis? can you explain what redis is and when you'd use it?
how familiar are you with web analytics?
can you please write a regular expression for me that will match a string starting at the beginning of the line, followed by five numeric digit, followed by any number whitespace characters, followed by a hyphen, followed by any number of whitespace characters and capturing the rest of the content of the line in a capturing group?

Comments

Drop Column If Exists in MySQL

IF EXISTS ( SELECT * FROM information_schema.columns WHERE table_name = 'country' AND column_name = 'created_at' AND table_schema = DATABASE() ) THEN
    ALTER TABLE `country` DROP COLUMN `created_at`;
END IF;
Because DROP COLUMN IF EXISTS isn't supported by MySQL.

Comments

Show All Columns on a MySQL Table

SELECT * FROM information_schema.columns WHERE table_name = ‘my_super_table_name’ AND table_schema = ‘my_super_database_name’;

Comments

Show All Indexes on a MySQL Database

SELECT TABLE_NAME, INDEX_NAME, COLUMN_NAME, CARDINALITY, INDEX_TYPE FROM information_schema.statistics WHERE INDEX_NAME != ‘PRIMARY’ AND table_schema = ‘my_super_database’;

Comments

Getting Started with Git

Below are some helpful links and tips for getting started with the Git version control system.

Git is rapidly becoming one of the most widely used version control systems is use today. Git is especially is open source projects as it allows for rapid merging: a feature not found in most version control systems. Git is also compact and FAST.

If you’re a developer, I encourage you to write open source software as a means of deliberate practice. Using Git in the context of open source will really help other contribute and use your work. I recommend github.com specifically. Even professionally, I think that Git’s market share will continue to rise and be more prevalent in the workplace.

After using subversion for years, I dropped it in favour of Git. And below are a few notes that I learned along the way that may make it easier for you to get started. I hope you find using as fun as I do.

Introduction

Here’s an excellent intro video. You should probably watch this first. There are two parts. http://excess.org/article/2008/07/ogre-git-tutorial/

 
Here’s a nice, short book on how GIT works. You may want to come back to this after you’ve played with the commands for a couple of days. But I do recommend coming back to it. It has lot of explanations that show how git works. I personally read this first. After reading it, I had a great grasp of the concepts which made it easier to memorize the commands.
http://peepcode.com/products/git-internals-pdf

//see my git links on my delicious account (note: there are 3 pages; some of the more useful ones are older links; the newer links are more advanced items, so you may want to skip them for now)
http://www.delicious.com/homer6/git

//Install Git on Ubuntu
sudo apt-get install git-core

 

Finding the Usage

//Run: git <command> –help to see usage on that command
//eg. git push –help

Some Common Commands

git clone -o github_remote https://github.com/jquery/jquery.git

git pull github_remote

git push github_remote github_branch_master

git push –all github_remote

git status

git commit -a -m “Fixed error with homepage not displaying the correct timezone.”

git add -i

 

//warning: destructive (like an svn revert); know what you’re doing first with this.

git reset –hard master

//add this bash alias to your ~/.bashrc file to be able to recursively add empty directories to a repository

alias git_add_empty_dirs=’find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;’

//turns on the shell colors for all working copies

git config –global color.ui always

//makes git status = git st

git config –global alias.st status

//create an alias to easily recursively update the submodules within a project

git config –global alias.subup “submodule update –init –recursive”

More Useful Git Resources

http://progit.org/book/

For people who have used SVN:
http://git.or.cz/course/svn.html

A Simple Workflow for using GIT in small teams
http://toroid.org/ams/git-central-repo-howto

Also, the git official website has a lot of resources…
http://git-scm.com/

Here’s a great article on rebasing:
http://www.randyfay.com/node/91

Comments

Create your own linux/mysql/php development box for Windows or Mac OS X

Download iso of ubuntu server edition 11
	http://www.ubuntu.com/download/server/download
Download VirtualBox
	http://www.virtualbox.org/wiki/Downloads


Install VirtualBox
	
Create a new VM with 1000mb ram and 20GB of storage
	- bridge the network connection
	- default install (enable openssh server)
	
$ sudo su -
$ visudo
$ vim /etc/network/interfaces
	auto eth0
	iface eth0 inet static
			address 192.168.7.55
			netmask 255.255.255.0
			gateway 192.168.7.1

$ /etc/init.d/networking restart
$ ifconfig
$ ping google.com  //confirms internet connectivity
$ apt-get update  //update package manager sources
$ apt-get install mysql-server  //install mysql
$ apt-get install apache2
$ apt-get install php5
$ php -v  //confirm php 5.3.5
$ apt-get install samba  //install samba
$ vim /etc/samba/smb.conf
	- enable (uncomment) [homes]
	- read only = no
	- create mask = 0775
	- directory mask = 0775
$ sudo smbpasswd myusername
$ /etc/init.d/smbd restart //restart samba service to apply changes
	- should be able to connect to your smb share via windows or mac (http://support.apple.com/kb/HT1568)
$ apt-get install git-core

Comments