Skip navigation

I created tradevertise recently. The idea is to find stuff that is close to you and trade with local people.

The internet changed things. It changed how information is shared. We went from knowledge being parked away in books at the library, to information being available at your finger tips, on your phone, while you’re in the bathroom. People have more free access to information than ever before. And it’s use to ARPANET!

Is that good? For consumers, yes! For producers? Maybe not.

I wonder what computer jobs were like in the 80’s. When the know-how of how to create a database schema was parked away inside a lengthy tome that only the senior engineer could grok. Now, that information, the answer to that same question you’ve had and would have spent days searching for the answer to, is now available in an online catalog. Got a problem? Go to google, type in your query.

Google changed things. Google indexed the internet. Google is like the computer catalog in the library.. except Google is slowly becoming the front end to all human knowledge that anyone cared to enter into the internet.

So information is transferring.. from humans, to machines. represents a corpus of knowledge that far superceeds what a single programmer could ever learn in his lifetime. It is the accumulated knowledge of what many programmers have learned in their lifetimes. And it doesn’t forget. Except for mod-delete.

So people just drop all they know into the internet. They get a +1! Thanks! But not paid for their contributions, which could potentially reach 100’s of people, some of which are corporations, businesses, places that will make money on what you’ve given away for free.

Now who gets paid? Let’s see.

  • Google: Advertising
  • Sites that host content: whatever they manage to make on ads or the sale of other services
  • Actual Internet Contributers: 0

So, what’s the deal? Smart people are not that important if their knowledge, ability to learn, ability to retain knowledge is not important (since machines cover that..)

But what if smart people all of a sudden stopped existing? Say suddenly, all your savants just stopped being savants, and all you had were non-nerdy people. Then the machines would stop learning :). The indexes would have less to index. And maybe humanity wouldn’t progress as quickly.

Your Academic Career Is Just Masturbation

What is state of the art in industry? Take a look at that.

Now take a look at your MSc or PhD paper. Back to state of the art in industry. Back to your MSc or PhD paper. Your MSc is now irrelevant.

The fact of the matter is, most of the work done in Universities for MSc or PhD work isn’t very good. In fact, it’s below not very good. It’s downright abysmal.

Nobody needs you to write about the role of a specific gene, or yet another computer vision thesis. US government labs, and industry labs already have research superceeding what you spent the last 3 years working on by decades.

It’s only logical. Research builds on what came before it. The state of the art, in computer vision, for example, is top secret — if those algorithms were released, it would be a security hazard for the US. The US military doesn’t publish its cutting edge research for a reason! It took the US military decades of research to get its flight control software to where it is today. I don’t mean to discourage you, but the tendency for smart people is to let their brains get to their head. You have to realize what you’re up against when you try to prove you know something to the world: the world collectively knows a lot more than you do.

So chill out. Calm down. Check yo’ self. What you’re doing in academic work is not that important. Technologies come and go in industry like you wouldn’t believe. The bottom line is, if it doesn’t make money, nobody cares about it.

Your research is only a means to an end. The end is get the jobs you want. The means justifies your being able to get those jobs to everyone around you.

Say you’re inventing yet another programming language to make writing code “faster and more efficient”. That doesn’t matter if your faster and more efficient code doesn’t get sold or seen by anyone. Are you an avid participant in, with 100k reputation? Stop that. You are masturbating. And according to lore masturbating could give you hairy palms or even sudden death. Do you get happy when you see imaginary points rack up in social karma sites? Big mistake. You’re conditioned by the gamification of social websites into thinking that the “work” you’re doing by helping others is actually useful. It’s not. By spending time on programming forums not making money and “pursuing knowledge”, you’re effectively wasting your life.

So what do you need?

You need sales. You need customers. You need relationships.

Take a look at the Google Graveyard. Leave your flower. If you’re a code geek, the effect should be chilling. Don’t make me spell it out for you. The vast majority of coding projects die. The vast majority of startups die. The .COM bubble burst because there was no money coming out of these websites that looked promising but offered services for free.

Balance your life

If you are doing an academic degree and are still single, you’re in huge trouble. Because the social aspect of your life is yet undeveloped, and you think your research is so important. Go out and have a beer. Have 2 beers. Mix and mingle. Have sex. Have plenty of sex. Get a partner. Sex is very important because it will develop you socially.

The social aspect in a company isn’t just “50% of the work we do”. The social aspect is everything. If you’re not social, you won’t have a good career.

It was great when it first came out. A competitor to DirectSound that worked on all systems. It still is kind of good.

But, the problem is, it _started out_ free, open, with no licensing fees, and cross platform. People promoted it widely, everyone paid attention, and many adopted it, after all it was “Free! No licensing fee!”

Then Creative Labs took over OpenAL and made it proprietary. But people continued to use OpenAL 1.1… since OpenAL 1.1 “works well enough” it isn’t being updated or maintained, and it continues to see widespread use.

However other sound systems such as FMOD or DirectSound have made many improvements over the base functionality OpenAL 1.1 provides.

The result of OpenAL 1.1 being available is a whole ton of systems is it became very old very fast, it still works, but not nearly as competitively as it did in 2008, for example. And there’s little chance of the situation for OpenAL The Free And Zero Licensing Cost Audio Software of being maintained by the open source community.

I keep coming across code like

for( int deviceIndex=0; deviceIndex < devices.size(); deviceIndex++ )
    devices[deviceIndex].param += value;

what’s wrong with this code? wouldn’t it be a lot better like this?

for( int i=0; i < devices.size(); i++ )
    devices[i].param += value;

i is a dummy variable. It’s name doesn’t matter – it just needs to be short. devices[deviceIndex] is redundant – we already know what we are accessing by the array’s name, devices[deviceIndex] is just longer and noisier than devices[i] – without adding additional clarity.

Just came across this in a C code apple example:

  // stuff..
} while (false);

The code breaks the loop when an error occurs inside it. This is kind of like try/catch/finally, where you have a simple catch(…) all block that you jump to if you “break” the loop. It seems like a poor substitute for a function call however.

Some artifacts may arise. For example, say you inherit from std::string. You want to write a function that ends up calling a method from std::string that returns a std::string: (like .substr()). Now you have an extra ctor call to construct your derived type object –

I’m testing polldaddy polls. Here’s the link.

The weirdest shit. You have to ask OpenGL to normalize byte colors. So the correct call to glVertexAttribPointer would be:

glVertexAttribPointer( attribNo, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, squareColors);

I spent like 20 minutes looking for what the problem could be with my code when I tried to switch float colors to byte colors, all my colors were white. And it was just this `normalized` flag.

I effectively had this:

