Zend DB Query Dump

June 25th, 2013

If you ever need to see the SQL that Zend DB has created, so that you can run it manually or any other reason, here’s how to do it.

[php]
// Turn on the profiler
$db->getProfiler()->setEnabled(true);

// Run your query
$db->update(‘someTable’, array(
‘thisField’ => 0.12551,
‘anotherField’ => ‘xxxxxxxxxxxx’
), ‘whatId = ‘ . $cdsDB->quote(‘james’));

// Output the last query
echo "\n" . $db->getProfiler()->getLastQueryProfile()->getQuery() . "\n";

// And the parameters for it
print_r($db->getProfiler()->getLastQueryProfile()->getQueryParams());

// Then turn the profiler off, unless you want to do more
$db->getProfiler()->setEnabled(false);

/*
And the output is

UPDATE `someTable` SET `thisField` = ?, `anotherField` = ? WHERE (whatId = 186459)
Array
(
[1] => 0.12551
[2] => xxxxxxxxxxxx
)
*/
[/php]

Strip Whitespace Out Of A File

June 6th, 2013

sed is a wonderful tool. Just used this command today to remove most of the whitespace from a file.

sed 's/ //g' test.txt > test2.txt

Faster Checked State jQuery

May 21st, 2012

http://jsperf.com/prop-vs-ischecked/4
Fastest by 98% is $el[0].checked; (in Chrome on Windows)

[code]// These will return true or false depending on the checked state of the HTML element
$(‘:checkbox[name=someCheckbox]’)[0].checked
$(‘:radio[name=someRadio]’)[0].checked[/code]

jQuery and Form Submit Breaking

May 10th, 2012

If you intercept the form submit with some jQuery and find that you can’t trigger the submit yourself with your script, you may need to check the name of your submit button. If you have a submit button named submit, jQuery will not be able to submit that form. You may also see the error “Uncaught TypeError: Property ‘submit’ of object # is not a function”.

The fix is simple of course. Change the button name.

Wrong: [code]<input type="submit" name="submit" id="confirm" value="Confirm">[/code]
Right: [code]<input type="submit" name="confirm" id="confirm" value="Confirm">[/code]

Hope that helps someone else.

Shift The Graph

February 19th, 2012

I have started working with an Arduino. For someone getting started in electronics, this device, and the community around it make it so much easier to learn. Within two minutes of plugging it in and starting the software, I was able to do something.

Fast forward a bit, this project is the first big project I have taken on. It is a 10 segment bar graph that I wired up, but now, I am moving it’s control from the 10 analog pins to some shift registers. This frees up most of the pins that I needed initially, and doesn’t make control more difficult.

A shift register is like a bucket brigade. Each bucket is one bit on the register, and as you pass it bits, the rest of them get passed one down the line. So, to control which legs of the shift register are powered and which not, I just have to pulse 1’s and 0’s into the register until I get it set the way I want. Since the LED segments are controlled by the shift register legs, they’re set by what is pulsed to the register.

If I want to have an alternating pattern, the registers contain these values
[code] [10101010] -> [10101010]
// Register 1 -> Register 2[/code]

If I were to push one more bit down the line, they would all move one step along.
[code] [01010101] -> [01010101]
// Register 1 -> Register 2[/code]

If I wanted to push the segments to all lit, the register just has to be fed 1’s.
[code] [11111111] -> [11010101]
// Register 1 -> Register 2[/code]


Part List

  • Arduino
  • 10 x 330Ω Resistors
  • 10 Segment LED bar graph or 10 x LED’s
  • 2 x 74LS164N Shift Registers (or any non-164 shift register, your wiring may be different)
  • Wires and Breadboards



Notes

  • For this project, I’m not using the reset ability of the 164, so that pin has been tied to V+.
  • There is an Arduino function called shiftOut() that would make this a little easier. I have not used it because I wanted to shift the bits myself to get a better feel for what it was doing.
  • To wire the shift registers to the Arduino, it’s pin 2 on the Arduino to the clock pin (pin 8) on the first or second shift register (since they’re both wired together), and pin 3 Arduino to data pin (pin 1) on the first shift register.




[code]
#define DATA 3
#define CLOCK 2

void setup() {
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT);

for(int i = 0; i < 10; ++i){
digitalWrite(DATA, LOW);
digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);
}
}

void loop() {
for(int i = 0; i < 10; ++i){
int hilo = random(0, 2);

switch(hilo){
case 0: digitalWrite(DATA, LOW); break;
case 1: digitalWrite(DATA, HIGH); break;
}

digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);
delay(50);
}
}
[/code]

WordPress - Entries (RSS) and Comments (RSS) - © 2011 Ben Dauphinee