Negation of Databinding in KnockoutJS

A common gotcha in KnockoutJS is negating an observable.

Most people would do the following:

<div class='center-block col-md-8 col-sm-8 col-xs-8' data-bind="visible: !isSearchPage">
    <div id="search-bar-page" type="text/html"><?php echo $this->fetch('search/search-bar.tpl.php'); ?></div>
</div>

The right thing to do is access it as a function:

<div class='center-block col-md-8 col-sm-8 col-xs-8' data-bind="visible: !isSearchPage()">
    <div id="search-bar-page" type="text/html"><?php echo $this->fetch('search/search-bar.tpl.php'); ?></div>
</div>

Goodluck!

ActiveRecord::ReadOnlyRecord: ActiveRecord::ReadOnlyRecord Solution

Weird Stuff eh? The ActiveRecord::ReadOnlyRecord: ActiveRecord::ReadOnlyRecord problem arises whenever you use a lot of SQL in your ActiveRecord queries.

Something like this will prompt that:

a = Product.joins('LEFT JOIN users ON products.user_id = users.id').where('products.user_id IS NULL')
a.destroy_all

This will immediately produce this error:

(0.2ms) BEGIN
(25.6ms) ROLLBACK
ActiveRecord::ReadOnlyRecord: ActiveRecord::ReadOnlyRecord

Solution

Use ActiveRecord.

a = Product.includes(:user).where('products.user_id IS NULL')
a.destroy_all

Good luck!

Run A Cron Job Every 30 Minutes

Here’s a crontab to run every 30 minutes.

0,30  * * * * php app/Console/cake.php send_emails

Bonuses

There are a few more templates for cron jobs

Every Wednesday

0 0 * * 3 php app/Console/cake.php send_emails

Every Monday, Wednesday and Friday

0 0 * * 1,3,5 php app/Console/cake.php send_emails

Run A Cron Job Everyday

Cron Jobs or Tasks are mostly done for jobs that are relatively regular. Here’s a crontab to run everyday.

Every midnight

00 00 * * * php app/Console/cake.php send_emails

Every noon

00 12 * * * php app/Console/cake.php send_emails

Every 6PM

00 18 * * * php app/Console/cake.php send_emails

Every 6PM

00 06 * * * php app/Console/cake.php send_emails

Good Luck!