void fun( const char* msg )
  function = [msg](){
    // do something with msg

Then call:

fun( string( "oh hi hello" ).c_str() ) ;

See what’s wrong? The string object whose char* ptr I passed to fun _dies_ immediately after the line executing call to fun runs. So the captured const char* ptr [msg] is invalid if function() runs at a later time (after return of call to fun())

nov 20 2013 4:22p

The item that an enemy would go for was flip flopping. It would continually flip between chasing after the 2 nearest items. I detected this bug in 2 minutes on the 1st launch, because I had inserted printf statements.

– Detection: printf statements
Enemy squadron Fighter thinks item B1 is reachable in 2.703664 seconds
Enemy squadron Fighter thinks item Bandit is reachable in 2.884945 seconds
Enemy squadron Fighter thinks item B1 is reachable in 2.703305 seconds
Enemy squadron Fighter thinks item Bandit is reachable in 2.884617 seconds

Reason: units were programmed not to chase after items that units on their same team were chasing after. Unfortunately overlooked the fact that I would be seen on as on my same team.

– If I’m already gathering an itembox, stick with it until i get it OR
– If the person gathering the itembox is ME, keep going after it.

Using integer indices into arrays of objects (instead of iterators, or pointers to the objects themselves) has saved my ass many times.

Say you have a vector<Object>. Well, you wouldn’t store pointers of type Object* to an element of this array, ever, because if the vector gets resized, all objects get deallocated/reallocated and so all your previous references will be invalid. But if you store a vector<Object*> and save an external reference to an Object* within that vector, then that’s no problem.

But anyway, storing integer arrays is much better than storing copies of pointers. For one, if the pointer gets deleted, you’re not left with an invalid / dangling pointer somewhere. Checking if a reference into the array is valid because you just have to check the integer index is between 0 and (.size()-1).

Simple example

f := (x) -> x^2

Is the function f(x)=x^2. You call it by writing


To animate the function, just add another parameter and give it a range in a plot command.

plot( a*f(x), x=-2..2, a=0.1..5 )

C++’s RTTI is expensive. Very expensive. Notoriously and verifiably expensive.

So how can we efficiently get information of the concrete subclass, given an abstract base class pointer, without the great expense of using RTTI?

Simple. Use an enum.

Consider the example in my stackoverflow post. What I did there is just keep a single bitfield (an int) that has concrete types bitwise OR’d in, in each derived constructor.

So, in the example posted, an object of Type BigCat would have 0111 for its typeTag field, indicating that it is an Animal, a Cat, and a BigCat. Concrete type checking is cheap as a bitwise AND.

eta is easy to compute if you have distance between 2 objects, their relative accelerations, and relative velocities.

By _relative_ accelerations and velocities, i mean the rate at which they are coming together. So you have to project both objects’ velocity components onto the line joining the two objects, and use that scalar component in these computations.

Without further ado, eta:

eta = -v1 +/- sqrt( v12 + 2a(dist) ) / a

In image:

I ran into this error before, it is described here. Basically preface whatever the offending line is with this->.

Did you know if you work in “High Quality Rendering” mode (click the red box) the split polygon tool is _much more helpful_?

What’s wrong with this code?

class Object{
  int x ;
  Object() {
    defaults() ;
  Object( int ix ) : x(ix) {
    defaults() ;
  defaults() { 
} ;

Well, obviously x has the value 0, instead of the initializer-list desired default value sent `ix`.

So, what happens when you have 10-15 members that all have default value initialization in defaults(), and possible assignment in the initializer list, is defaults() clobbers whatever was sent to the initializer list, since the initializer list runs first.

I puzzled over this for a few minutes.

Warcraft 1,2 & 3 used swords for attack, shields for stop. It works because the entire theme was medieval. So, swords mean attack, shields mean “stop”. Regardless of unit type (even air units — there’s no cognitive dissonance there).

Starcraft 1 & 2 cleverly abstracted this away though. Swords clearly wouldn’t fit in Starcraft. Different units had different means of attacking. Zerg never use guns. They use spit or claws. Protoss had some “sword-like” units that did hand-to-hand combat (zealots), but other units fired projectiles (dragoons). They used a _crosshair_ instead for the attack symbol.

So, in my own game I had to think, what symbolizes _attack_ in my game? It’s a space combat game, and attack is done primarily via missiles. So I subbed in a picture of a missile for attack. And voila. The right symbol for attack is _a picture of whatever attacking is done with_ in your game.

If it were a streetfighting game, you’d use an icon of a fist.

I couldn’t find a way to do this through the GUI, but I’m positive there was one.

Anyway, the MEL command to show normals for the selected mesh:

polyOptions -dn 1;

And to hide them again

polyOptions -dn 0;

Taken from here

Maya rotate snap hotkey is j

j means rotate snap, because you know, in original english rotation by discrete amounts of 15 degrees was called “jotation”.

Anyway, double clicking the ROTATE TOOL gives you a box @ right, you can modify the size of the discrete step there.

If you notice, holding j “temporarily” clicks on the “discrete rotate” setting.

Maya vertex snap hotkey is v

If you hold v it will let you snap a vertex to another one while dragging.

Maya is a visual editor, so they actually hid the information of the numerical coordinates of the vertices pretty well.

You can usually get the results you want by snapping. But when you can’t, there’s the Component Editor.

You go to Window / General Editors / Component Editor to get it. I learned this from a SimplyMaya thread.

I almost forgot the simple formula for checkerboarding,

if( (i % 2) == (j % 2) )  WHITE;
else BLACK ;

If both i and j are EVEN, OR both i and j are ODD, you get one color. If they differ in “oddness” then you get the other color.

There is a really shitty post on stackoverflow about this, filled with nonsense.

I’m working with old OpenGL code. Specifically, code based off GLES2Sample.

There was a slight change around iOS 5.0 or so, requiring you to have a root view controller. If your code is based off older sample code, such as GLES2Sample, then no root view controller was created in those code samples.

To fix GLES2Sample, I know the following fix works. Right in `applicationDidFinishLaunching`, I create a root view controller and attach my glView to it.

    - (void) applicationDidFinishLaunching:(UIApplication *)application
      // To make the 'Application windows are expected
      // to have a root view controller
      // at the end of application launch' warning go away,
      // you should have a rootviewcontroller,
      // but this app doesn't have one at all.
      window.rootViewController = [[UIViewController alloc] init];  // MAKE ONE
      window.rootViewController.view = glView; // MUST SET THIS UP OTHERWISE

That makes the warning go away, and doesn’t really affect your app otherwise.

Developer journals are my answer to dead code. Word Documents, blog entries, whatever. Source control history is harder to wade through than dated log entries about how a function used to work, and how it works now.

Logging with thoughts on what changed and why it changed is essential, even if you’ll never refer to it, the peace of mind you get while simultaneously retaining a clean code base is worth it. Delete with confidence – and a backup. Plus, you’ll never get the clarity why you deleted something as when the moment you deleted it.

Here’s an example of a journal entry I just made for today:

This is part of a Word document. I just downsized the font so it is quickly scrollable. I doubt I will need the comments or dead code I am about to delete, or that I will be unable to regenerate them easily, but just in case, the info is all there in this dated entry.

This article confirmed my suspicion.

Besides a wide variety of flavors and roast selections (with French Vanilla available as a light roast), Target’s coffee is indeed my cup of.. coffee.

So far I’ve only began the French Vanilla bag, but it tastes delicious. It actually tastes a lot like coffee shop coffee. It’s very fresh, very smooth, and the vanilla flavoring is just right — not overpowering, but pleasantly tasty.

I also got the plain light roast. It costs about $3.50 less than a bag of Starbuck’s blonde, if it’s good, it will probably be my new main.

There’s this point in Woo’s paper that confused me before, and it just confused me again now.

The paper says to always pick the largest t.

So the situations in red and pink confused me. It would seem at first glance that “further t” (in the pink diagram, the one intersecting min.y) would be the “greater t” but the _wrong one_ to pick.

But it turns out when you cull the back faces _based on ray direction_, the smaller t would be at the max.y plane, even though the ray starts AFTER the max.y plane.

Note Woo’s method as presented _doesn’t work for when the ray starts totally inside the box_.

If the ray starts inside the box, if you only need the boolean result then RETURN TRUE immediately. But if you need the intersection point, you need to turn around some of the rules of the test:

From “Geometric Tools for Computer Graphics”, the definition of convex given on pg 265 sec 7.7 is:

A set S is convex if given any two points P and Q in S,the line segment ( 1 − t ) P + t Q for t ∈ [0, 1] is also in S.

Said more plainly, if every line you can draw that connects two vertices a shape is completely contained inside the shape (tracing edges is allowed), then that shape is convex.

Basic program showing how to use GLSL and GLUT together

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <map>
using namespace std ;

#include <math.h>

//     #defining GLEW_STATIC means to compile the glew library as a static lib.
//     This means your prog WILL NOT require the glew32.dll file to accompany your executable.
#include <GL/glew.h>
#pragma comment( lib, "glew32s.lib" )   // the 's' is for 'static'

//#include <GL/glew.h>
//#pragma comment( lib, "glew32.lib" )

// I'm using the STATIC LIB way above, because I prefer it.

#include <GL/glut.h>

GLuint glslProgId ;     // GLSL shader PROGRAM identifier
GLuint vshId, pshId ;   // GLSL vertex shader id, pixel shader id

// These 2 are "handles" that connect the POSITION attribute in
// the GLSL shader with __AN ACTUAL SET OF VERTICES__ from the C++ source code.
// In this program each VERTEX has a position and a color (only).
GLuint positionAttribute, colorAttribute;

// This is the connector between the uniform variable modelViewMatrix,
// used in the glsl shader code.  We need this variable to LOAD
// a specific modelview matrix INTO the GLSL shader before rendering the verts.
GLuint uniformModelViewMatrix;

// The vertex array object identifier.  This single number
// identifies EVERYTHING about the vertex buffer we are 
// about to create and render, from its attribute set (positions, colors)
// to where to fetch the data from when it's time to draw.
GLuint vao ;

// window width and height.
float w=512.f, h=512.f;

struct VertexPC
  float x,y,z, r,g,b,a ;
  VertexPC( float ix, float iy, float iz, float ir, float ig, float ib, float ia ):
    x(ix),y(iy),z(iz), r(ir),g(ig),b(ib),a(ia)
} ;

// The data for the vertex and index buffers.
// I'm just using index buffers to show how they are used.
static VertexPC verts[] = { 
  VertexPC(0,0,0, 1,0,0,1),
  VertexPC(1,0,0, 0,1,0,1),
  VertexPC(0,1,0, 0,0,1,1)
} ;
static int indices[] = {0,1,2};

map<int,const char*> glErrName ;
map<int,const char*> createErrMap()
  map<int,const char*> errmap ;
  errmap.insert( make_pair( 0x0000, "GL_NO_ERROR" ) ) ;
  errmap.insert( make_pair( 0x0500, "GL_INVALID_ENUM" ) ) ;
  errmap.insert( make_pair( 0x0501, "GL_INVALID_VALUE" ) ) ;
  errmap.insert( make_pair( 0x0502, "GL_INVALID_OPERATION" ) ) ;
  errmap.insert( make_pair( 0x0503, "GL_STACKOVERFLOW" ) ) ;
  errmap.insert( make_pair( 0x0504, "GL_STACK_UNDERFLOW" ) ) ;
  errmap.insert( make_pair( 0x0505, "GL_OUTOFMEMORY" ) ) ;
  errmap.insert( make_pair( 0x8CD5, "GL_FRAMEBUFFER_COMPLETE" ) ) ;
  errmap.insert( make_pair( 0x8CD6, "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT" ) ) ;
  errmap.insert( make_pair( 0x8CD7, "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" ) ) ;
  errmap.insert( make_pair( 0x8CD9, "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS" ) ) ;
  errmap.insert( make_pair( 0x8CDD, "GL_FRAMEBUFFER_UNSUPPORTED" ) ) ;                    
  return errmap ;

inline bool GL_OK()
  GLenum err = glGetError() ;
  if( err != GL_NO_ERROR )
    printf( "GLERROR %d %s\n", err, glErrName[ err ] ) ;
  return err == GL_NO_ERROR ;

inline bool GL_OK( int line, const char* file )
  GLenum err = glGetError() ;
  if( err != GL_NO_ERROR )
    printf( "GLERROR %d %s, line=%d of file=%s\n", err, glErrName[ err ], line, file ) ;
  return err == GL_NO_ERROR ;

inline bool CHECK( bool cond, const char* errMsg )
  if( !cond )  puts( errMsg ) ;
  return cond ;

#define CHECK_GL GL_OK( __LINE__, __FILE__ ) 

//#define CHECK_GL GL_OK()

void printShaderInfoLog(GLuint obj)
  int infologLength = 0;
  glGetShaderiv( obj, GL_INFO_LOG_LENGTH, &infologLength ) ;
  if( infologLength )
    char *infoLog = (char *)malloc(infologLength);
    int charsWritten ;
    glGetShaderInfoLog( obj, infologLength, &charsWritten, infoLog ) ;
    puts( infoLog ) ;
    free( infoLog ) ;

void printProgramInfoLog( GLuint obj )
  int infologLength = 0;
  glGetProgramiv( obj, GL_INFO_LOG_LENGTH, &infologLength ) ;
  if( infologLength )
    char *infoLog = (char *)malloc( infologLength ) ;
    int charsWritten ;
    glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
    puts( infoLog ) ;
    free( infoLog ) ;

void setupShaders()
  // The text of the shaders.  I put it as an inline string
  // just so I could post this easily w/o external files,
  // but you could easily load the shader from an external file.
  // The point is, you must pass your shader to OpenGL as
  // just a NULL terminated string.
  const char *vs = 
    "uniform mat4 modelViewMatrix ;                         "
    "                                                       "
    "attribute vec3 position;                               "
    "attribute vec4 color;                                  "
    "                                                       "
    "varying vec4 Color;                                    "
    "                                                       "
    "void main()                                            "
    "{                                                      "
    "  Color = color;                                       "
    "  gl_Position = modelViewMatrix * vec4(position,1.0) ; "
    "}                                                      " ;

  const char *fs =
    "in vec4 Color;            "
    "                          "
    "void main()               "
    "{                         "
    "  gl_FragColor = Color ;  "
    "}                         " ;
  vshId = glCreateShader(GL_VERTEX_SHADER) ;  CHECK_GL ;
  glShaderSource( vshId, 1, &vs, NULL ) ;  CHECK_GL ;
  glCompileShader( vshId ) ;  CHECK_GL ;
  printShaderInfoLog( vshId );
  pshId = glCreateShader(GL_FRAGMENT_SHADER) ;  CHECK_GL ;
  glShaderSource( pshId, 1, &fs, NULL ) ;  CHECK_GL ;
  glCompileShader( pshId ) ;  CHECK_GL ;
  printShaderInfoLog( pshId );

  glslProgId = glCreateProgram();
  glAttachShader( glslProgId, vshId );
  glAttachShader( glslProgId, pshId );

  glLinkProgram( glslProgId );
  printProgramInfoLog( glslProgId );

  positionAttribute = glGetAttribLocation( glslProgId, "position" ) ;
  colorAttribute = glGetAttribLocation( glslProgId, "color" ) ; 

  uniformModelViewMatrix = glGetUniformLocation( glslProgId, "modelViewMatrix" ) ;

  // Make a "vertex buffer"
  GLuint vertexBuffer ;
  glGenBuffers( 1, &vertexBuffer ) ;

  glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer ) ;
  glBufferData( GL_ARRAY_BUFFER, sizeof( verts ), verts, GL_STATIC_DRAW ) ;

  // Make an "index buffer"
  GLuint indexBuffer ;
  glGenBuffers( 1, &indexBuffer ) ;
  glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ) ;
  glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( indices ), indices, GL_STATIC_DRAW ) ;

  // You know, this is weird, but a VERTEX ARRAY OBJECT
  // Vertex BUFFERS store the data.
  // A VAO stores the SETUP of how a group of
  // vertices is to be rendered.
  // That is, it stores:
  // 1)  The DATA (in vertex BUFFERS) to be drawn
  // 2)  THE SEMANTICS of that data (vertex format)

  // So you can see, it's all very intermingled and messy.
  // TO draw vertex data with GLSL, you have to:
  //   1) Load the raw vertex data into a vertex buffer
  //   2) set up vertex attributes (via glVertexAttribPointer)
  //      WHICH does 2 things:
  //      a)  It tells OpenGL the VERTEX FORMAT (floats? 3 elements? 4 elements? stride?)
  //   3) Call glDrawArrays or glDrawElements( ..., 0 ) 
  // INIT THE VERTEX ARRAY (stuff to draw)
  // The vertex array OBJECT remembers info about
  // indices, and the actual vertex buffer object
  // from which to pull data when rendering.
  glGenVertexArrays( 1, &vao ) ;
  glBindVertexArray( vao ) ;

  glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer ) ;
  glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ) ;
  glEnableVertexAttribArray( positionAttribute ) ;
    positionAttribute,  // index. NOTE THIS HAS BEEN CONNECTED UP EARLIER
    // IN THE LINE:
    //   > positionAttribute = glGetAttribLocation( glslProgId, "position" ) ; // C++ code line
    // and "position" is used in the GLSL vertex shader as:
    //   > attribute vec3 position; // GLSL shader line
    // SO. Don't be confused, the `positionAttribute` variable is simply connected up
    // to the vertex shader's INCOMING "position" attribute.  Naked girls.
    3,          // size. 3 floats/vertex
    GL_FLOAT,   // type. floats!
    0,          // normalized? No.
    sizeof(VertexPC),          // stride
    0           // pointer.  0 says to use the CURRENTLY BOUND
    // If you want to draw from CLIENT MEMORY you would pass AN ACTUAL ADDRESS
  ) ;

  glEnableVertexAttribArray( colorAttribute ) ;

  int offset = 3*sizeof(float) ;
  glVertexAttribPointer( colorAttribute, 4, GL_FLOAT, 0, sizeof( VertexPC ),
    (void*)offset  // RE: THE LAST PARAMETER: I know it looks ridiculous!! to pass a NUMBER as cast to VOID* here,
    // but that's C api's for you.  "Wait! Shouldn't it be &offset?"
    // NO. Your eyes kid you not.  You take the INTEGER NUMBER (which amounts to 12 here)
    // AND JUST PASS THAT AS IF IT WERE A "VOID*" POINTER. Even though you and I know it is not.
  ) ;


