Skip to content

Instantly share code, notes, and snippets.

View Sam-Belliveau's full-sized avatar

Sam Belliveau Sam-Belliveau

  • Cornell University
  • Ithaca, NY
View GitHub Profile
@Sam-Belliveau
Sam-Belliveau / counter.c
Last active December 17, 2018 02:03
A counter thats faster than using an int and printf. It also never stops counting until 10^2^24, but you can increase the max int without slowing it down like with gmp.
#include <stdio.h>
#include <stdlib.h>
int main(){char *d,*n=calloc(0x1000000,1);*n=48;for(;;){d=n;if(*d!=57)++*d;else{while(*d
==57)*(d++)=48;if(*d)++*d;else*d=49;}while(*++d);while(d--!=n)putchar(*d);putchar(13);}}
@Sam-Belliveau
Sam-Belliveau / StaticVector.hpp
Last active January 6, 2019 18:02
it is like std::vector, but it is made not to change size. This lets you make a few optimizations. This should work just like std::vector, or std::array, as it has implicit conversions, iterators, and move semantics.
/*
Copyright 2018, Sam R. Belliveau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@Sam-Belliveau
Sam-Belliveau / CArray.hpp
Created December 21, 2018 15:44
Helps with carrays and them decaying into pointers
#ifndef SAMS_CARRAY_LIBRARY_HPP
#define SAMS_CARRAY_LIBRARY_HPP
#include <cstdint>
#include <array>
namespace CArray
{
/* Make std::array */
template<class T, std::size_t N>
@Sam-Belliveau
Sam-Belliveau / owned_ptr.hpp
Last active January 1, 2019 01:50
it is like unique_ptr or scoped_ptr, but you can copy it. When you copy it, the new ptr is marked as shared, and will not be deallocated. If it is moved or stolen, it will be marked with what the other ptr is marked with. It works for arrays and single objects. Pointers that are marked shared will not deallocate. Pointers marked Moved will not d…
/*
Copyright 2018, Sam R. Belliveau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@Sam-Belliveau
Sam-Belliveau / smart_ptr.hpp
Last active February 5, 2019 20:02
This is a class that you can inheret when making a smart pointer class. It has cool features such as when the pointer type is a fixed array, it works just like std::array
#ifndef SAMS_SMART_POINTER_BASE_CLASS_HPP
#define SAMS_SMART_POINTER_BASE_CLASS_HPP 1
#include <cstddef>
namespace smart
{
/* Size Type, Remove dependency <cstdint> */
using size_t = std::size_t;
@Sam-Belliveau
Sam-Belliveau / Ratio.hpp
Last active January 6, 2019 21:20
I dont know a ratio class and some constants
#ifndef SAMS_RATIO_CLASS_HPP
#define SAMS_RATIO_CLASS_HPP 1
#include <cstdint>
#include <type_traits>
template <std::uintmax_t Numer, std::uintmax_t Denom, bool Pos = true>
class Ratio
{
public: /* Public Static Members */
@Sam-Belliveau
Sam-Belliveau / Mallocator.hpp
Last active January 1, 2019 22:34
to use, when making a std::vector or std::deque, make them like std::vector<T, Mallocator<T>> or std::deque<T, Mallocator<T>>. This will not call the constructor or deconstructor, so only use it on primitive types.
#ifndef SAMS_MALLOCATOR_ALLOCATOR_CLASS
#define SAMS_MALLOCATOR_ALLOCATOR_CLASS
#include <memory>
#include <type_traits>
#include <cstdlib>
template<class T>
struct Mallocator : public std::allocator<T>
{
@Sam-Belliveau
Sam-Belliveau / Range.hpp
Last active July 14, 2019 02:34
C++ Range Library
/*\
|*| Copyright 2018, Sam R. Belliveau
|*|
|*| Permission is hereby granted, free of charge, to any person obtaining a copy
|*| of this software and associated documentation files (the "Software"), to deal
|*| in the Software without restriction, including without limitation the rights
|*| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|*| copies of the Software, and to permit persons to whom the Software is
|*| furnished to do so, subject to the following conditions:
#include <iostream>
#include <cstdint>
using Int = std::uintmax_t;
using Float = long double;
constexpr Float getPhi()
{
Float Phi = 1;
for(Int i = 0; i < 0xffff; ++i)
#include <stdio.h>
#include <stdint.h>
int main(){uint16_t i[]={14894U,15710U,14478U,4100U,4100U,16382U,16385U,24021U,
20821U,24029U,21573U,23621U,16385U,16382U};for(int r=0;r<0xE;++r){for(int
m=0x8000;m;m>>=1)if(i[r]&m)printf("##");else printf(" ");puts("");}}