Skip to content

Instantly share code, notes, and snippets.

View Ratstail91's full-sized avatar

Kayne Ruse Ratstail91

View GitHub Profile
@Ratstail91
Ratstail91 / gist:3120337
Created July 16, 2012 03:43
BBox Pseudocode
BBox::GetWorldBBox():
return world bbox
end
BBox::CheckCollisionType( box ):
myBox = GetWorldBBox()
//I know this part
if inside return inside
if outside return outside
@Ratstail91
Ratstail91 / palindrome.cpp
Created March 2, 2013 11:20
Palindromic source code generator for C++
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 3) {
@Ratstail91
Ratstail91 / gist:5095121
Last active December 14, 2015 13:39
Me, playing around with SQLite3.
#include "sqlite3.h"
#include <iostream>
#include <cstring>
using namespace std;
int charcount(char* str, const char c) {
int count = 0;
while(*str) {
@Ratstail91
Ratstail91 / linked_list.hpp
Created March 12, 2013 13:19
Playing with a linked list
#ifndef LINKEDLIST_HPP_
#define LINKEDLIST_HPP_
class Node {
public:
Node() {
next = nullptr;
}
virtual ~Node() {}
@Ratstail91
Ratstail91 / network.hpp
Created May 5, 2013 17:10
This is my idea for a minimalist networking interface. This is what I /wish/ existed. I might try and make this work, but I'm inexperienced with networking and making APIs.
#ifndef NETWORK_HPP_
#define NETWORK_HPP_
/* Unless noted otherwise, functions return 0 on success, or -1 on error.
* There are NO blocking functions.
*
* This is my idea for a minimalist networking interface. This is what I
* /wish/ existed. I might try and make this work, but I'm inexperienced
* with networking and making APIs.
*/
@Ratstail91
Ratstail91 / singleton.hpp
Created May 11, 2013 14:52
This isn't compiling.
#ifndef SINGLETON_HPP_
#define SINGLETON_HPP_
template<typename T>
class Singleton {
public:
static T* GetSingletonPtr() {
return &singleton;
}
static T& GetSingletonRef() {
@Ratstail91
Ratstail91 / gist:5700173
Created June 3, 2013 18:25
This is how I unit test.
#include "image.hpp"
#include "sprite_sheet.hpp"
#include "raster_font.hpp"
#include "surface_manager.hpp"
#include "button.hpp"
#include "SDL/SDL.h"
#include <iostream>
#include <chrono>
while(1)
{
calculateDT
disaptch inbound packets (you don't pass DT here, instead, this should have a reference to your gamestate object)
update accordingly (pass DT HERE)
render
}
@Ratstail91
Ratstail91 / gist:5748293
Created June 10, 2013 12:12
Basic mutex template, using SDL's threading systems.
int thread(void*) {
SDL_mutexP(lock); //remember: p for pause
if (/* not ready */) {
SDL_CondWait(cond, lock);
}
//do something
SDL_mutexV(lock);
SDL_CondSignal(otherCond);
}
#include <iostream>
using namespace std;
/* this is the most efficient prime number algorithm I could come up with
* the speed is worst case O(n)
*/
bool isPrime(int n) {
//two is the only even prime
if (n == 2) {
return true;