void keyboard(unsigned char key, int x, int y)
    case 27: //esc
      glDeleteVertexArrays( 1,&vao ) ;
      glDeleteProgram( glslProgId );
      glDeleteShader( vshId );
      glDeleteShader( pshId );
      break ;

void resizeWindow(int width, int height)

void draw()
  glViewport( 0, 0, w, h ) ;
  glClearColor( 0.1f, 0.1f, 0.1f, 0.1f ) ;

  // Bind the shader I created earlier
  glUseProgram( glslProgId );
  // Update the uniform variable.  YOU CAN
  // IE glUniformMatrix4fv must be called AFTER glUseProgram
  float m[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 } ;
  glUniformMatrix4fv(uniformModelViewMatrix, 1, false, m);

  // Here we bind the vertex array "object".  This is EQUIVALENT
  // to "replaying" 
  glBindVertexArray( vao );

  // Now we could draw in one of 2 ways:

  //glDrawArrays( GL_TRIANGLES, 0, 3 ) ; // draw as vertex buffer (with no index buffer)

    3, //# INDICES in the index buffer
    GL_UNSIGNED_INT, // I used 4-byte ints. Some other people use shorts, but I never do.
    0  // 0 means, use the index buffer bound
  ) ;


int main(int argc, char **argv)
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowSize( w,h ) ;
  glutCreateWindow("GLSL with GLUT");


  //if( glewIsSupported("GL_VERSION_3_0") )


  setupShaders() ;

  glutMainLoop() ;

  return 0 ; 

If you’re using numerical indexing to access the xyz components of a vector, (with 0=x, 1=y, 2=z) a good tip is to remember that

axis = 0 ; // for example.
otherAxis1 = ( axis + 1 ) % 3 ; // =1
otherAxis2 = ( axis + 2 ) % 3 ; // =2

This works for all values of axis to get you “the other 2″ axes

The description on Wikipedia is ok, but here’s more.

Marching cubes is all about filling the space with cubes, and “cutting the cubes” by triangles if the isosurface cuts through the cube.

This talk by Shewchuk is great to help understand what an isosurface is, etc.

Now, there’s all this talk about 256 possible cube configurations. What’s that about.

Well the cube has 8 vertices. Pretend being inside the isosurface means the vertex is “wet”. Assuming the cube could dip in and out of the isosurface on any of those 8 vertices, means there are 2^8=256 possible configurations for the vertices to be “wet” (inside the isosurface).

The case where the cube is “completely dry” is when no vertices are inside the isosurface. If I put one corner in the isosurface, then one vertex is “wet”. But wait! There are 8 ways that “one corner” can be wet, because there are 8 corners on a cube. So each of the 8 corners can be in one of 2 states (“wet” or “dry”), means there are 2^8 possible configurations for the corners to be wet and dry. This actually boils down to just 14 cases if you exploit symmetry (ie consider the case of “one vertex being wet” as one case, not 8 cases).

This is easier to understand if you look at a square.

So there, we have 4 vertices, so 2^4=16 cases. case 0 is “dry”. case 1 has 1 vertex wet, and there are 4 symmetric cases. Case 2 has 2 adjacent corners.. etc. Just look at the diagram.

I can’t count the number of times extremely difficult mathematese was made understandable via a quick diagram.

All academics should take COMIC DRAWING as a course in university. The reason is, to be able to express themselves via diagrams and symbols, actors and examples, rather than just relying on words and the jargon of their field.

Well, a surprising result, never use your extern variables inside a function that runs before main.

Here’s an example:

In the header:

//extern test.  the externs are giving 0's.
struct Vector4f
  float x,y,z,w;
  Vector4f( float ix, float iy, float iz, float iw ) :x(ix),y(iy),z(iz),w(iw){}
} ;

extern Vector4f Red ; // This is the weird variable..

In the main.cpp file:

static map<char, Vector4f> initMapping()
  map<char, Vector4f> mp ;
  mp.insert( make_pair( 'r', Red ) ) ;
  for( auto &p : mp )
    printf( "%c: %f %f %f %f\n", p.first, p.second.x, p.second.y, p.second.z, p.second.w );
  return mp ;

//Vector4f Red(1,0,0,1) ; // if this is here, Red has (1,0,0,1)
map<char, Vector4f> colorMapping = initMapping() ;
Vector4f Red(1,0,0,1) ; // if Red is only given its value HERE, when the static ctor runs, Red will be (0,0,0,0)

int main(int argc, const char * argv[])
  for( auto &p : colorMapping )
    printf( "%c: %f %f %f %f\n", p.first, p.second.x, p.second.y, p.second.z, p.second.w );

So those 2 declarations of Vector4f Red (without extern qualifier) in the cpp are the issue here. If the compiler runs into the Vector4f Red(1,0,0,1) ; BEFORE running SomeStruct::initMapping(), then the mapping has the correct value for Red in it. If the compiler first runs into Vector4f Red(1,0,0,1) only __after__ running SomeStruct::initMapping(), then the value of Red inside the map would be all 0’s.

I was browsing my spam and I came across this “spammer template”: use it to develop spam protection software!

{I have|I’ve} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It’s|It
is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site
owners|website owners|web owners} and bloggers made good content as you did, the
{internet|net|web} will be {much more|a lot more} useful than ever before.
I {couldn’t|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I’ll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss feed} as I {can not|can’t} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you’ve} any?

