Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <queue>
#include <ostream>
#include <ranges>
struct location {
@CedricSch
CedricSch / main.cpp
Created January 26, 2022 08:02
Simple type trait
#include <iostream>
#include <type_traits>
namespace detail {
struct false_type
{
const static bool value = false;
};
struct true_type
export default class TaskQueue {
constructor(concurrency) {
this.concurrency = concurrency
this.running = 0
this.queue = []
}
async next() {
while(this.running < this.concurrency && this.queue.length) {
const task = this.queue.shift()
@CedricSch
CedricSch / exercise_8_1.js
Created June 3, 2021 01:00
Exercise 8.1 Http Cache
import https from "https";
import { createHash, randomInt } from "crypto";
import { PassThrough, Readable } from "stream";
import { promises as fs } from "fs";
/**
*
* Please feel free to inform me about a better solution.
*
*/
@CedricSch
CedricSch / exercise_8_23.js
Last active June 2, 2021 21:30
Exercise 8.3 Colored console output
class DecoratedConsole {
constructor(console) {
this.console = console;
this.RED = "\x1b[31m";
this.GREEN = "\x1b[32m";
this.YELLOW = "\x1b[33m";
this.RESET = "\x1b[0m";
}
_getColorString(color, message) {
@CedricSch
CedricSch / exercise_8_2.js
Last active June 2, 2021 21:16
Exercise 8.2 Timestamped logs
function createConsoleProxy(console) {
return new Proxy(console, {
get: (target, property) => {
const proxyFunctionNames = ["log", "error", "debug", "info"];
if (proxyFunctionNames.includes(property)) {
return function (...argumentList) {
const isoDate = new Date().toISOString();
// Every argument after argumentList[0] will be used as substitution values
const newMessage = `${isoDate}: ${argumentList[0]}`;
@CedricSch
CedricSch / exercise_7_3.js
Last active June 26, 2023 17:08
Solution for exercise 7.3 A tamper-free queue
import http from "http";
/*------------------------------------------------------------------------------------------------------------*/
class Queue {
constructor(executor) {
const queue = [];
let resolverFunctions = [];
async function enqueue(element) {
if(resolverFunctions.length) {
const resolve = resolverFunctions.shift();
constexpr unsigned int WIDTH = 1280, HEIGHT = 640;
// Update rate in hz
constexpr float timerUpdateRate = 60;
constexpr float cpuUpdateRate = 600;
// How many ticks before timers have to be updated
constexpr float cpuTicksToDo = cpuUpdateRate / timerUpdateRate;
float currentCpuTicks = 0;