Skip to content

Instantly share code, notes, and snippets.

View lanesurface's full-sized avatar
😅
Butchering some code

Lane Surface lanesurface

😅
Butchering some code
View GitHub Profile
#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>
@lanesurface
lanesurface / chrono_util.hpp
Last active July 6, 2020 03:01
Various things that should have been included in <chrono>
#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)
{
/*
* 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(
/* 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;
// 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(
// 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;
// Don't even come @ me. I'm so tired rn.
Thread x, y;
CyclicBarrier b;
int[] a = new int[]
{ 1
, 2
, 3
, 4
, 5
// 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 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<>();
// 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,