{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I
{may just|may|could} subscribe. Thanks.|
{It is|It’s} {appropriate|perfect|the best} time to make some plans for the future and {it is|it’s} time to be happy.
{I have|I’ve} read this post and if I could I {want to|wish to|desire to} suggest you {few|some} interesting things or {advice|suggestions|tips}. {Perhaps|Maybe} you {could|can} write next articles referring to this article. I {want to|wish to|desire to} read {more|even more} things about it!|
{It is|It’s} {appropriate|perfect|the best} time to make {a few|some} plans for {the future|the longer term|the long run}
and {it is|it’s} time to be happy. {I have|I’ve} {read|learn} this {post|submit|publish|put up} and if I
{may just|may|could} I {want to|wish to|desire to} {suggest|recommend|counsel} you
{few|some} {interesting|fascinating|attention-grabbing} {things|issues}
or {advice|suggestions|tips}. {Perhaps|Maybe} you {could|can} write {next|subsequent} articles {relating to|referring to|regarding}
this article. I {want to|wish to|desire to} {read|learn} {more|even more} {things|issues} {approximately|about}
{I have|I’ve} been {surfing|browsing} {online|on-line} {more than|greater than} {three|3} hours {these days|nowadays|today|lately|as of late}, {yet|but} I {never|by no means} {found|discovered} any {interesting|fascinating|attention-grabbing} article like yours. {It’s|It is} {lovely|pretty|beautiful}
{worth|value|price} {enough|sufficient} for me.
{In my opinion|Personally|In my view}, if all {webmasters|site owners|website
owners|web owners} and bloggers made {just right|good|excellent} {content|content material} as
{you did|you probably did}, the {internet|net|web} {will be|shall be|might be|will probably be|can be|will
likely be} {much more|a lot more} {useful|helpful} than ever before.
Ahaa, its {nice|pleasant|good|fastidious} {discussion|conversation|dialogue} {regarding|concerning|about|on the topic of} this {article|post|piece of writing|paragraph} {here|at this place} at this {blog|weblog|webpage|website|web
site}, I have read all that, so {now|at this time} me also commenting {here|at this place}.

I am sure this {article|post|piece of writing|paragraph} has touched
all the internet {users|people|viewers|visitors}, its really really
{nice|pleasant|good|fastidious} {article|post|piece
of writing|paragraph} on building up new {blog|weblog|webpage|website|web site}.

Wow, this {article|post|piece of writing|paragraph} is {nice|pleasant|good|fastidious}, my {sister|younger sister} is
analyzing {such|these|these kinds of} things, {so|thus|therefore} I am going to {tell|inform|let know|convey} her.
{Saved as a favorite|bookmarked!!}, {I really like|I like|I love}
{your blog|your site|your web site|your website}!
Way cool! Some {very|extremely} valid points!
I appreciate you {writing this|penning this} {article|post|write-up}
{and the|and also the|plus the} rest of the {site is|website is} {also very|extremely|very|also really|really} good.
Hi, {I do believe|I do think} {this is an excellent|this is a great} {blog|website|web
site|site}. I stumbledupon it ;) {I will|I am going to|I’m going to|I may} {come back|return|revisit} {once again|yet again} {since I|since i have} {bookmarked|book marked|book-marked|saved as a favorite} it. Money and freedom {is the best|is the greatest} way to change, may you be rich and continue to {help|guide} {other people|others}.|
Woah! I’m really {loving|enjoying|digging} the template/theme of this {site|website|blog}.
It’s simple, yet effective. A lot of times it’s {very hard|very difficult|challenging|tough|difficult|hard}
to get that “perfect balance” between {superb usability|user friendliness|usability} and {visual appearance|visual appeal|appearance}.
I must say {that you’ve|you have|you’ve} done a {awesome|amazing|very good|superb|fantastic|excellent|great} job with this.
{In addition|Additionally|Also}, the blog loads {very|extremely|super} {fast|quick}
for me on {Safari|Internet explorer|Chrome|Opera|Firefox}.
{Superb|Exceptional|Outstanding|Excellent} Blog!|
These are {really|actually|in fact|truly|genuinely} {great|enormous|impressive|wonderful|fantastic} ideas in {regarding|concerning|about|on the topic of} blogging.
You have touched some {nice|pleasant|good|fastidious} {points|factors|things} here.
Any way keep up wrinting.|
{I love|I really like|I enjoy|I like|Everyone loves} what you guys
{are|are usually|tend to be} up too. {This sort of|This type of|Such|This kind of} clever work
and {exposure|coverage|reporting}! Keep up the {superb|terrific|very good|great|good|awesome|fantastic|excellent|amazing|wonderful} works guys I’ve {incorporated||added|included} you guys to {|my|our||my personal|my own} blogroll.|
{Howdy|Hi there|Hey there|Hi|Hello|Hey}! Someone in my {Myspace|Facebook} group shared this {site|website} with us so I came to {give it a look|look it over|take a look|check it out}. I’m definitely
{enjoying|loving} the information. I’m {book-marking|bookmarking} and will be tweeting this to my followers! {Terrific|Wonderful|Great|Fantastic|Outstanding|Exceptional|Superb|Excellent} blog and {wonderful|terrific|brilliant|amazing|great|excellent|fantastic|outstanding|superb} {style and design|design and style|design}.|
{I love|I really like|I enjoy|I like|Everyone loves} what you guys {are|are usually|tend to be} up too. {This sort of|This type of|Such|This kind of} clever work and {exposure|coverage|reporting}! Keep up the {superb|terrific|very good|great|good|awesome|fantastic|excellent|amazing|wonderful} works guys I’ve {incorporated|added|included} you guys to {|my|our|my
personal|my own} blogroll.|
{Howdy|Hi there|Hey there|Hi|Hello|Hey} would you
mind {stating|sharing} which blog platform you’re {working with|using}? I’m {looking|planning|going}
to start my own blog {in the near future|soon} but
I’m having a {tough|difficult|hard} time {making a decision|selecting|choosing|deciding} between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your {design and style|design|layout} seems different then most blogs and I’m looking for something {completely unique|unique}.
P.S {My apologies|Apologies|Sorry} for {getting|being} off-topic but I
had to ask!|
{Howdy|Hi there|Hi|Hey there|Hello|Hey} would you mind letting me know which {webhost|hosting company|web host} you’re {utilizing|working with|using}? I’ve
loaded your blog in 3 {completely different|different} {internet browsers|web browsers|browsers} and I must say
this blog loads a lot {quicker|faster} then most. Can you {suggest|recommend} a good {internet
hosting|web hosting|hosting} provider at a {honest|reasonable|fair} price?
{Thanks a lot|Kudos|Cheers|Thank you|Many thanks|Thanks}, I appreciate it!
{I love|I really like|I like|Everyone loves} it {when
people|when individuals|when folks|whenever people} {come together|get together} and share {opinions|thoughts|views|ideas}.

Great {blog|website|site}, {keep it up|continue the good work|stick with it}!
Thank you for the {auspicious|good} writeup. It in fact
was a amusement account it. Look advanced to {far|more} added
agreeable from you! {By the way|However}, how {can|could} we communicate?
{Howdy|Hi there|Hey there|Hello|Hey} just wanted to give you
a quick heads up. The {text|words} in your {content|post|article} seem to be running off the
screen in {Ie|Internet explorer|Chrome|Firefox|Safari|Opera}.
I’m not sure if this is a {format|formatting} issue or something to do with {web browser|internet browser|browser} compatibility but I {thought|figured} I’d post to let you know.
The {style and design|design and style|layout|design} look great though!
Hope you get the {problem|issue} {solved|resolved|fixed} soon.
{Kudos|Cheers|Many thanks|Thanks}|
This is a topic {that is|that’s|which is} {close to|near to} my heart… {Cheers|Many thanks|Best wishes|Take care|Thank you}! {Where|Exactly where} are your contact details though?|
It’s very {easy|simple|trouble-free|straightforward|effortless} to find out any {topic|matter} on {net|web} as compared to {books|textbooks}, as I found this {article|post|piece of writing|paragraph} at this {website|web site|site|web page}.
Does your {site|website|blog} have a contact page?

I’m having {a tough time|problems|trouble} locating it but, I’d like to {send|shoot} you an {e-mail|email}.
I’ve got some {creative ideas|recommendations|suggestions|ideas} for your blog you might be interested in hearing. Either way, great {site|website|blog} and I look forward to seeing it {develop|improve|expand|grow} over time.|
{Hola|Hey there|Hi|Hello|Greetings}! I’ve been {following|reading} your {site|web site|website|weblog|blog} for {a long time|a while|some time}
now and finally got the {bravery|courage} to go ahead and give you a shout out from {New Caney|Kingwood|Huffman|Porter|Houston|Dallas|Austin|Lubbock|Humble|Atascocita} {Tx|Texas}!
Just wanted to {tell you|mention|say} keep up the {fantastic|excellent|great|good} {job|work}!
Greetings from {Idaho|Carolina|Ohio|Colorado|Florida|Los angeles|California}!
I’m {bored to tears|bored to death|bored} at work so I decided to {check out|browse} your {site|website|blog} on my iphone during lunch break. I {enjoy|really like|love} the {knowledge|info|information} you {present|provide} here and can’t wait to take a look when
I get home. I’m {shocked|amazed|surprised} at how {quick|fast} your blog loaded on my {mobile|cell phone|phone} .. I’m not even using WIFI, just
3G .. {Anyhow|Anyways}, {awesome|amazing|very good|superb|good|wonderful|fantastic|excellent|great} {site|blog}!
Its {like you|such as you} {read|learn} my {mind|thoughts}!

