OS X: replace tabs with spaces in all files using expand
We use four spaces (a.k.a. soft tabs) to indent our PHP files. If an errant developer has unknowingly used tabs, you can use expand to replace tabs with spaces across an entire project.
We use four spaces (a.k.a. soft tabs) to indent our PHP files. If an errant developer has unknowingly used tabs, you can use expand to replace tabs with spaces across an entire project.
If you call array_filter without a callback function, it’ll remove all array elements that evaluate to false (including zeroes).
$numbers = array(0, 1, 2, 0); echo array_filter($numbers);
Produces:
array(1,2);
I miss Ruby’s shorthand collect method to return an array of single attributes:
animals.collect(&:name)
…so I’ve created a (less elegant) equivalent for PHP.
class ArrayExtensions
{
/**
* From an array of objects, create a new array containing only
* a single attribute of each object
*
* Similar to array.collect(&:attribute) in Ruby
*/
public static function collect_by_attribute($attribute, $array_of_objects)
{
if (!is_array($array_of_objects))
{
return array();
}
$output = array();
foreach ($array_of_objects as $object)
{
if (is_object($object) && isset($object->$attribute))
{
$output[] = $object->$attribute;
}
}
return $output;
}
}
Use it like this:
$colours = ArrayExtensions::collect_by_attribute('colour', $animals);
…and you’ll get a simple array containing just the attribute you’ve specified:
array('brown', 'blue', 'green')
If you happen to be using PHP ActiveRecord, they have a function called collect that will accomplish the same thing.
$colours = ActiveRecord\collect($animals, 'colour');
You can’t use file_exists because it doesn’t search the include path.
fopen has a third argument that will check the include path, though:
if (@fopen('Log.php', 'r', true))
{
echo 'It exists!';
}
Rather than > or », use tee.
Redirecting the output of commands run with sudo requires a different approach. For instance considerFrom https://help.ubuntu.com/community/RootSudosudo ls > /root/somefilewill not work since it is the shell that tries to write to that file. You can usels | sudo tee -a /root/somefileto append, orls | sudo tee /root/somefileto overwrite contents.
Most new code is checked into the trunk. In general, our developers try to never “break the tree”. Anyone who checks in code which causes the trunk builds to fail will be the recipient of heaping helpings of trash talk and teasing until he gets it fixed. The trunk should always build, and as much as possible, the resulting build should always work. Most new code is checked into the trunk. The trunk is the place where active development of new features is happening. The trunk could be described as “basically unstable”. In our situation, the stability of the trunk build fluctuates over the months during our development cycle. During the early and middle parts of a development cycle, the trunk is often not very stable at all. As we approach alpha, beta and final release, things settle down and the trunk gets more and more stable. At the moment of release, a branch gets created. This branch becomes our maintenance tree for that release. Our current maintenance branch is called “3.0”, since that’s the current major version number of our product. When we need to do a bug fix or patch release, it is done in the maintenance branch. Each time we do a release out of the maintenance branch (like 3.0.2), we apply a tag. After the maintenance branch is created, the trunk once again becomes “basically unstable”. Developers start adding the risky code changes we didn’t want to include in the release. New feature work begins. The cycle starts over and repeats itself.From http://www.ericsink.com/scm/scm_branches.html
apache2ctl -t -D DUMP_VHOSTS
ls . | xargs -i -t cp ./{} /path/to/new/directory
See example 12-6 at http://www.homepage.montana.edu/~unixuser/051905/abs-guide/moreadv.html
add_column :facebook_user_id, :integer, :limit => 8 # BIGINT
Using screen is a great way to leave long-running processes churning away when you’re not logged into the machine.
screen
screen -r
If you’ve opened multiple screens, a list will be displayed:
There are several suitable screens on:
1681.ttys004.braeburn (Detached)
1686.ttys004.braeburn (Detached)
Just use the process ID of the screen to resume the right one:
screen -r 1681