Skip to content

Instantly share code, notes, and snippets.

View gsdayton98's full-sized avatar

Glen Dayton gsdayton98

View GitHub Profile
@gsdayton98
gsdayton98 / printstat.cpp
Created June 9, 2021 19:04
Print struct state
#include <iomanip>
#include <iostream>
#include <sys/stat.h>
std::ostream& operator<<(std::ostream& gozouta, const struct stat& st) {
gozouta << "File stat" << std::endl;
gozouta << "device: " << st.st_dev << " rdev: " << st.st_rdev << std::endl;
gozouta << "mode: " << std::oct << std::setfill('0') << std::setw(4) << st.st_mode << std::endl;
gozouta << "nlinks: " << std::dec << st.st_nlink << std::endl;
gozouta << "inode: " << std::dec << st.st_ino << std::endl;
@gsdayton98
gsdayton98 / printtimespec.cpp
Created June 9, 2021 19:01
OSX Timespec print
#include <ctime>
#include <sys/time.h>
#include <iostream>
std::ostream& operator<<(std::ostream& gozouta, const struct timespec& timspec) {
struct tm loctime;
char cbuf[512];
(void) ::localtime_r(&timspec.tv_sec, &loctime);
@gsdayton98
gsdayton98 / deleteDuplicates.cpp
Last active August 29, 2015 14:26
C++ code to delete duplicates from an array using a heap structure to achieve O(n*log n) performance
#include <cstdlib>
#include <algorithm>
// Delete duplicate entries from an array using C++ heap.
int *deleteDuplicates(int theArray[], size_t theArrayLength)
{
int *topSortedArray = theArray + theArrayLength;
if (theArrayLength > 1)
{
// Heap is in theArray[0:heapEnd-1]