You {seem|appear} {to understand|to know|to grasp} {so much|a lot} {approximately|about} this, {like you|such as you}
wrote the {book|e-book|guide|ebook|e book} in it or something.
{I think|I feel|I believe} {that you|that you
simply|that you just} {could|can} do with {some|a few} {%|p.
c.|percent} to {force|pressure|drive|power} the message {house|home} {a
bit|a little bit}, {however|but} {other than|instead of} that, {this
is|that is} {great|wonderful|fantastic|magnificent|excellent} blog.
{A great|An excellent|A fantastic} read. {I’ll|I will} {definitely|certainly} be back.|
I visited {multiple|many|several|various} {websites|sites|web sites|web pages|blogs} {but|except|however} the audio {quality|feature} for audio songs {current|present|existing} at this {website|web site|site|web page} is {really|actually|in fact|truly|genuinely} {marvelous|wonderful|excellent|fabulous|superb}.|
{Howdy|Hi there|Hi|Hello}, i read your blog {occasionally|from time to time} and i own a similar one and i was just {wondering|curious} if you get a lot of spam {comments|responses|feedback|remarks}? If so how do you {prevent|reduce|stop|protect against} it, any plugin or anything you can {advise|suggest|recommend}? I get so much lately it’s driving me {mad|insane|crazy} so any {assistance|help|support} is very much appreciated.
Greetings! {Very helpful|Very useful} advice {within this|in this particular} {article|post}!
{It is the|It’s the} little changes {that make|which will make|that produce|that will make} {the biggest|the largest|the greatest|the most important|the most significant} changes. {Thanks a lot|Thanks|Many thanks} for sharing!|
{I really|I truly|I seriously|I absolutely} love {your blog|your site|your website}.. {Very nice|Excellent|Pleasant|Great} colors & theme. Did you {create|develop|make|build} {this website|this site|this web site|this amazing site} yourself? Please reply back as I’m {looking to|trying
to|planning to|wanting to|hoping to|attempting to} create {my own|my very own|my own personal} {blog|website|site} and {would like to|want
to|would love to} {know|learn|find out} where you got
this from or {what the|exactly what the|just what the} theme {is called|is
named}. {Thanks|Many thanks|Thank you|Cheers|Appreciate
{Hi there|Hello there|Howdy}! This {post|article|blog post} {couldn’t|could not} be written {any better|much better}! {Reading through|Looking at|Going through|Looking through} this {post|article} reminds me of my previous roommate! He {always|constantly|continually} kept {talking about|preaching about} this. {I will|I’ll|I am going to|I most certainly will} {forward|send} {this article|this information|this post} to him.
{Pretty sure|Fairly certain} {he will|he’ll|he’s
going to} {have a good|have a very good|have a great} read.
{Thank you for|Thanks for|Many thanks for|I appreciate you for} sharing!
{Wow|Whoa|Incredible|Amazing}! This blog looks {exactly|just} like my old one!
It’s on a {completely|entirely|totally} different {topic|subject} but it has pretty much the same {layout|page layout} and design. {Excellent|Wonderful|Great|Outstanding|Superb} choice of colors!|
{There is|There’s} {definately|certainly} {a lot to|a great deal to} {know about|learn about|find
out about} this {subject|topic|issue}. {I like|I love|I really like} {all the|all
of the} points {you made|you’ve made|you have made}.|
{You made|You’ve made|You have made} some {decent|good|really
good} points there. I {looked|checked} {on the internet|on
the web|on the net} {for more info|for more information|to find out more|to learn more|for additional information} about the issue
and found {most individuals|most people} will go along with your views on
{this website|this site|this web site}.|
{Hi|Hello|Hi there|What’s up}, I {log on to|check|read} your {new stuff|blogs|blog} {regularly|like every week|daily|on a regular basis}. Your {story-telling|writing|humoristic} style is {awesome|witty}, keep {doing what you’re doing|up
the good work|it up}!|
I {simply|just} {could not|couldn’t} {leave|depart|go away} your {site|web site|website} {prior to|before} suggesting that I {really|extremely|actually} {enjoyed|loved} {the standard|the usual} {information|info} {a person|an individual} {supply|provide} {for your|on your|in your|to your} {visitors|guests}? Is {going to|gonna} be {back|again} {frequently|regularly|incessantly|steadily|ceaselessly|often|continuously} {in order to|to} {check up on|check out|inspect|investigate cross-check} new posts|
{I wanted|I needed|I want to|I need to} to thank you for this {great|excellent|fantastic|wonderful|good|very good} read!! I {definitely|certainly|absolutely} {enjoyed|loved} every {little bit of|bit of} it. {I have|I’ve got|I have got} you {bookmarked|book marked|book-marked|saved as
a favorite} {to check out|to look at} new {stuff you|things you}
{Hi|Hello|Hi there|What’s up}, just wanted to {mention|say|tell you}, I {enjoyed|liked|loved} this {article|post|blog post}. It was {inspiring|funny|practical|helpful}. Keep on posting!|
I {{leave|drop|{write|create}} a {comment|leave a response}|drop a {comment|leave a response}|{comment|leave a response}} {each time|when|whenever} I {appreciate|like|especially enjoy} a {post|article} on a {site|{blog|website}|site|website} or {I have|if I have} something to {add|contribute|valuable to contribute} {to the discussion|to the conversation}. {It is|Usually it is|Usually it’s|It’s} {a result of|triggered by|caused by} the {passion|fire|sincerness} {communicated|displayed} in the {post|article} I {read|looked at|browsed}. And {on|after} this {post|article} Bobobobo’s Weblog | technology and the internets.

I {{was|was actually} moved|{was|was actually} excited} enough to
{drop|{leave|drop|{write|create}}|post} a {thought|{comment|{comment|leave a response}a
response}} {:-P|:)|;)|;-)|:-)} I {do have|actually do have} {{some|a few} questions|a couple of questions|2 questions} for
you {if you {don’t|do not|usually do not|tend not to} mind|if it’s
{allright|okay}}. {Is it|Could it be} {just|only|simply} me or {do|does
it {seem|appear|give the impression|look|look as if|look
like} like} {some|a few} of {the|these} {comments|responses|remarks} {look|appear|come across} {like they are|as if
they are|like} {coming from|written by|left by} brain
dead {people|visitors|folks|individuals}? :-P
And, if you are {posting|writing} {on|at} {other|additional} {sites|social sites|online sites|online
social sites|places}, {I’d|I would} like to {follow|keep up with} {you|{anything|everything} {new|fresh} you have to post}. {Could|Would} you {list|make a list} {all|every one|the complete urls} of {your|all your} {social|communal|community|public|shared} {pages|sites} like your {twitter feed, Facebook page or linkedin profile|linkedin profile, Facebook page or twitter feed|Facebook page, twitter feed, or linkedin profile}?|
{Hi there|Hello}, I enjoy reading {all of|through} your {article|post|article post}. I {like|wanted} to write a little comment to support you.|
I {always|constantly|every time} spent my half an hour to read this {blog|weblog|webpage|website|web site}’s
{articles|posts|articles or reviews|content} {everyday|daily|every day|all the time} along with a {cup|mug} of coffee.
I {always|for all time|all the time|constantly|every time} emailed this {blog|weblog|webpage|website|web site}
post page to all my {friends|associates|contacts}, {because|since|as|for the reason that} if like to read it {then|after that|next|afterward} my {friends|links|contacts} will too.
My {coder|programmer|developer} is trying to {persuade|convince} me to
move to .net from PHP. I have always disliked the idea because of the {expenses|costs}.
But he’s tryiong none the less. I’ve been using {Movable-type|WordPress} on {a number of|a variety of|numerous|several|various} websites for about a year and am {nervous|anxious|worried|concerned} about switching to
another platform. I have heard {fantastic|very good|excellent|great|good} things about blogengine.
net. Is there a way I can {transfer|import} all my wordpress {content|posts}
into it? {Any kind of|Any} help would be {really|greatly} appreciated!
{Hello|Hi|Hello there|Hi there|Howdy|Good day}! I could
have sworn I’ve {been to|visited} {this blog|this web site|this website|this site|your blog} before but after {browsing through|going through|looking at} {some of the|a few of the|many of the} {posts|articles} I realized it’s new to me.
{Anyways|Anyhow|Nonetheless|Regardless}, I’m {definitely|certainly} {happy|pleased|delighted} {I found|I discovered|I came across|I stumbled upon} it and I’ll
be {bookmarking|book-marking} it and checking back {frequently|regularly|often}!
{Terrific|Great|Wonderful} {article|work}! {This is|That is} {the type of|the kind of} {information|info} {that are
meant to|that are supposed to|that should} be shared {around the|across the} {web|internet|net}.
{Disgrace|Shame} on {the {seek|search} engines|Google} for {now not|not|no longer} positioning this {post|submit|publish|put up} {upper|higher}!
Come on over and {talk over with|discuss with|seek advice from|visit|consult with} my {site|web site|website} .
{Thank you|Thanks} =)|
Heya {i’m|i am} for the first time here. I {came across|found} this board and I find It {truly|really} useful & it helped me out {a lot|much}. I hope to give something back and {help|aid} others like you {helped|aided} me.|
{Hi|Hello|Hi there|Hello there|Howdy|Greetings}, {I think|I believe|I do believe|I do think|There’s no
doubt that} {your site|your website|your web site|your
blog} {might be|may be|could be|could possibly be} having {browser|internet browser|web
browser} compatibility {issues|problems}. {When I|Whenever I}
{look at your|take a look at your} {website|web site|site|blog} in
Safari, it looks fine {but when|however when|however, if|however,
when} opening in {Internet Explorer|IE|I.E.}, {it has|it’s got} some overlapping issues. {I just|I simply|I merely} wanted to {give you a|provide you with a} quick heads up! {Other than that|Apart from that|Besides that|Aside from that}, {fantastic|wonderful|great|excellent} {blog|website|site}!|
{A person|Someone|Somebody} {necessarily|essentially} {lend a hand|help|assist} to make {seriously|critically|significantly|severely} {articles|posts} {I would|I might|I’d} state.
{This is|That is} the {first|very first} time I frequented your {web page|website page} and
{to this point|so far|thus far|up to now}? I {amazed|surprised} with the {research|analysis} you made to {create|make} {this
actual|this particular} {post|submit|publish|put up} {incredible|amazing|extraordinary}.
{Great|Wonderful|Fantastic|Magnificent|Excellent} {task|process|activity|job}!
Heya {i’m|i am} for {the primary|the first} time here. I {came across|found} this board and I {in finding|find|to find} It {truly|really} {useful|helpful} & it helped me out {a lot|much}. {I am hoping|I hope|I’m hoping} {to give|to
offer|to provide|to present} {something|one thing} {back|again} and {help|aid} others {like you|such as you} {helped|aided} me.
{Hello|Hi|Hello there|Hi there|Howdy|Good day|Hey there}!
{I just|I simply} {would like to|want to|wish to} {give you a|offer you a} {huge|big} thumbs up {for the|for
your} {great|excellent} {info|information} {you have|you’ve got|you have got} {here|right here} on this post. {I will be|I’ll be|I am} {coming back to|returning to} {your blog|your site|your website|your web site} for more soon.
I {always|all the time|every time} used to {read|study} {article|post|piece of writing|paragraph}
in news papers but now as I am a user of {internet|web|net} {so|thus|therefore} from
now I am using net for {articles|posts|articles or reviews|content}, thanks to web.
Your {way|method|means|mode} of {describing|explaining|telling} {everything|all|the whole
thing} in this {article|post|piece of writing|paragraph} is
{really|actually|in fact|truly|genuinely} {nice|pleasant|good|fastidious}, {all|every
one} {can|be able to|be capable of} {easily|without difficulty|effortlessly|simply}
{understand|know|be aware of} it, Thanks a lot.
{Hi|Hello} there, {I found|I discovered} your {blog|website|web site|site} {by means of|via|by the use of|by way of} Google {at the same time as|whilst|even as|while} {searching for|looking for} a {similar|comparable|related} {topic|matter|subject}, your {site|web site|website} {got here|came} up, it {looks|appears|seems|seems to
be|appears to be like} {good|great}. {I have|I’ve} bookmarked it in my google bookmarks.
{Hello|Hi} there, {simply|just} {turned into|became|was|become|changed into} {aware of|alert to} your {blog|weblog} {thru|through|via} Google, {and found|and located} that {it is|it’s}
{really|truly} informative. {I’m|I am} {gonna|going to} {watch out|be careful} for brussels. {I will|I’ll} {appreciate|be grateful}
{if you|should you|when you|in the event you|in case
you|for those who|if you happen to} {continue|proceed} this {in future}.
{A lot of|Lots of|Many|Numerous} {other folks|folks|other people|people} {will be|shall be|might be|will probably be|can be|will likely
be} benefited {from your|out of your} writing.

