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 <algorithm> // std::for_each<> | |
#include <array> // For test, but not necessary. | |
/* Prints the contents of some arbitrary array in order. Spaces are placed | |
* between each element. Note that the elements themselves are put onto the | |
* stream, so an overload of this operator should be provided for the element | |
* type of the array if it is not predefined by C++ or otherwise. | |
*/ | |
template <std::size_t N, typename 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
#ifndef CHRONO_UTIL_INCLUDED | |
#define CHRONO_UTIL_INCLUDED | |
#include <chrono> | |
#include <iostream> | |
template <typename Rep_Type, typename Dur_Period> | |
std::ostream& operator<<( | |
std::ostream& stream, | |
const std::chrono::duration<Rep_Type, Dur_Period>& dur) | |
{ |
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
/* | |
* FILE: print_tuple.cpp | |
* DESCRIPTION: Print the contents of a std::tuple<>. | |
* DATE: 06/25/2020 | |
*/ | |
#include <iostream> | |
#include <tuple> | |
template <int I=0, typename ...T> | |
void print_tuple( |
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
/* Simple code fragment to find the minimum element in an | |
* array. Unfortunately this cannot be templated without | |
* making it an actual function, so it only works with an | |
* array of ints. | |
*/ | |
auto find_min=[]( | |
int *begin, | |
int *end) | |
{ | |
auto *min_idx=begin, min_val=*begin; |
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
// A simple example of the DDA line-drawing algorithm using characters. | |
import static java.lang.Math.abs; | |
public class Main { | |
static class Frame { | |
private int w, h; | |
private char[][] frm; | |
Frame( |
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
// Absolutely disgusting. Don't do any of the things I do here. | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.ArrayBlockingQueue; | |
public class ABQ { | |
public static void main(String[] args) { | |
Thread x, y; |
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
// Don't even come @ me. I'm so tired rn. | |
Thread x, y; | |
CyclicBarrier b; | |
int[] a = new int[] | |
{ 1 | |
, 2 | |
, 3 | |
, 4 | |
, 5 |
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
// LOL, the blocking is so bad, but it allows you to see the threads | |
// at work. | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.concurrent.locks.ReadWriteLock; | |
import java.util.concurrent.locks.ReentrantReadWriteLock; | |
public class RWLocks { | |
private ReadWriteLock rw; |
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
// This is probably breaking a thousand best practices, but it works, so | |
// take it or leave it, buddy. | |
List<String> s; | |
Lock l; | |
Thread r, w; | |
Condition update; | |
Scanner sc; | |
s = new ArrayList<>(); |
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
// Hmm, interesting. If we never need to direcly call a method (requiring | |
// knowledge of the type which this set has been instantiated with), then | |
// there is no need to even provide a type! ...assuming you're fine working | |
// with an Iterator which returns Objects. Do note that this is not really | |
// any better than working with raw types, haha. | |
Set<?> so; | |
int i; | |
so = new TreeSet<>(java.util.Arrays.asList( | |
0, | |
1, |
NewerOlder