Tuesday, June 21, 2016

Javascript's Round vs PHP's Round

Today I learned that by default PHP rounds differently than javascript.

PHP (using the default PHP_ROUND_HALF_UP)

php > echo round(-1.5);
"Round val up to precision decimal places away from zero, when it is half way there. Making 1.5 into 2 and -1.5 into -2."


"For negative numbers, if the decimal portion is exactly -0.5, the return value is the smallest integer that is greater than the number."

Saturday, May 21, 2016


It would be nice if there were a sqlalchemy/flask equivalent to this: https://github.com/dominno/django-moderation

The equivalent might use sqlalchemy_utils for its generic relationships: https://sqlalchemy-utils.readthedocs.io/en/latest/generic_relationship.html

Thursday, May 19, 2016

Modified Preorder Tree Traversal

This was a great explanation of Modified Preorder Tree Traversal (or MPTT): https://www.sitepoint.com/hierarchical-data-database-2/

A common use-case for MPTT is categorization data, like with the way django-oscar uses django-mptt: https://github.com/django-mptt/django-mptt

Sunday, May 8, 2016

Datatables - Uncaught TypeError: Cannot read property 'style' of undefined

If you see this error in datatables: "Uncaught TypeError: Cannot read property 'style' of undefined"

It's likely that you're missing a header column in your table. Make sure you have the same number of <th> elements as items in the "columns" section of your datatables initialization.

Select2 Replacement

This selectize.js library looks like a good replacement for Select2: https://selectize.github.io/selectize.js/

Wednesday, May 4, 2016

Javascript Data Tables