{I am|I’m} curious to find out what blog {system|platform} {you have been|you happen to be|you are|you’re} {working with|utilizing|using}?

I’m {experiencing|having} some {minor|small} security {problems|issues} with my latest {site|website|blog} and {I would|I’d} like to find something more {safe|risk-free|safeguarded|secure}.
Do you have any {solutions|suggestions|recommendations}?|
{I am|I’m} {extremely|really} impressed with your writing skills {and also|as well as} with the layout on your {blog|weblog}. Is this a paid theme or did you {customize|modify} it yourself? {Either way|Anyway} keep up the {nice|excellent} quality writing, {it’s|it is} rare
to see a {nice|great} blog like this one {these days|nowadays|today}.
{I am|I’m} {extremely|really} {inspired|impressed} {with your|together with your|along with your} writing {talents|skills|abilities} {and also|as {smartly|well|neatly} as} with the {layout|format|structure} {for your|on your|in your|to your} {blog|weblog}. {Is this|Is that this} a paid {subject|topic|subject matter|theme} or did you {customize|modify} it {yourself|your self}? {Either way|Anyway} {stay|keep} up the {nice|excellent} {quality|high quality} writing, {it’s|it is}
{rare|uncommon} {to peer|to see|to look} a {nice|great} {blog|weblog} like this
one {these days|nowadays|today}..|
{Hi|Hello}, Neat post. {There is|There’s} {a problem|an issue} {with your|together with your|along with your} {site|web site|website} in {internet|web} explorer, {may|might|could|would} {check|test} this? IE {still|nonetheless} is the {marketplace|market} {leader|chief} and {a large|a good|a big|a huge} {part of|section of|component to|portion of|component of|element of} {other folks|folks|other people|people} will {leave out|omit|miss|pass over} your {great|wonderful|fantastic|magnificent|excellent} writing {due to|because of} this problem.|
{I’m|I am} not sure where {you are|you’re} getting your {info|information}, but {good|great} topic. I needs to spend some time learning {more|much more} or understanding more. Thanks for {great|wonderful|fantastic|magnificent|excellent} {information|info} I was looking for this {information|info} for my mission.|
{Hi|Hello}, i think that i saw you visited my {blog|weblog|website|web site|site} {so|thus} i came to “return the favor”.{I am|I’m}
{trying to|attempting to} find things to {improve|enhance} my {website|site|web site}!
I suppose its ok to use {some of|a few of} your ideas!


GKMatch is weird. You don’t ever instantiate GKMatch directly. Instead you use GKMatchMaker as a type of “factory” to instantiate GKMatch objects.

There are basically 2 ways to get a GKMatch up and running.

1) BOOTY CALLS: I call out people I want to have sex with have a match with BY NAME.

2) RANDOM ENCOUNTER: All players initiated THEIR OWN random partner search, and GameCenter “hooked them up” with a random partner.

First we’ll cover booty calls, then random encounters.

1. Booty call

BOOTY CALL works as follows. ONE OF THE PLAYERS (the “horny dude”) INVITES ALL THE OTHER PLAYERS BY NAME. He can invite as many players as he wishes (mm hmm). ALL PLAYERS WHO WANT TO ACCEPT INVITES BY NAME __MUST__ HAVE REGISTERED TO RECEIVE “BOOTY CALLS” BY SETTING [GKMatchmaker sharedMatchmaker].inviteHandler. We’ll call those players “the booty”.

[GKMatchmaker sharedMatchmaker].inviteHandler = ^( GKInvite *acceptedInvite, NSArray *playersToInvite )
  printf( "You got an invitation to join a match started by `%s`\n", [acceptedInvite.inviter UTF8String] );
  [ [GKMatchmaker sharedMatchmaker] matchForInvite:acceptedInvite completionHandler:^( GKMatch *theMatch, NSError *nsError ) {
    if( nsError ) {
      error( nsError, "matchForInvite:acceptedInvite" ) ; // prints the error (using my `error` function)
      return ;

    Game->match = theMatch ; /////////////// YOU MUST DO THIS.
    // ATTACH YOUR GKMatchDelegate.  __YOU MUST DO THIS__
    // otherwise you have no chance in hell of making a GKMatch work.
    // I instantiated myGameMatchDelegate OUTSIDE this function.
    // instantiating it here gives an ARC error. 
    theMatch.delegate = myGameMatchDelegate ; // myGameMatchDelegate implements GKMatchDelegate protocol

    // Now after this, your GKMatchDelegate match:player:didChangeState: event will trigger
    // automatically.  You can continue to do network setup there.  From that point forward
    // the machines are "having sex" (network connected).
 } ] ;
} ;

The “horny dude” who initiates the booty call does so like this:

GKMatchRequest *request = [[GKMatchRequest alloc] init] ; 
request.minPlayers = 2 ; // INCLUDES YOU.  "The minimum number of players must be at least 2."
request.maxPlayers = 2 ;
request.defaultNumberOfPlayers = 2 ;
request.playerAttributes = 0 ; // NO SPECIAL ATTRIBS
request.playerGroup = 0 ;

// Only for when you have another user to play with BYNAME.
request.playersToInvite = [[NSArray alloc] initWithObjects:@"G:1928347891235", nil] ; //G:1928347891235 is
// the ID of the player I want to booty call.

// A block to be called when a response from an invited BY NAME player is returned to your game.
request.inviteeResponseHandler = ^( NSString *playerID, GKInviteeResponse response )
  printf( "\n*** `%s` RESPONDED TO YOUR INVITE WITH `%s`\n", 
  [playerID UTF8String], GKInviteeResponseName[response] ) ;
} ;

