Skip to content

Instantly share code, notes, and snippets.

View superwills's full-sized avatar

William superwills

View GitHub Profile
@superwills
superwills / Hugely readable table drawing characters
Last active December 20, 2015 16:09
Hugely readable table drawing characters
From http://en.wikipedia.org/wiki/Box-drawing_character
┘ ┐ ┌ └ ┼ ─ ├ ┤ ┴ ┬ │ • × ⌘ π √ ÷ ² ³ ¼ ½ ¾
A matrix:
┌ ┐
│ 1 0 0 │
│ 0 1 0 │
│ 0 0 1 │
└ ┘
@superwills
superwills / Callback.h
Created August 14, 2013 17:01
Callback.h -- C++ callbacks
#ifndef CALLBACK_H
#define CALLBACK_H
#include <functional>
using namespace std ;
// REQUIRES APPLE LLVM
//Under Apple LLVM compiler 4.0 - Language,
// - C++ Standard Library: choose libc++ (LLVM C++ standard with C++11 support)
// NOT GNU
@superwills
superwills / Keychain.hpp
Created October 11, 2013 18:05
SecCRUD operations (SecCreate, SecRead, SecUpdate, SecDelete) for serialization of binary objects with primitive-typed data in them.
#ifndef KEYCHAIN_H
#define KEYCHAIN_H
/*
kSecAttrAccessible - A CFTypeRef (opaque) value that indicates when your app
needs access to the data in a keychain item. You should choose the
most restrictive option that meets your app’s needs so that iOS can protect
that item to the greatest extent possible. For a list of possible values,
see “Keychain Item Accessibility Constants.”
@superwills
superwills / Chancer.h
Last active December 28, 2015 14:59
Chancer redistributes the uniform distribution of randFloat(0,1) to any distribution you'd like.
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std ;
float randFloat()
{
return (float)rand() / RAND_MAX ;
}
@superwills
superwills / chances.txt
Last active December 28, 2015 16:19
Chance table
If you want an event in a game that runs at 60FPS to occur ON AVERAGE (once every 30 seconds),
then the probability interval you should use is 0.000555555556. So pick a range,
say [0, 0.000555555556].
Call randFloat(0,1) once every frame, and if the random generated is on
[0,0.000555555556] then make the event happen.
This table is to choose a probability interval (on [0,1]).
If you want something to occur on average ONCE per second for a 60 FPS game,
then the probability interval for that event should be exactly 1/60 chance
@superwills
superwills / fisheryates.cpp
Created November 29, 2013 01:08
Fisher-Yates shuffle
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std ;
int randInt( int a, int b )
{
return a + rand()%(b-a) ;
}
@superwills
superwills / stringtrim.hpp
Last active December 29, 2015 20:19
std::string::trimExtensions for std::string to trim() whitespace.
// Extensions for std::string to trim whitespace
string& trimR( string& str )
{
if( !str.size() ) return str;
// find the last whitespace chr, then delete from there to end.
string::iterator iter = --str.end() ;
while( isspace( *iter ) ) --iter;
str.erase( ++iter, str.end() ) ;
return str ;
}
@superwills
superwills / KeychainSimple.cpp
Last active November 28, 2016 10:26
Call `testKeychain()` from application `didFinishLaunchingWithOptions` or something to run this test code.
bool SecCheck( OSStatus res, const char* msg )
{
if( res==errSecSuccess )
{
printf( "< %s okie dokie >\n", msg ) ; // COMMENT THIS OUT TO SILENCE OK's
}
else
{
printf( "< NOT OK!! >: %s FAILED:\n >> ", msg ) ;
switch( res )
@superwills
superwills / Point in Polygon
Last active September 7, 2019 15:15
Pt In Poly simple algorithm. Works for convex & concave polygons.
#include <stdlib.h> // MUST BE BEFORE GLUT ON WINDOWS
#ifdef _WIN32
#include <gl/glut.h>
#else
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#endif
@superwills
superwills / index.html
Last active October 7, 2019 03:32 — forked from tiffany352/index.html
Twitter archive browser
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Twitter Archive Browser</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<style>