Posts

Showing posts from 2013

New toys...

Unlike some of my prior posts showing expensive hardware that I got to play with, this time it is much more meager. I got a Raspberry Pi. This time, it really is a toy. I got one of the starter kits with an 8GB SD pre-loaded with several linux distros to try out and the clear case. If it works out, one more of those and I can put one in each of my sons' rooms. Very basic, yes... but that's exactly why I'd consider it for them. Hard to get in trouble when it doesn't get infected like windows and doesn't have TB of storage. So far, I'm pretty impressed with what it has to offer in a package smaller than many computer mice. I'm sure I'll be posting more about it soon.

Yii multiple select dropdownlist with default values

So I was coding a form in Yii, and came across a situation where I had a value of 0111110 (no, yes, yes, yes, yes, yes, no) that I needed to pre-populate values in a multiple select drop down. This didn't seem like it should be that hard, but the Yii documentation lacked a bit there. The first step was to split out the string. $optionValues = str_split($model->variable); Now, we create a blank array to hold our options. $options = array(); Then, we go through those options and set selected on the ones that need selected. foreach ($optionValues as $optionKey=>$optionVal) {      if ($optionVal) {         $options[$optionKey] = array('selected' => 'selected');     } } Now, we render the drop down list. echo $form->dropDownList($model, 'variable', array('0' => 'Zero', '1' => 'One','2'=>'Two','3' => 'Three', '4' => 'Four', '5' =...

Get "Null or Value" on related model in Yii

I have two tables, one with bases and one with transmitters. Bases work without transmitters, but transmitters don't work without bases. This means a HAS_MANY / BELONGS_TO relationship works out well in most cases. I recently ran into a two-fold problem. 1) I wasn't getting the null values from the related table when filtering on !=7. 2) If I added an OR statement, it ran really... really... really slow. The second was easily fixed by adding an index containing the joining field and the filtering field, but that still left the OR, which wasn't real efficient. The solution was coalesce in my search() function. $criteria->addCondition('coalesce(transmitters.field,0) != 7'); transmitters was the related table I was filtering on, and field was the field. Basically, anything that's null becomes a 0, so it's not a 7 (and not a null), so it shows up. Nothing too difficult this time, but hopefully it can save someone (probably me in a few weeks) s...

MySQL Query Times with Varying Batch Insert Sizes

I'm always curious how different things affect performance, so when I had to import 775 company records with around 30 fields, 26,681 base unit records with almost 90 fields and 30,197 transmitter records with over 100 fields into a MySQL database, it became time to do some testing. Initially, the process was taking a few seconds, but that was only a subset of the data. Once I got this larger set of data, it was taking 18:49 to import it, which wasn't acceptable. So, time to leave the straight "insert into ___ set ___=___" method that is so much more readable and move to "insert into ___ values ( __ , __ )" style. The first thing I did in testing was to disable indexes, insert, then enable indexes again. This brought the time down to 9:27, which is a big improvement, but still not where I wanted to be. Changing from set _=_ to values ( _ , _ ) made no real difference. Then, I changed to doing multiple records in a single pass, and what a difference t...

No longer in eCommerce

Since I'm no longer in eCommerce, I need a new blog title and about me text. Plus, since I'm developing stuff from scratch, I'm way more likely to write some code snippets on here. Time for some updates. Suggestions anyone?

A bit of CSS coding humor

/* because ellipsis is too hard to spell */ .dotdotdot { text-overflow:ellipsis; overflow: hidden; white-space:nowrap; }