Thursday, March 14, 2013

How do I make it so all future files and dirs have the permissions I want (for example, 775 rather than 755 for new directories) on a Mac OS X machine?

On your Mac OS X machine, create or open the following file via the following command:
sudo vim /etc/launchd-user.conf
Then, copy and past the following text into it:
umask 002
Then, restart your computer.

Sunday, March 10, 2013

What does PHP's print_r($_FILES) look like?

<?php
print_r($_FILES);
/*
THE ABOVE CODE OUTPUTS:
Array
(
    [image] => Array
        (
            [name] => aircraft war military fighter pilot cockpit planes vehicles jet aircraft 3000x1928 wallpaper_www.wallpaperhi.com_6.jpg
            [type] => image/jpeg
            [tmp_name] => /Applications/MAMP/tmp/php/phpzqf0Y6
            [error] => 0
            [size] => 383379
        )

)
*/

Saturday, March 9, 2013

How do I increase PHP's resource limits?

Check/edit your php.ini file for the following settings:
; Maximum amount of memory a script may consume (8MB).
memory_limit = 256M

; Maximum size of POST data that PHP will accept.
post_max_size = 32M

; Maximum allowed size for uploaded files.
upload_max_filesize = 32M

Friday, March 8, 2013

What does PHP's getimagesize function return?

<?php
$getimagesize = getimagesize('example/image/path/file.png');
print_r($getimagesize);
exit;
/*
THE ABOVE CODE OUTPUTS:
Array
(
    [0] => 1748
    [1] => 1165
    [2] => 2
    [3] => width="1748" height="1165"
    [bits] => 8
    [channels] => 4
    [mime] => image/jpeg
)
*/

How can I add an existing user to an existing group via the command line on a Mac OS X machine?

dseditgroup -o edit -u your_admin_username -p -a the_username_of_user_you_want_to_add_to_group -t user the_name_of_the_group_you_want_to_add_user_to
If I wanted to add myself to the "www" group I would simply run the following command:
dseditgroup -o edit -u johnerck -p -a johnerck -t user www
Run the groups command to see that you've been added:
groups

Wednesday, March 6, 2013

How can I determine the differences between two MySQL databases?

mysqldump --skip-comments --no-data -u your_user1 -p your_database_name1 > file_1.sql
mysqldump --skip-comments --no-data -u your_user2 -p your_database_name2 > file_2.sql
diff file_1.sql file_2.sql
Note that the first two lines may end up being identical except for the .sql file name at the end of the command (because databases that you want to compare often exist in independent environments). For example, you might run the first command locally and the second on a remote dev machine. In both instances your user may be root and your database name might be the name of your project. If you run the first command on your local machine and the second on a remote, you'll have to scp file_2.sql to your local machine before running the diff command. Enjoy!

Monday, March 4, 2013

How do I search multiple files for a specific word in one fell swoop?

# To list files that contain "the phrase"
grep 'the phrase' -li -r /etc
# To search for "the phrase" within a specific file
grep 'the phrase' /etc/httpd/conf/httpd.conf
This command is particularily useful if you're searching a folder full of MS Word docs. Word docs aren't plain text files (duh) and therefore don't get matched properly by most application level search features (e.g. TextWrangler).

The 'l' option is shorthand for '--files-with-matches'. Only the names of files containing selected lines are written to standard output.

The 'i' option is shorthand for '--ignore-case'. Omit this option if you do want your search to be case sensitive.

Lastly, the 'r' option is shorthand for '--recursive'. This tells grep to recursively search the subdirectories listed. This is key when you're interested in searching a folder full of docs (as opposed to an individual file).

About Me

My photo
I code. I figured I should start a blog that keeps track of the many questions and answers that are asked and answered along the way. The name of my blog is "One Q, One A". The name describes the format. When searching for an answer to a problem, I typically have to visit more than one site to get enough information to solve the issue at hand. I always end up on stackoverflow.com, quora.com, random blogs, etc before the answer is obtained. In my blog, each post will consist of one question and one answer. All the noise encountered along the way will be omitted.