Skip to content

Instantly share code, notes, and snippets.

View greggman's full-sized avatar
😁

Greggman greggman

😁
View GitHub Profile
@greggman
greggman / gist:9047289
Created February 17, 2014 09:11
Show GL matrix storage

this code

void printMat(const char* l) {
    float mat[16] = { 0, };
    glGetFloatv(GL_MODELVIEW_MATRIX, mat);
    printf("%s\n", l);
    printf("%f %f %f %f\n", mat[0], mat[1], mat[2], mat[3]);
    printf("%f %f %f %f\n", mat[4], mat[5], mat[6], mat[7]);
    printf("%f %f %f %f\n", mat[8], mat[9], mat[10], mat[11]);

printf("%f %f %f %f\n", mat[12], mat[13], mat[14], mat[15]);

@greggman
greggman / gist:9553597
Created March 14, 2014 18:18
dns server that directs all traffic to the machine its on
# requires https://github.com/tjfontaine/node-dns
var os = require('os')
var dns = require('native-dns');
var server = dns.createServer();
var port = 53;
var interfaces = os.networkInterfaces();
var addresses = [];
for (k in interfaces) {
@greggman
greggman / SetFrustumToSubRectOfLargerView.c
Created April 10, 2014 17:42
Set a frustum to a sub rect of a larger view
void SetFrustumToSubRectOfLargerView(
float fullWidth, // width of large 'virtual' monitor that other views will be sub rect of
float fullHeight, // height of large 'virtual' monitor that other views will be sub rect of
float subRectX, // left edge of sub rect for this view
float subRectY, // top edge of sub rect for this view
float subRectWidth, // width of sub rect for this view
float subRectHeight, // height of sub rect fo this view
float fovInRadians, // field of view in radians for fullwidth x fullheight view.
float zNear, // z near clipping plane
float zFar) // z far clipping plane
@greggman
greggman / foo.js
Created May 3, 2014 09:39
Closure no like?
/**
* Some class
* @constructor
* @param {string} name The name.
*/
var Employee = (function(){
// private static field
// @type {string}
var staticVar;
@greggman
greggman / testme.js
Created May 27, 2014 12:27
works on JSDoc 3.3.0-alpha5 with Java but not with node.js
/*
* Some license text, bla bla bal
*/
"use strict";
define(['./somelibrary'], function(SomeLibrary) {
/**
* @typedef {Object} FooThing~Options
function resize() {
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (canvas.width != width ||
canvas.height != height) {
canvas.width = width;
canvas.height = height;
}
}
@greggman
greggman / foo.md
Created November 21, 2014 08:33
Answer on SO is wrong

Make any empty repo

$ mkdir test
$ cd test
$ git init
Initialized empty Git repository in /Users/gregg/temp/delme-git/.git/
@greggman
greggman / inspect.cs
Created November 30, 2014 22:22
Print out stuff about fields of an object in C#
Vector2 v = new Vector2(2f,3f);
System.Text.StringBuilder s = new System.Text.StringBuilder();
System.Reflection.FieldInfo[] fields = v.GetType().GetFields();
s.Append("numField: " + fields.Length + "\n");
// foreach (System.Reflection.FieldInfo info in fields) {
for (int ii = 0; ii < fields.Length; ++ii) {
System.Reflection.FieldInfo info = fields[ii];
System.Type t = info.GetType();
s.Append("[" + ii + "]");
s.Append(info.Name);
@greggman
greggman / serialize.cs
Created December 2, 2014 21:55
How to serialize primitives in a generic way
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
using System;
@greggman
greggman / gist:18953af231c9bf79cb12
Last active August 29, 2015 14:10
What could possibly happen when typing a single key in the Chrome omnibox

#Lifetime of an omnibox key press:

The stuff below is all made up. I have not worked on the omnibox in Chrome. But I wouldn't be surprised if this is close to reality.

  • Should we initiate an IME? Chrome has one built in.
    • I'm sure there's lots of allocations required for an IME but let's skip those
  • Create request to ask Google for things that match what we're typing
  • Create HTTP request data to send in request. Let's assume it's UTF8 json like {query:"k"}.
  • Note: Being UTF-8 we're going to have to write that query on the fly.