Skip to content

Instantly share code, notes, and snippets.

View pileon's full-sized avatar

Joachim Pileborg pileon

View GitHub Profile
#include "Event.h"
#include <iostream>
namespace events {
TargetType Event::getTarget() {
return target;
}
std::string Event::getDescription() {
@pileon
pileon / main.c
Last active May 9, 2018 04:10
Code testing possible forking and file bug
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int order;
FILE* file = fopen("sample_input.txt", "r");
if (file != NULL)
{
@pileon
pileon / CMakeLists.txt
Created March 21, 2018 12:10
Defining macros in CMake for use in source
cmake_minimum_required(VERSION 3.10)
project(Macro)
set(CMAKE_CXX_STANDARD 11)
add_executable(Macro main.cpp)
target_compile_definitions(Macro PUBLIC PATHTOPYTHONSCRIPT=\"${CMAKE_SOURCE_DIR}/bin/postprocessing/extractlinedata.py\")
@pileon
pileon / input_lines_of_numbers.cpp
Created December 7, 2017 13:53
Read X number of lines with an indeterminate number of integers
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
int main()
{
size_t number_of_rows;
std::cout << "Enter the number of rows: ";
Object* read(char* str)
{
Object* object = (Object*)malloc(sizeof(*object));
object->identity[0] = 0;
int capacity = (100 + 1) - (10);
// No allocation here object->name = (char*)malloc(capacity * sizeof(*object->name));
object->value = 0.0;
int length = strlen(str);
if (length > capacity)
@pileon
pileon / word-counter.cpp
Created February 11, 2017 00:03
Simple C++ program to show how to count a specific word in a text file
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iterator>
int main()
{
std::string filename;
std::cout << "Enter filename: ";
#include <stdio.h>
#include <limits.h>
// Important note: When reading input, something like 123abc is considered
// a valid value, and will be read as 123. The non-numeric input will not be
// detected immediately.
// This is because of how the scanf function works, and can't be solved with
// the current limitations (unless we read as a string and attempt to convert
// it to a number manually, either through strtol or with our own function
// (the atoi function can't be used, it's prone to the same problem)).
@pileon
pileon / random_data_save_load.cpp
Created September 19, 2016 13:36
Shows how to generate a file with 128 rows of 3300 random floating point values, then load it back in
#include <iostream>
#include <vector>
#include <sstream>
#include <random>
#include <fstream>
void save_random_data();
void read_random_data();
int main()
@pileon
pileon / pointer_wrapper.h
Last active July 12, 2022 12:28
Simple container for wrapping pointers to data of a known size. Works like an array or a vector, including iterators
// This code is in the public domain. I claim no ownership, but also no responsibility.
#ifndef POINTER_CONTAINER_H
#define POINTER_CONTAINER_H
#include <cstddef> // for std::size_t
template<typename T>
class pointer_container
{