jquery – Replace Source query string value without redirecting

If you are working with browsers that support the HTML5 History API, you could use replaceState:

$(document).ready(() => {
    var redirectUrl = _spPageContextInfo.webAbsoluteUrl + "/" + _spPageContextInfo.layoutsUrl + "/Redirect.aspx";

    var queryParameters = {}, queryString = location.search.substring(1), re = /((^&=)+)=((^&)*)/g, m;

    while (m = re.exec(queryString)) {
        queryParameters(decodeURIComponent(m(1))) = decodeURIComponent(m(2));
    }

    queryParameters('Source') = redirectUrl;

    var updatedParams = location.search.replace(location.search, $.param(queryParameters));

    if (history.replaceState) {
        var newurl = window.location.origin + window.location.pathname + "?" + updatedParams;
        window.history.replaceState({ path: newurl }, '', newurl);
    }
});

However, if you are trying to modify the source on a form in SharePoint, that won’t be sufficient. Some onclick events are populated when the page loads with the initial Source value and these events will have to be override as well since they will redirect to the previous value:

$("#part1").on("click", "input(value='Cancel')", function (e) {
    e.preventDefault();
    window.location.href = redirectUrl;
});

$("#Ribbon.ListForm.Edit.Commit.Cancel-Large").click(function (e) {
    e.preventDefault();
    window.location.href = redirectUrl;
});

java – URLify a given String – replace spaces with %20

Your code does what you describe, but the code does not what it is really supposed to do.

You are not the first person ever who needs to convert an arbitrary string into a form that can be embedded in a URL. Several people before you have already solved this problem. The crucial point is to know how these people named the method or function or class or module where they implemented this function.

In Java, most network-related things are in the package java.net, and since URLs and URIs are network-related, they are there as well. Directly next to the classes URL and URI you will find the class URLEncoder that does all the work for you, including several edge cases you probably never heard of. Using this heavily tested and well-known piece of code is much better than rolling your own.

Hmmm, a pretty heavy down-side of Java’s URLEncoder is that it is old and dusty and probably will not be updated anymore. It does not even encode spaces as %20, but as +, and the + is something that only works in the query string part of a URL.

This Stack Overflow answer describes the bad API that standard Java is providing for this use case. The encoding part of this answer to that question is good, the general Java approach is bad, as I wrote in the comment below that answer. So be careful and don’t copy that code blindly.

Erase history change history lose information replace information algorithm as a person

We cannot change the history of a person because we cannot travel back in time. Suppose that the person were a computer algorithm. Suppose there were a computer matrix, like a noncommutative math matrix. Is the Cloud like that? Could we completely delete and erase something in the algorithm, and by doing so erase its history, and then replace it with an alternative history? Can information be permanently lost? Can lost information be replaced by new information put in its place?

c++ – Replace while(true); with std::condition_variable

I am trying to replace in an adapted code from internet, a tread pooling class, named ThreadPool:

void ThreadPool::Wait()
{
    // we're done waiting once all threads are waiting
    while (m_threads_waiting != m_threads.size())
    {
        ;
    }
}

where m_threads_waiting is defined as:

std::atomic<size_t> m_threads_waiting{ 0 };

and m_threads is defined as:

std::vector<std::thread> m_threads;

The replacing code is:

void ThreadPool::Wait()
{
    std::unique_lock<std::mutex> lock{ m_wait_mutex };
    m_threads_done.wait(lock, (&)()
                                {
                                    return m_threads_waiting != m_threads.size();
                                });
    lock.unlock();
}

where m_wait_mutex is defined as:

std::mutex m_wait_mutex;

and m_threads_done is defined as:

std::condition_variable m_threads_done;

The code is self-explanatory, the Wait() method should “wait” until all threads are done. And this method is called on main thread. Please tell me the the replaced code is correct and it is better than the old one.

replace with graphics

I was wondering whether the Moderator and Admin tab could be provided with a graphic.
If so, where and how would it work?

.

bitcoin core – Will “Taproot” replace Lightning Network?

With respect to the original Wording of the Question I believe Taproot will actually make the Lightning Network Pointfull instead of Pointless.

While Taproot allows us to save some space on the bitcoin base layer it will not make the lightning network obsolete. Remember the main issue with respect to onchain scaling is that a protocol where every transaction is broadcasted to every participant is just to inefficient if transactions should represent a substantial fraction of monetary payments in the world.

With respect to the Lightning network there are actually many improvements possible for the Lightnign network if Taproot is activated. Most notably the fact that we can have Point Time Lock Contracts instead of HTLCs which give us a way more flexibility in the payment process as addition of points and secrets is linear where as payment hash addition and secrete addition is not linear eg:

H(r1+r2) != H(r1) + H(r2)

The property of linearity allows us to have applications like

  • stuckless payments
  • payment deceolleration
  • escrow services

python – Pandas replace rare values in a pipeline

A common preprocessing in machine learning consists in replacing rare values in the data by a label stating “rare”. So that subsequent learning algorithms will not try to generalize a value with few occurences.

Pipelines enable to describe a sequence of preprocessing and learning algorithms to end up with a single object that takes raw data, treats it, and output a prediction. scikit-learn expects the steps to have a specific syntax (fit / transform or fit / predict). I wrote the following class to take care of this task so that it can be run inside a pipeline. (More details about the motivation can be found here: pandas replace rare values)

Is there a way to improve this code in term of performance or reusability ?

class RemoveScarceValuesFeatureEngineer:

    def __init__(self, min_occurences):
        self._min_occurences = min_occurences
        self._column_value_counts = {}

    def fit(self, X, y):
        for column in X.columns:
            self._column_value_counts(column) = X(column).value_counts()
        return self

    def transform(self, X):
        for column in X.columns:
            X.loc(self._column_value_counts(column)(X(column)).values
                  < self._min_occurences, column) = "RARE_VALUE"

        return X

    def fit_transform(self, X, y):
        self.fit(X, y)
        return self.transform(X)


if __name__ == "__main__":
    import pandas as pd

    sample_train = pd.DataFrame(
        ({"a": 1, "s": "a"}, {"a": 1, "s": "a"}, {"a": 1, "s": "b"}))
    rssfe = RemoveScarceValuesFeatureEngineer(2)
    print(sample_train)
    print(rssfe.fit_transform(sample_train, None))
    print(20*"=")

    sample_test = pd.DataFrame(({"a": 1, "s": "a"}, {"a": 1, "s": "b"}))
    print(sample_test)
    print(rssfe.transform(sample_test))