Skip to content

Instantly share code, notes, and snippets.

Avatar
😁

Greggman greggman

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

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 Mar 14, 2014
dns server that directs all traffic to the machine its on
View gist:9553597
# 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 Apr 10, 2014
Set a frustum to a sub rect of a larger view
View SetFrustumToSubRectOfLargerView.c
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
Closure no like?
View foo.js
/**
* 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
works on JSDoc 3.3.0-alpha5 with Java but not with node.js
View testme.js
/*
* Some license text, bla bla bal
*/
"use strict";
define(['./somelibrary'], function(SomeLibrary) {
/**
* @typedef {Object} FooThing~Options
View resize-canvas-to-css.js
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 Nov 21, 2014
Answer on SO is wrong
View foo.md

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 Nov 30, 2014
Print out stuff about fields of an object in C#
View inspect.cs
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 Dec 2, 2014
How to serialize primitives in a generic way
View serialize.cs
// ------------------------------------------------------------------------------
// <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 Aug 29, 2015
What could possibly happen when typing a single key in the Chrome omnibox
View gist:18953af231c9bf79cb12

#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.