Skip to main content

Posts

Showing posts from February, 2017

Timeout function if it takes too long to finish in Python

import errno import os import signal import time class TimeoutError(Exception): pass class timeout: def __init__(self, seconds=1, error_message='Timeout'): self.seconds = seconds self.error_message = error_message def handle_timeout(self, signum, frame): raise TimeoutError(self.error_message) def __enter__(self): signal.signal(signal.SIGALRM, self.handle_timeout) signal.alarm(self.seconds) def __exit__(self, type, value, traceback): signal.alarm(0) with timeout(seconds=3): time.sleep(4)

Correlated Cross-Occurrence (CCO): How to make data behave

Cross-occurrence allows us to ask the question: are 2 events correlated. To use the Ecom example, purchase is the conversion or primary action, a detail page view might be related but we must test each cross-occurrence to make sure. I know for a fact that with many ecom datasets it is impossible to treat these events as the same thing and get anything but a drop in quality of recommendations (I’ve tested this). People that use the ALS recommender in Spark’s MLlib sometimes tell you to weight the view less than the purchase. But this is nonsense (again I’ve tested this). What is true is that *some* views lead to purchases and others do not. So treating them all with the same weight is pure garbage. What CCO does is find the views that seem to lead to purchase. It can also find category-preferences that lead to certain purchases, as well as location-preference (triggered by a purchase when logged in from some location).  And so on. Just about anything you know about users or c...

Backup WordPress Database And Filesystem Data On Linux With Scripts

f you’re like me, you run a WordPress blog and are terrified of the thought of something going wrong.  With core updates, theme updates, plugin updates, and server component updates, there is a lot of room for error.  This is where a WordPress backup could help ease your mind. WordPress recommends taking a backup of your blog before any of these are done and there are even some popular plugins that will do this for you.  For example, you could use the popular  UpdraftPlus  or similar, but I believe there is room for error in those as well.  While I could be wrong, I think WordPress must be in good shape for backup plugins to be successful. The alternative would be to create your own backup scripts that run on a cron schedule.  We’re going to see how to do this for WordPress instances running on a Linux machine. Creating the Backup Script There are two core components that need to be backed up in case of a catastrophe.  You need to back...