Monthly Archives: November 2014

Knockout Extender: filter

ko.extenders.filter = function (target, pattern) {
    var result = ko.computed({
        read: target,
        write: function (value) {
            if (typeof value !== "string") {
                target(value);
                return;
            }
            var current = target();
            var filtered = value.replace(pattern, "");
            if (filtered !== current) {
                target(filtered);
            } else if (value !== current) {
                target.notifySubscribers(filtered);
            }
        }
    }).extend({ notify: "always" });
    result(target());
    return result;
};

var x = ko.observable().extend({ filter: /[aeiou]/gi });
x("hello");
console.log(x());
x("WORLD");
console.log(x());

Output:

hll
WRLD

Mercurial and Upstream CVS with MQ

# Set up repo
cvs checkout repo
cd repo
hg init
>> .hgignore echo syntax: glob
>> .hgignore echo CVS/*
>> .hgignore echo .cvsignore
# Consult .cvsignore files
hg addremove
# Verify pending changes
hg commit -m "Upstream import."
hg init --mq
hg commit --mq -m "Initial import."

# Create patches
hg qnew -m MESSAGE PATCH
# Make changes
hg qrefresh -UD
# Repeat as needed

# Tag queue
hg qnew -m "Add tag TAG." TAG
>> .mqtags echo TAG
hg add .mqtags  # Only for the first tag
hg qrefresh -UD
# Now you can `hg qgoto TAG`

# Save queue
hg commit --mq -m MESSAGE

# Update from upstream
hg update qparent
cvs update
# Consult .cvsignore files
hg addremove
# Verify pending changes
hg commit -m "Upstream update."
hg update qtip
hg rebase
# Fix merge conflicts
hg commit --mq -m "Rebase to upstream."