Skip to content

Instantly share code, notes, and snippets.

View bwedding's full-sized avatar

bwedding

  • Sweden
View GitHub Profile
@bwedding
bwedding / raytrace.cpp
Last active January 24, 2020 17:07
Raytrace a sphere
// Raytrace.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
// Viewer here: https://www.kylepaulsen.com/stuff/NetpbmViewer/
#include <iostream>
#include <fstream>
#include <vector>
struct vec3
{
@bwedding
bwedding / threading.cpp
Last active December 14, 2023 08:59
Example of C++ std::thread Windows Specific. Creates 30 threads which draw red, white and blue bar graphs moving at separate rates.
#include <iostream>
#include <thread>
#include <mutex>
#include <random>
#include <Windows.h>
using namespace std::chrono_literals;
constexpr int LINE_LEN = 100;
bool Running = false;
@bwedding
bwedding / factorialPar.cpp
Created December 5, 2019 01:37
Parallel factorial
#include <iostream>
#include <algorithm>
#include <vector>
#include <execution>
#include <numeric>
long double Factorial(std::vector<int> & numbers)
{
long double result = 1.0;
std::for_each(
@bwedding
bwedding / deedle.cpp
Created December 5, 2019 00:08
ASCII Progress Deedle Class
#include <thread>
enum DeedleType
{
Sticks,
Bubbles,
Rect,
LineBoxes,
Boxes
};
@bwedding
bwedding / SolveSystemsOfEquations.cpp
Last active May 24, 2021 05:29
Simple C++ program to solve 2 variable systems of equations using elimination method.
// SystemsOfEquations.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
struct Equation
{
double xCoefficent;
double yCoefficent;
double result;
@bwedding
bwedding / RandomRange.cpp
Created November 16, 2019 18:04
Class to Generate Random Numbers in a Range
#pragma once
#include <random>
class RandomRange
{
private:
int low;
int high;
std::uniform_int_distribution<> distr; // define the range
std::mt19937 eng{ std::random_device{}() };
// Benchmark C string vs. C++ std::string for the following task:
// Replace "," with ",\n".
#include "stdafx.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
using System;
using System.Diagnostics;
using System.Text;
namespace CSharpBenchmark
{
class Program
{
private static Random random = new Random();
@bwedding
bwedding / SerilogColoredLines.cs
Created July 3, 2019 22:30
A logger extension to add background colored lines to Serilog
using System;
using System.Collections.Generic;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;
namespace main1
{
static class LoggerExtensions
{
public const string BackgroundBlack = "\u001b[40m";
#include<stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <chrono>
using namespace std::chrono;
class ExecutionTimer
{
public: