Skip to content

Instantly share code, notes, and snippets.

View ButchDean's full-sized avatar
💻
Well, it works on my docker container! ¯\_(ツ)_/¯

Dean Butcher ButchDean

💻
Well, it works on my docker container! ¯\_(ツ)_/¯
View GitHub Profile
@ButchDean
ButchDean / RN2DEC.cpp
Last active December 29, 2017 20:21
Code to convert Roman Numerals to Decimals. (RN2DEC created by ButchDean72 - https://repl.it/@ButchDean72/RN2DEC)
#include <cstdio>
#include <unordered_map>
#include <vector>
#include <cstring>
#include <memory>
const std::string sample = "MCMLXXII";
struct ROMAN_NUMERALS
{
@ButchDean
ButchDean / SSETest.cpp
Created December 29, 2016 04:54
SSE test/sample code from Game Engine Architecture by Jason Gregory
#include <cstdio>
#include <xmmintrin.h>
__m128 addWithAssembly(const __m128 a, const __m128 b)
{
__asm addps xmm0, xmm1
}
__m128 addWithIntrinsics(const __m128 a, const __m128 b)
{
@ButchDean
ButchDean / boo.c
Last active May 23, 2016 22:01
A countdown timer handy for many things.
#include <stdio.h>
#include <time.h>
int main()
{
time_t start, now;
double secs = 0.0;
int timercountdown = 10;
start = now = time(NULL);
@ButchDean
ButchDean / palindromicNum.cpp
Created January 6, 2016 01:43
Demo code inspired by Project Euler to determine if a number is palindromic.
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
int main(int argc, char* argv[])
{
if(argc == 1)
return 0;
@ButchDean
ButchDean / runfuncslambda.cpp
Last active August 29, 2015 14:19
C++11 lambda-based function execution example. Awesome for test harness.
#include <cstdio>
#include <vector>
#include <algorithm>
typedef void (*func)();
void Func1()
{
std::puts("Func1() called.");
}
@ButchDean
ButchDean / my_atoi.c
Last active August 29, 2015 14:12
An efficient solution to convert a signed number character string to a signed int. Was going to put it up on Stack Overflow, but the question was closed as duplicate.
#include <stdio.h>
#include <string.h>
#include <math.h>
int my_atoi(const char* snum)
{
int idx, strIdx = 0, accum = 0, numIsNeg = 0;
const unsigned int NUMLEN = (int)strlen(snum);
/* Check if negative number and flag it. */
@ButchDean
ButchDean / ToRoman.c
Last active December 28, 2015 13:39
Code to convert a decimal into its equivalent Roman numeral string.
#include <stdio.h>
#include <string.h>
#define MAX_ROMAN_NUMERALS 100
struct ROMAN_NUMERALS
{
char letter;
int value;
};
@ButchDean
ButchDean / ConvertToBase.cpp
Created November 17, 2013 04:52
This piece of code makes use of the STL vector and map to convert a number from base 10 to any other base in the range 2-36. This code demonstrates the power of the STL in defining quite complicated structures efficiently, as well as saving on many lines of extra code in making use of such structures.
#include <iostream>
#include <vector>
#include <map>
using namespace std;
class CBaseConverter
{
public:
CBaseConverter(){}
@ButchDean
ButchDean / NumDigits.c
Last active December 25, 2015 20:19
Non-iterative approach to finding the number of digits in an integer. Also works for both positive and negative numbers.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int digits;
digits = (atoi(argv[1]) == 0) ? 1 : (int)log10(abs(atoi(argv[1]))) + 1;