This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Diagnostics; | |
using System.Collections.Concurrent; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Queue import Queue, Empty | |
from functools import wraps | |
from threading import Thread, Semaphore | |
ctrlc_queue = Queue() | |
exit_sem = Semaphore(0) # Read: there are 0 ctrlc threads on start-up | |
def needs_ctrlc(fun): | |
@wraps(fun) | |
def wrapped(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User { | |
public String[] usernames; | |
public User(String[] names) { | |
usernames = names; | |
} | |
public String[] getUsernames() { | |
return usernames; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <cstdio> | |
#include <unistd.h> | |
#include <pthread.h> | |
#include <termios.h> | |
using std::cout; | |
using std::getchar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
OlderNewer