Skip to content

Instantly share code, notes, and snippets.

@idanz
idanz / gist:6411301
Last active December 22, 2015 03:38
Knockout pauseable computed
###
inspired from http://www.knockmeout.net/2011/04/pausing-notifications-in-knockoutjs.html , with the following changes
1. Pause never causes trigger or computation
2. Resume only causes trigger if the computed dependencies were triggered while it was paused
3. Pause and Resume can be nested without any additional triggers or computation
###
ko.pauseableComputed = (evaluatorFunction, evaluatorTarget) ->
isPaused = ko.observable(false)
pauseCounter = ko.observable(0)
# Using this method ensures that when the counter goes from 1 to 2, the isPaused observable does not trigger again
@idanz
idanz / south_reset.py
Created September 27, 2012 17:30
Management command for resetting a certain app migration and creating a new initial migration
from optparse import make_option
from os.path import dirname, join, abspath, basename
import shutil
import subprocess
from django.core.management.base import AppCommand
class Command(AppCommand):
help = "Reset south migrations for app"
option_list = AppCommand.option_list + (
make_option('--soft',
@idanz
idanz / chained_cache.py
Created September 16, 2012 05:51
ChainedCache Backend for Django
from django.core.cache import BaseCache
from django.core.cache import get_cache
from lock_factory import LockFactory
class ChainedCache(BaseCache):
def __init__(self, name, params):
BaseCache.__init__(self, params)
self.caches = [get_cache(cache_name) for cache_name in params.get('CACHES', [])]
self.debug = params.get('DEBUG', False)