Skip to content

Instantly share code, notes, and snippets.

@evanw
evanw / chart.png
Created September 20, 2012 03:13
WebSocket Speed Test
chart.png
@evanw
evanw / gl.cpp
Created November 11, 2013 01:04
The mandelbulb fractal shader from https://www.shadertoy.com/view/MdfGRr ported to C++ with GLUT. Uses W/A/S/D to rotate and up/down/left/right to move. Compiles on OS X with: g++ main.cpp gl.cpp -framework GLUT -framework OpenGL -Wno-deprecated-declarations
#include "gl.h"
mat4 &mat4::transpose() {
std::swap(m01, m10); std::swap(m02, m20); std::swap(m03, m30);
std::swap(m12, m21); std::swap(m13, m31); std::swap(m23, m32);
return *this;
}
mat4 &mat4::rotateX(float degrees) {
float radians = degrees * (M_PI / 180);
@evanw
evanw / Makefile
Created November 28, 2013 19:33
PNaCl bug with RequestFilteringInputEvents
SDK = ~/nacl_sdk/pepper_canary
build:
$(SDK)/toolchain/mac_pnacl/bin/pnacl-clang++ -o filtering.bc filtering.cpp -O2 -I $(SDK)/include -L $(SDK)/lib/pnacl/Release -lppapi_cpp -lppapi
$(SDK)/toolchain/mac_pnacl/bin/pnacl-finalize -o filtering.pexe filtering.bc
@evanw
evanw / main.rs
Created December 29, 2013 05:36
Rust language: Use after free? (rustc 0.8)
struct Foo {
x: int
}
impl Drop for Foo {
fn drop(&mut self) {
println!("drop {}", self.x);
}
}
@evanw
evanw / Makefile
Created January 4, 2014 18:20
C++ memory test compiled using emscripten with 512mb heap
SOURCES = \
main.cpp
CPP_FLAGS = \
-fno-exceptions \
-fno-rtti \
-Wall \
-Wextra
JS_FLAGS = \
@evanw
evanw / Makefile
Created January 28, 2014 20:20
Code generated by emlink is incorrect
SDK = ~/.emsdk_portable
JS_FLAGS = -s ASM_JS=1 -O1
CPP_FLAGS = -std=c++11 -fno-rtti -fno-exceptions
EMSCRIPTEN_PATH = $(shell $(SDK)/emsdk active_path emscripten-1.7.8)
CLANG_PATH = $(shell dirname $(shell PATH=$(shell $(SDK)/emsdk active_path clang-3.2-64bit):$(PATH) which clang))
EMCC = LLVM=$(CLANG_PATH) python $(shell PATH=$(EMSCRIPTEN_PATH):$(PATH) which emcc)
EMLINK = LLVM=$(CLANG_PATH) python $(shell dirname $(shell PATH=$(EMSCRIPTEN_PATH):$(PATH) which emcc))/emlink.py
default: cpp_simple cpp_modules js_simple js_modules
SDK = ~/.emsdk_portable
EMSCRIPTEN_PATH = $(shell $(SDK)/emsdk active_path emscripten-1.7.8)
CLANG_PATH = $(shell dirname $(shell PATH=$(shell $(SDK)/emsdk active_path clang-3.2-64bit):$(PATH) which clang))
EMCC = LLVM=$(CLANG_PATH) python $(shell PATH=$(EMSCRIPTEN_PATH):$(PATH) which emcc)
default: build
build:
$(EMCC) main.cpp
@evanw
evanw / build.sh
Created April 6, 2014 17:17
Google Closure Compiler ignores input source maps
java \
-jar compiler.jar \
--js main.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
--js_output_file main.min.js \
--create_source_map main.min.js.map \
--source_map_format V3
import os
import re
import json
import base64
path = 'compiled.js.mem'
data = open('compiled.js.mem', 'rb').read()
print 'data length:', len(data)
def tinystr(s):
build:
emcc -O1 -fno-rtti -fno-exceptions temp.c -o temp.js