request.inviteMessage = @"COME PLAY WITH ME" ; // This appears in a game center notification notice.
// This is like a GKMatch constructor for the caller.
// It usually completes almost IMMEDIATELY.
[ [GKMatchmaker sharedMatchmaker] findMatchForRequest:request
   withCompletionHandler:^( GKMatch *newMatch, NSError *nsError )
    if( nsError ) {
      error( nsError, "[MM findMatchForRequest] failed" ) ;
      return ;
    // This is the chance to finish setting up the GKMatch object.
    newMatch.delegate = myGameDelegate ; // YOU HAVE TO SET THE DELEGATE.
    Game->match = newMatch ; // YOU MUST DO THIS.
] ;

So after the booty call goes out, OTHER PLAYERS RECEIVE THE INVITATIONS AND ACCEPT IT (Note: requires VIA GC OVERLAY).


BOTH PLAYERS ARE LOOKING FOR “RANDOM ENCOUNTERS”. They put on makeup/shave as appropriate. They then EACH INVOKE findMatchForRequest, BUT WITHOUT SPECIFYING OTHER PLAYER NAMES TO HOOK UP WITH. In other words, they’re looking to hook up with just anybody. GAMECENTER WILL “HOOK THEM UP” WITH RANDOM PARTNERS (TO HAVE SEX WITH).

The code that both players call then, to say to GameCenter they are DTF with just about anyone, is very similar to the code used “make a booty call” above. You just don’t fill out the playerIDs field (leave it nil).

GKMatchRequest *request = [[GKMatchRequest alloc] init] ; 
request.minPlayers = 2 ; // INCLUDES YOU.  "The minimum number of players must be at least 2."
request.maxPlayers = 2 ;
request.defaultNumberOfPlayers = 2 ;
request.playerAttributes = 0 ; // NO SPECIAL ATTRIBS
request.playerGroup = 0 ;

request.playersToInvite = nil ; // NIL THAT
// This is like a GKMatch constructor for the caller.
// It completes IMMEDIATELY.
[ [GKMatchmaker sharedMatchmaker] findMatchForRequest:request
   withCompletionHandler:^( GKMatch *newMatch, NSError *nsError )
    if( nsError ) {
      error( nsError, "[MM findMatchForRequest] failed" ) ;
      return ;
    // This is the chance to finish setting up the GKMatch object.
    newMatch.delegate = myGameDelegate ; // YOU HAVE TO SET THE DELEGATE.
    Game->match = newMatch ; // YOU MUST DO THIS.
] ;

I don’t have any real technical reason for hating exceptions. I simply hate exceptions in a stylistic sense.

Exceptions are a retroactive way of handling error conditions. They kind of say “Yeah try this, if that doesn’t work, then do that.”

  to parse the value out of the string
catch( ValueParsingException ex )
  not a valid value..?

Seems like a manager with a bad attitude. Like “Yeah try it, whatever, and if that doesn’t work, then do this other thing”. Sure, technically it’s very clear what the code is doing. But to me, (mostly because I’ve seen too many 200 line try/catch blocks), try/catch will always be a code structure very readily abused.

I generally hate people that say they will do one thing, then partway through they say “No, go back” and start doing something else. But that is exactly the language of a try/catch block.

Exceptions are like walking across the street without looking:

  to cross the street
catch( BusHitException busException )
  go to hospital?

I much prefer a series of rigorous if statements to try/catch blocks where possible. I’d much rather have code like this:

if( the string is valid )
  parse the value out of the string
  not a valid value.

So in other words, look before crossing:

if( there are no cars )
  cross the street

That would be more like a while loop, but you get the idea.

If statements say “I’m watching what is going on, this code knows what its doing.”

Sure, you can achieve the exact same ends with try/catch as with if/else. But try/catch all too often is used as sloppy code. I hate when exceptions are used in the generic “If something goes wrong then just throw that general error “Uh there was an exception” and printstacktrace.”

Have you ever seen one of those 200 line try blocks? Disgusting. People use them because they don’t know/they don’t care what is going wrong.

Try/catch can too easily be abused. That’s why I hate it as a programming construct.

Funky Inheritance

Or functor-based inheritance

Funky inheritance is my name for when you allow attachment of functors to specify behavior instead of always just subclassing.

This came up recently in some UI event handling code that I was writing. Buttons come and go, dialogs appear and get dismissed. Each dialog dismissal button (okButton) needs something specific to happen, but that same functionality is extremely unlikely to be reused in another dialog.

Normally, to write an object type that has customizable behavior (by a subclass), you would write a base class like this:

class Dialog
  virtual void onDismiss() = 0 ;

So, when you subclass Dialog, you override onDismiss to provide custom behavior that occurs when the dialog is dismissed (assume onDismiss would be invoked by a window manager).

class FileOpenDialog : public Dialog
  virtual void onDismiss()
    // stuff to do when the FileOpenDialog is dismissed..

So, that’s the regular (classical) inheritance pattern. Every time you want different functionality onDismiss(), you’d write a new subclass of Dialog. Another way to get custom code to run onDismiss is to allow onDismiss() to accept a functor that can be invoked …

class FileOpenDialog : public Dialog
  virtual void onDismiss( function <void ()> runThisAfter )
    // stuff to do when the FileOpenDialog is dismissed..
    // then..
    runThisAfter() ;


You could write onDismiss as a functor in base class Dialog instead of using classical inheritance here:

class Dialog
  function< void (Dialog* that) > onDismiss ;

Now onDismiss is a functor (that may or may not be set).

So then customized behavior is by instance, not by class. Creating a FileOpenDialog object would then be like:

Dialog fileOpenDialog ;
fileOpenDialog.onDismiss = [](Dialog* that) {
  // Do something with `that`, which acts as `this`
  // if this were a member function ;)
} ;

When the window object handler finds out a dialog has been dismissed, it invokes the onDismiss handler if it has been set.

// It is detected that fileOpenDialog needs to be closed:
if( fileOpenDialog.onDismiss )
  fileOpenDialog.onDismiss( fileOpenDialog ) ;

// Above line manually passes `this`.
// If I am not mistaken, this is considered "Pythonic" (just kidding,
// but Python does require passing of self in a similarly visible fashion)

This may come across to you as very JavaScripty- or follow a prototypal inheritance pattern. But it actually isn’t prototypal inheritance, because objects do not inherit from other objects. Each instance of Dialog has its own behavior, that is not repeated by any other instance of Dialog.

Of course, this would need some more detail and fleshing out to really work. But this is the jist of funky inheritance. Regular inheritance is class-wide customization. Funky inheritance is instance-wide customization. Funky inheritance is great for when you need to define custom behavior (often one-off, for a button or a widget) without having to define an entire subclass.

Drawbacks of Funky Inheritance

Functors are unable to persist their own internal running state except as static variables. However statics inside a functor are inaccessible from outside the functor. This means modification of a functor’s internal values is difficult/impossible from outside the functor. So, that kind of sucks sometimes.

One way you can modify a functor’s internal state variables is to capture a pointer before entering the functor:

Object * someObject = new Object() ;
functor = [ someObject ]() {
  // now if someObject is modified outside the functor,
  // I will use "the most up to date" version of someObject.
} ;

Functors seem to be best used to send global state messages or somehow modify global state. For example, if a FileOpenDialog is modal, it may flip off the `modal` flag inside your window manager when it is dismissed. Functors are also useful to modify the object running the functor’s state as well.

GameCenter isn’t easy to work with. For one it’s networking, and networking errors are hard to debug because there’s no natural UI. debug print messages is all you’ve got. It doesn’t help that GC is none too detailed on what you did wrong, and sometimes weird errors can occur if you use the API incorrectly.

1. A match request by name can take up to 2 minutes to reach the remote device. Unprepared for this I’d just sit there trying the request again and again, wondering why it wasn’t working.

2. The iOS simulator doesn’t seem to work for GKMatchmaker requests. I don’t know why this is, but the iOS simulator cannot even startBrowsingForNearbyPlayersWithReachableHandler.


I created an xml file with my newest XCode C++ theme.

It looks like this:

So, gray background, white text, all numeric constants and defines are kinda blue, classes are purple, and C preprocessor macros are red.

The factory pattern is most useful when an object type cannot and should not be used independently of some master managing class.

An analogy would be if you have a Theater as the "Master class" (factory) and the objects that are created in the factory are Tickets. So you have to ask the Master Theater class for a new Ticket() whenever you want one. The Master class can now remember that it has sold you a Ticket and that there is one additional Ticket in the system. Tickets aren’t useful at all if the ticket issuer disappeared. Notice this is much better than having a system where Tickets are created with no reference to a Theater, but then are registered to a theater after creation. That would be like "counterfeit your ticket, then call us and tell us you have a ticket to our Theater".

And so the factory pattern makes perfect sense here.

Objects make the most sense in the context of encapsulating code that:

  • Has some mandatory startup that must run (constructors), otherwise the related functions won’t work
  • Has a family of related functions, but not all of them should be called by the class user (private)
  • Has some cleanup routines that should be called when the user is done (destructor)

An example of this is my SecKeyHelper.h file I wrote today. That file is just C functions, but there is some code that must be called before any of the related functions work. On top of that, only 2 functions should really be called by the class user.

Public key loading, private key loading, it’s all very easy with OpenSSL on Linux. You must link the libcrypto.dylib library in XCode for this to work.

XCode 4.6 project download here

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
// I'm not using BIO for base64 encoding/decoding.  It is difficult to use.
// Using superwills' Nibble And A Half instead 
#include "base64.h"
// The PADDING parameter means RSA will pad your data for you
// if it is not exactly the right size
RSA* loadPUBLICKeyFromString( const char* publicKeyStr )
  // A BIO is an I/O abstraction (Byte I/O?)
  // BIO_new_mem_buf: Create a read-only bio buf with data
  // in string passed. -1 means string is null terminated,
  // so BIO_new_mem_buf can find the dataLen itself.
  // Since BIO_new_mem_buf will be READ ONLY, it's fine that publicKeyStr is const.
  BIO* bio = BIO_new_mem_buf( (void*)publicKeyStr, -1 ) ; // -1: assume string is null terminated
  BIO_set_flags( bio, BIO_FLAGS_BASE64_NO_NL ) ; // NO NL
  // Load the RSA key from the BIO
  RSA* rsaPubKey = PEM_read_bio_RSA_PUBKEY( bio, NULL, NULL, NULL ) ;
  if( !rsaPubKey )
    printf( "ERROR: Could not load PUBLIC KEY!  PEM_read_bio_RSA_PUBKEY FAILED: %s\n", ERR_error_string( ERR_get_error(), NULL ) ) ;
  BIO_free( bio ) ;
  return rsaPubKey ;
RSA* loadPRIVATEKeyFromString( const char* privateKeyStr )
  BIO *bio = BIO_new_mem_buf( (void*)privateKeyStr, -1 );
  //BIO_set_flags( bio, BIO_FLAGS_BASE64_NO_NL ) ; // NO NL
  RSA* rsaPrivKey = PEM_read_bio_RSAPrivateKey( bio, NULL, NULL, NULL ) ;
  if ( !rsaPrivKey )
    printf("ERROR: Could not load PRIVATE KEY!  PEM_read_bio_RSAPrivateKey FAILED: %s\n", ERR_error_string(ERR_get_error(), NULL));
  BIO_free( bio ) ;
  return rsaPrivKey ;
unsigned char* rsaEncrypt( RSA *pubKey, const unsigned char* str, int dataSize, int *resultLen )
  int rsaLen = RSA_size( pubKey ) ;
  unsigned char* ed = (unsigned char*)malloc( rsaLen ) ;
  // RSA_public_encrypt() returns the size of the encrypted data
  // (i.e., RSA_size(rsa)). RSA_private_decrypt() 
  // returns the size of the recovered plaintext.
  *resultLen = RSA_public_encrypt( dataSize, (const unsigned char*)str, ed, pubKey, PADDING ) ; 
  if( *resultLen == -1 )
    printf("ERROR: RSA_public_encrypt: %s\n", ERR_error_string(ERR_get_error(), NULL));
  return ed ;
unsigned char* rsaDecrypt( RSA *privKey, const unsigned char* encryptedData, int *resultLen )
  int rsaLen = RSA_size( privKey ) ; // That's how many bytes the decrypted data would be
  unsigned char *decryptedBin = (unsigned char*)malloc( rsaLen ) ;
  *resultLen = RSA_private_decrypt( RSA_size(privKey), encryptedData, decryptedBin, privKey, PADDING ) ;
  if( *resultLen == -1 )
    printf( "ERROR: RSA_private_decrypt: %s\n", ERR_error_string(ERR_get_error(), NULL) ) ;
  return decryptedBin ;
unsigned char* makeAlphaString( int dataSize )
  unsigned char* s = (unsigned char*) malloc( dataSize ) ;
  int i;
  for( i = 0 ; i < dataSize ; i++ )
    s[i] = 65 + i ;
  s[i-1]=0;//NULL TERMINATOR ;)
  return s ;
// You may need to encrypt several blocks of binary data (each has a maximum size
// limited by pubKey).  You shoudn't try to encrypt more than
// RSA_LEN( pubKey ) bytes into some packet.
// returns base64( rsa encrypt( <<binary data>> ) )
// base64OfRsaEncrypted()
// base64StringOfRSAEncrypted
// rsaEncryptThenBase64
char* rsaEncryptThenBase64( RSA *pubKey, unsigned char* binaryData, int binaryDataLen, int *outLen )
  int encryptedDataLen ;
  // RSA encryption with public key
  unsigned char* encrypted = rsaEncrypt( pubKey, binaryData, binaryDataLen, &encryptedDataLen ) ;
  // To base 64
  int asciiBase64EncLen ;
  char* asciiBase64Enc = base64( encrypted, encryptedDataLen, &asciiBase64EncLen ) ;
  // Destroy the encrypted data (we are using the base64 version of it)
  free( encrypted ) ;
  // Return the base64 version of the encrypted data
  return asciiBase64Enc ;
// rsaDecryptOfUnbase64()
// rsaDecryptBase64String()
// unbase64ThenRSADecrypt()
// rsaDecryptThisBase64()
unsigned char* rsaDecryptThisBase64( RSA *privKey, char* base64String, int *outLen )
  int encBinLen ;
  unsigned char* encBin = unbase64( base64String, (int)strlen( base64String ), &encBinLen ) ;
  // rsaDecrypt assumes length of encBin based on privKey
  unsigned char *decryptedBin = rsaDecrypt( privKey, encBin, outLen ) ;
  free( encBin ) ;
  return decryptedBin ;
int main( int argc, const char* argv[] )
  puts( "We are going to: rsa_decrypt( unbase64( base64( rsa_encrypt( <<binary data>> ) ) ) )" );
  // public key
  //1. The file must contain:
  //on a separate line (i.e. it must be terminated with a newline).
  //2. Each line of "gibberish" must be 64 characters wide.
  //3. The file must end with:
  //-----END CERTIFICATE-----
  // YOUR PUBLIC KEY MUST CONTAIN NEWLINES.  If it doesn't (ie if you generated it with
  // something like
  // ssh-keygen -t rsa -C ""
  // ) THEN YOU MUST INSERT NEWLINES EVERY 64 CHRS (just line it up with how I have it here
  // or with how the ssh-keygen private key is formatted by default)
  const char *b64_pKey = "-----BEGIN PUBLIC KEY-----\n"
  "-----END PUBLIC KEY-----\n";
  // private key
  const char *b64priv_key = "-----BEGIN RSA PRIVATE KEY-----\n"
  "-----END RSA PRIVATE KEY-----\n";
  // String to encrypt, INCLUDING NULL TERMINATOR:
  int dataSize=37 ; // 128 for NO PADDING, __ANY SIZE UNDER 128 B__ for RSA_PKCS1_PADDING
  unsigned char *str = makeAlphaString( dataSize ) ;
  printf( "\nThe original data is:\n%s\n\n", (char*)str ) ;
  RSA *pubKey = loadPUBLICKeyFromString( b64_pKey ) ;
  int asciiB64ELen ;
  char* asciiB64E = rsaEncryptThenBase64( pubKey, str, dataSize, &asciiB64ELen ) ;
  RSA_free( pubKey ) ; // free the public key when you are done all your encryption
  printf( "Sending base64_encoded ( rsa_encrypted ( <<binary data>> ) ):\n%s\n", asciiB64E ) ;
  puts( "<<----------------  SENDING DATA ACROSS INTERWEBS  ---------------->>" ) ;
  char* rxOverHTTP = asciiB64E ; // Simulate Internet connection by a pointer reference
  printf( "\nRECEIVED some base64 string:\n%s\n", rxOverHTTP ) ;
  puts( "\n * * * What could it be?" ) ;
  // Now decrypt this very string with the private key
  RSA *privKey = loadPRIVATEKeyFromString( b64priv_key ) ;
  // Now we got the data at the server.  Time to decrypt it.
  int rBinLen ;
  unsigned char* rBin = rsaDecryptThisBase64( privKey, rxOverHTTP, &rBinLen ) ;
  printf("Decrypted %d bytes, the recovered data is:\n%.*s\n\n", rBinLen, rBinLen, rBin ) ; // rBin is not necessarily NULL
  // terminated, so we only print rBinLen chrs
  RSA_free(privKey) ;
  bool allEq = true ;
  for( int i = 0 ; i < dataSize ; i++ )
    allEq &= (str[i] == rBin[i]) ;
  if( allEq ) puts( "DATA TRANSFERRED INTACT!" ) ;
  else puts( "ERROR, recovered binary does not match sent binary" ) ;
  free( str ) ; 
  free( asciiB64E ) ; // rxOverHTTP  
  free( rBin ) ;

Rae Johnston posts about an experience in a Starbucks’ involving a Bioshock Infinite t-shirt.

I am not sticking up for that guy. He sounds like a loser. But I want to explain what I think is behind that behavior.

First of all reading her top tweets you can see she gets a lot of flack for being a girl gamer. That brings us to the first point:

Any guys that give girl gamers flack for being a girl are sexist guys period. They’re losers. The girl is on “their turf” so they subject her to bad treatment. Only losers do that and there’s no excuse for it.

Second is the encounter with that guy that got almost 10k retweets. The thing there is, there is already a bunch of internet memes about gamer girls who pretend to like games, only to get guys’ attention.

Also you have to keep in mind the shock value of hot girl gamers. Although this might not be true nerdy guys immediately think they have a shot at the nerdy hot girl. Because! Finally! A hot chick who digs the things I do. We’re on the same page! Blah blah blah.

He did a stupid thing calling you out rudely for the shirt. He was a moron. But these are just thoughts on what is going through nerds’ heads.

I can never find this when I’m looking for it, so I dedicated a whole blog post to it.


The easiest way I’ve found to generate a random alphanumeric string involves RAND(), SHA(), and TO_BASE64()

select LEFT( TO_BASE64( SHA(rand()) ), 6 ) ;

You need MySQL 5.6 to execute.

Alternatively some MYSQL Procedures magic


drop function if exists randChr //
create function randChr()
returns char
  IF RAND() <= 0.5 THEN -- Lowercase
	return CHAR( 97 + 25*rand() ) ;
  ELSE -- uc
    return CHAR( 65 + 25*rand() ) ;
END //

drop function if exists randString //
create function randString( len int )
returns varchar(255)
  SET @n = 0;
  SET @res = '' ;
    SET @res = concat( @res, randChr() ) ;
    set @n = @n + 1 ;
  UNTIL @n >= len END REPEAT;
  return @res ;
END //


select randString( 5 );

Starting from my previous program (Windows), connecting in Mac OS X is even EASIER, only there are a couple’a gotchas.

To code with MYSQL in Mac OS X, just install MySQL normally. In fact it comes with the `/include` and `/lib` folders when you installed it. They are in `/usr/local/mysql` (which is a link to the specific version you have).

Ok, now that’s done, here’s your C++ program:

#include <stdio.h>
#include <stdlib.h>
#include "/usr/local/mysql/include/mysql.h"

MYSQL mysql;    // MYSQL global
MYSQL * conn ;  // represents connection to database

int main()
  mysql_init( &mysql ) ;
  conn = mysql_real_connect(  &mysql,
                              "localhost",// synonymous with
                              "root",     // connect as user="root".  Uh, bad security here..
                              "",         // my root password is blank.  REALLY bad security :)
                              "mysql",    // connect to the 'mysql' _database_ within MySQL itself.
                               0, 0, 0 ) ;
  // Check if connection succeeded.
  if( !conn )
    printf( "Couldn't connect to MySQL database server!\n" ) ;
    printf( "Error: %s\n", mysql_error( &mysql ) ) ;
    return 1 ;
  //else  puts( "Connect success" ) ;
  // Here, we are connected.
  // form a sql string to execute.
  if( mysql_query( conn, "select * from user" ) )
    printf("Whoops!  The query failed.  Error:  %s\n", mysql_error( conn ) );
    return 1 ;

  // here, query succeeded, so we can proceed to pull out results.
  MYSQL_RES * resultset ;
  MYSQL_ROW row;  // MYSQL_ROW is #defined as (char **)
  // Data ALWAYS comes back from MySQL as
  // an array of strings.  To convert it
  // to ints or whatever is YOUR JOB as the programmer.

  // mysql_store_result basically fetches
  // the entire array of results and dumps them
  // into our local program memory space (all
  // in the resultset variable.
  resultset = mysql_store_result( conn );

  // How many rows will there be?
  my_ulonglong numRows = mysql_num_rows( resultset ) ;
  printf( "There are %llu ROWS (records) of data\n", numRows ) ;
  // Now tell me what columns there are
  // in the result set.
  int numFields = mysql_num_fields( resultset ) ;
  printf( "There are %d FIELDS (columns) of data\n", numFields ) ;

  // Print all those column by name
  MYSQL_FIELD * fields = mysql_fetch_fields( resultset ) ;
  for( int i = 0 ; i < numFields ; i++ )
    printf( "%25s", fields[i].name ) ;

  printf( "\n" ) ;
  // print all results
  while( (row = mysql_fetch_row( resultset )) )
    // row is 2d array of char
    // underlying type is char **
    for ( int i = 0; i < numFields ; i++ )
      printf( "%5s", row[ i ] ) ;
    puts( "" ) ;    // next row
  mysql_free_result( resultset );  // Now free the result
  mysql_close( conn ) ;  // And close down.
  return 0;

GOTCHA #1: An easy one, but you need to link up your TARGET with the libmysqlclient.a library file. So goto your TARGETS / BUILD PHASES tab, under “Link Binary With Libraries” go select “libmysqlclient.a” from /usr/local/mysql/lib.
GOTCHA #2: This is the stupid one, COPY /usr/local/mysql/lib/libmysqlclient.18.dylib to /usr/lib/. ISN’T THAT DUMB??? Well it’s the eq of copying a DLL to C:\Windows\System32 on Windows. Just something you have to do.

If you don’t copy the .dylib you’ll get Library not loaded: libmysqlclient.16.dylib reason: image not found.

The easiest.

1. Mac OS X

sudo apachectl start

Make sure cgi is enabled in your Apache settings

sudo vi /etc/apache2/httpd.conf

Create and build the following:

#include <stdio.h>

int main(int argc, const char * argv[])
  //puts( "HTTP/1.1 200 OK" ) ;
  puts( "Content-Type: text/plain; charset=UTF-8" ) ;
  puts( "Status: 200 OK" ) ;
  puts( "" ) ;
  puts( "HELLO INTERNET" ) ;

The default folder Xcode 4.6 dumps the exec in is


Take the exec (called PROJECTNAME) and drop it into:


hit http://localhost/cgi-bin/YOUREXECNAME

It should say HELLO INTERNET.

You are on your way to C++ internet freedom

I simulated some game results. In the sim, Player 2 was so bad, he was 0 for 680. The ranking algorithm ranked him first though, because he sucked so bad, he kept on losing increasingly large quantities of negative points for each match he lost.

It is possible! This table shows it as a sort of nested table.


Get every new post delivered to your Inbox.

Join 44 other followers