Skip to content

Instantly share code, notes, and snippets.

View bwedding's full-sized avatar

bwedding

  • Sweden
View GitHub Profile
@bwedding
bwedding / StringSplitter.cpp
Created January 23, 2023 14:19
Split strings based on any number of delimiters. Standard C++
// StringSplitter.cpp
#include <iostream> // std::cout
#include <vector> // std::vector
#include <fstream>
std::vector<std::string> Split(const std::string str, const std::vector<std::string> delims)
{
const std::string fixedDelim = ",";
std::vector<std::string> split;
size_t t = 0;
@bwedding
bwedding / Split.cpp
Created December 6, 2021 22:48
C++ version of C# Split(). Splits a string with multiple delimiters into a std::vector<std::string>
// StringSplitter.cpp
#include <iostream> // std::cout
#include <vector> // std::vector
#include <fstream>
std::vector<std::string> Split(const std::string str, const std::vector<std::string> delims)
{
const std::string fixedDelim = ",";
std::vector<std::string> split;
size_t t = 0;
// FileDegradation.cpp : Place an MP3, MP4, JPG or any other file in a directory and create another
// empty directory. Add the filenames with paths to the const strings below
// Uses the excellent PicoSHA2 to calculate the file hash: https://github.com/okdshin/PicoSHA2
#include <iostream>
#include <filesystem>
#include <chrono>
#include <thread>
#include "PicoSHA2.h"
@bwedding
bwedding / texasCovid.cpp
Last active July 3, 2020 03:28
Prediction of COVID Infection in Texas based on real data
#include <vector>
#include <iostream>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;
const int NumDays = 45;
const int PopulationTexas = 30000000;
@bwedding
bwedding / NumberToWords.cpp
Last active June 27, 2020 02:15
Number To Words
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include "ConsoleApplication10.h"
std::map<const int, const std::string> Numbers =
{
{1, "one" }, {2, "two"}, {3, "three"}, {4, "four"}, {5, "five"},
{6, "six"}, {7, "seven"}, {8, "eight"}, {9, "nine"}, {10, "ten"},
@bwedding
bwedding / playtickets.cpp
Created May 12, 2020 06:43
Ticket System
#include <iostream>
#include <iomanip>
#include <ctime>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <sstream>
enum class UserChoice
{
@bwedding
bwedding / fbcustom.js
Last active April 28, 2020 23:08
Facebook custom conversion based on time such as a video playing
<script>
const VideoLenSeconds = 300; // Modify this to the length of your video in seconds. 300 = 5 mins
const Divisions = 10; // 10 = every 10%, 4 = every 25%, 5 = every 20%
const ConversionPct = 75; // Set this to record a desired conversion percentage
// Don't change these!
const MSecsPerSecond = 1000;
var percentageViewed = 0;
var converted = false;
@bwedding
bwedding / spherecollision.cs
Last active May 9, 2020 00:23
C# Sphere collision performance test with parallel for loop
using System;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Linq;
namespace collisions_sharp
@bwedding
bwedding / DeadendFill.cpp
Created April 6, 2020 02:44
Solve a maze by dead end filling
// DeadEndMazeSolver.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <thread>
#include <chrono>
using Maze = std::vector<std::vector<bool>>;
using PrintableMaze = std::vector<std::vector<unsigned char>>;
@bwedding
bwedding / SVNLogToCSV
Last active March 16, 2020 20:17
Parse a copied SVN log into a CSV file
// SVNLogToCSV.cpp : This program will take an SVN log file, as captured in the repository documentation
// and convert it to a CSV file for deeper analysis
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
const std::string Revision = "Revision:";
const std::string Author = "Author:";