Skip to content

Instantly share code, notes, and snippets.

Based on the pseudocode sample above, a `next/last/redo` could be executed on the second try,
without being executed in the first try, for *at least* the following reasons:
1. Initial transaction setup caused a retry with an unconditional `next/last/redo` in the body of the coderef
2. Some action in the coderef, before an unconditional `next/last/redo` caused a retry.
3. An unexpected or undesirable situation after a *skipped, conditional* `next/last/redo` causes a retry
(like optimistic locking failure). On the second try, conditions have changed (e.g. modification of data
in the database) and this changes the path taken by the code, triggering the *conditional* `next/last/redo`,
that wasn't triggered on the first try, due to different conditions in that run.
@Irfy
Irfy / tx_exec.pl
Last active April 19, 2019 09:02
Files to try out the problem and potential solutions to https://stackoverflow.com/questions/55752813/
#!/usr/bin/perl
use strict; # make sure $PWD is in your PERL5LIB
# no warnings!
use tx_exec qw(tx_exec);
tx_exec ("normal", sub { return "foobar"; });
tx_exec ("die", sub { die "barbaz\n"; });
tx_exec ("last", sub { last; });
import inspect
import ctypes
from time import sleep
from threading import Thread
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exctype):
exctype = type(exctype)
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exctype))
$ cat x.cc
#include<type_traits>
#include<utility>
using namespace std;
struct T {
T() = default;
T(const T&) {}
};
static_assert(is_move_constructible<T>(), "");
T a;
@Irfy
Irfy / x.cc
Created November 30, 2015 10:23
Demoing defaulted move ctor neither being generated nor called (see ImplicitDelete)
#include <utility>
#include <iostream>
using namespace std;
struct Explicit {
// prints whether the containing class's move or copy constructor was called
// in practice this would be the expensive vector<string>
string owner;
Explicit(string owner) : owner(owner) {};
Explicit(const Explicit& o) { cout << o.owner << " is actually copying\n"; }
@Irfy
Irfy / move.cc
Created November 29, 2015 20:07
Unintuitive move ctor behavior (gcc 5.2 in gnu++11 mode)
#define IMPLICIT_DELETE_MEMBER 0
#define DEFAULT_KEYWORD_INSIDE 0
#include <utility>
#include <iostream>
struct Explicit {
Explicit() = default;
Explicit(const Explicit&) { std::cout<<"Explicit-Copy called\n"; }
Explicit(Explicit&&) noexcept { std::cout<<"Explicit-Move called\n"; }
#include <iostream>
#include <vector>
#include <cstdio>
#include <unistd.h>
#include <pthread.h>
#include <termios.h>
using std::cout;
using std::getchar;
public class User {
public String[] usernames;
public User(String[] names) {
usernames = names;
}
public String[] getUsernames() {
return usernames;
}
@Irfy
Irfy / so9336486.java
Created February 18, 2012 01:12
An alternative to late binding of template arguments to template arguments, by pulling the early bound template arguments to bind later, at the same time with their template arguments.
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Vector;
interface Wrapped<T> {
void commonWrappedMethod();
}
class Wrapped1<T> implements Wrapped<T> {
@Irfy
Irfy / 9303362.py
Created February 17, 2012 00:47
Implement a cutoff window and a circular window on top of numpy's matrix.
"""
Demonstrates creating windows or views of two-dimensional arrays, in two ways:
* Cutting off parts of window that is outside
* Continuing windows on the opposite side (circular sliding)
'numpy' is a very useful numerical library for python which *already* supports
creating windows/views (actually sub-arrays, for multidimensional arrays). This
code demonstrates how to "wrap" such an underlying implementation to provide
specialized functionality.