12.31.2013

Happy New Year.

Ally and I celebrated by going to Montrose for some Colorado Boy pizza and to see the Hobbit in the Fox Cinema’s Penthouse theater. Then I got pulled over for being a padidle. I swear, the headlight went out only 2 minutes earlier.

No Comments »
date Dec 31st 2013
author Mike
category Photo
tags(none)
  No Comments »

12.30.2013

First day working remotely. For as much as I hate Skype, it’s an incredibly handy tool.

No Comments »
date Dec 30th 2013
author Mike
category Photo
tags(none)
  No Comments »

12.29.2013

We watched Yentl and Elf today. Elf has better singing parts, but I probably only think so because it’s Zooey Deschanel singing and not Barbra Streisand.

Also, Ally straightened AJ’s hair, and I set up my command station in the sleep loft. I can foresee myself banging out some pretty badass code from here.

No Comments »
date Dec 29th 2013
author Mike
category Photo
tags,
  No Comments »

12.28.2013

We live in Ridgway now. This is going to take a while to get used to.

A few things I learned:

  • I can’t pack my life into one box. It’s more like a dozen or so.
  • Ally is amazing, and is surprisingly good at rolling up a rug on her own.
  • Nicole has to be honest, even when playing Bullshit.
No Comments »
date Dec 28th 2013
author Mike
category Photo
tags,
  No Comments »

Git Dev

1. Checkout master code from github.

cd into development directory, then run:

git checkout -b development origin/master

This simultaneously pulls down the master, and switches you into a development branch on local server.

2. Develop on local dev server, and track on remote development branch.

Make changes and updates. Repeat the following as much as needed:

git add .
git commit -m "commit message"
git push origin development:development

This will create a secondary parallel branch in github.

3. Merge development with master in github.

git checkout master
git merge --no-ff development
git branch -d development
git push origin master
git push origin :development
No Comments »
date Sep 14th 2013
author Mike
category Geek
tags
  No Comments »

PHP: array_merge an array with itself

I recently wanted to merge an array with itself, duplicating all of its own elements and appending them to the original array, over and over until it was thousands of times its original size. It took me a little while to find the best way to do this, so I thought I’d share what I found.

Luckily, you can use PHP’s array_merge() function to double the original array’s size. For example:

$fruits = array( 'Apples', 'Oranges', 'Bananas', 'Strawberries' );
$fruits = array_merge( $fruits, $fruits);
echo implode( ', ', $fruits);

This yields: Apples, Oranges, Bananas, Strawberries, Apples, Oranges, Bananas, Strawberries

Awesome, we’ve made our 4 element array into an 8 element array. But what about making it much bigger? I was running speed tests, and wanted an array that had 10,000 elements or more,* so I needed to keep running these array merges. Doing array_merge( $fruits, $fruits, $fruits, ...) wouldn’t work since each additional argument only adds another 4 elements to the array.

The simplest thing to do is recursively duplicate the array, and compound the results. By doing this, the first iteration yields an 8 element array, the second has 16 elements, the third has 32, etc. Example of how to do this:

$fruits = array( 'Apples', 'Oranges', 'Bananas', 'Strawberries' );
for($i=0; $i<11; $i++) {
    $fruits = array_merge( $fruits, $fruits);
}

By running the for loop 11 times, you end up with an array with 8,192 elements, and increasing it to 12 your result has 16384 elements. If you need more elements, use the following equations to figure out how many times you need to loop through your array:

How many elements you'll end up with:

(2^[number of iterations]) * [starting array count]
Example:
(2^11) * 4 = 8192

How many times to loop to achieve a certain length:

ln( [desired final array count] / [starting array count] ) / ln(2)
Example:
ln( 10000/4 ) / ln(2) = ln(2500) / ln(2) = 11.3
Always iterate to the next highest integer, so 11.3 = 12 iterations

By using 12 iterations, you're sure to get at least 10,000. If you need a more exact number, you can always use array_splice() to truncate the result.

 

* For the speed test I was trying to manipulate database objects, and I only had 4 of them in the database. I wanted to see what would happen if I had tens-of-thousands of them in the database, hence the duplication.

No Comments »
date Jan 2nd 2013
author Mike
category Geek
tags, ,
  No Comments »