Skip to content

Instantly share code, notes, and snippets.

View Kuranes's full-sized avatar

Tuan Kuranes Kuranes

View GitHub Profile
@rmurphey
rmurphey / gist:3086328
Created July 10, 2012 21:23
What's wrong with Netmag's "Optimize your JavaScript" post

What's wrong with Netmag's "Optimize your JavaScript" post

Update: The original post on Netmag has been updated since this was written.

I tweeted earlier that this should be retracted. Generally, these performance-related articles are essentially little more than linkbait -- there are perhaps an infinite number of things you should do to improve a page's performance before worrying about the purported perf hit of multiplication vs. division -- but this post went further than most in this genre: it offered patently inaccurate and misleading advice.

Here are a few examples, assembled by some people who actually know what they're talking about (largely Rick Waldron and Ben Alman, with some help from myself and several others from the place that shall be unnamed).

Things that are just plain wrong

@rygorous
rygorous / magic_ring.cpp
Created July 22, 2012 03:55
The magic ring buffer.
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
#include <Windows.h>
// This allocates a "magic ring buffer" that is mapped twice, with the two
// copies being contiguous in (virtual) memory. The advantage of this is
// that this allows any function that expects data to be contiguous in
// memory to read from (or write to) such a buffer. It also means that
@deplinenoise
deplinenoise / typesafe_varargs
Last active July 13, 2022 00:29
You can pass along an array of info with varargs using C++ variadic templates. It generates really tight code; the only remaining overhead at runtime is the static arrays of type information (they end up in the `.rodata` segment). In this example I'm passing in an integer describing each arg, but you could just as well pass in function pointers …
// Type-safe varargs with C++11 variadic templates.
//
// Andreas Fredriksson <deplinenoise at gmail dott com>
//
// This code is in the public domain.
#include <stdio.h>
#include <stdarg.h>
@kalineh
kalineh / pch
Last active December 22, 2015 06:29
Header for intended use as pre-compiled header. Includes C++ standard libraries and platform headers. Force include + use as precompiled-header.
#define _PCH_LIBC
#define _PCH_WINDOWS_H
#define _PCH_EXTLIB
#ifdef _PCH_LIBC
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
@cvan
cvan / gist:6444031
Created September 4, 2013 23:07
convert URI of image to data URI
// Load an image in your browser and paste this in your console
var i=new Image();i.src=document.location.href;i.onload=function(){var c=document.createElement('canvas');c.width=this.width;c.height=this.height;c.getContext('2d').drawImage(this,0,0);window.location=c.toDataURL('image/png');};
@transitive-bullshit
transitive-bullshit / billboard_sao.frag
Created September 30, 2013 21:08
WebGL GLSL SAO (Scalable Ambient Obscurance) fragment shader. SAO is a more efficient method for computing SSAO (Screen-Space Ambient Occlusion). Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. For details on the technique itself, see: McGuire et al [12] http://graphics.cs.wi…
// total number of samples at each fragment
#define NUM_SAMPLES {{ numSamples }}
#define NUM_SPIRAL_TURNS {{ numSpiralTurns }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
#define VARIATION {{ variation }}
uniform sampler2D sGBuffer;
@transitive-bullshit
transitive-bullshit / billboard_hbao.frag
Created September 30, 2013 21:10
WebGL GLSL HBAO (Horizon-Based Ambient Occlusion) fragment shader. HBAO is a higher quality approach for computing SSAO (Screen-Space Ambient Occlusion) developed by Nvidia in 2008. Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. Specifically, the technique views the depth bu…
// number of directions to sample in UV space
#define NUM_SAMPLE_DIRECTIONS {{ numSampleDirections }}
// number of sample steps when raymarching along a direction
#define NUM_SAMPLE_STEPS {{ numSampleSteps }}
#define APPLY_ATTENUATION {{ attenuation }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
@transitive-bullshit
transitive-bullshit / billboard_ssao.frag
Created September 30, 2013 21:12
WebGL GLSL SSAO (Screen-Space Ambient Occlusion) fragment shader. Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. This SSAO version uses per-fragment depth and normal data to integrate local visibility over a normal-oriented hemisphere in world space by comparing the linear d…
#define SAMPLE_COUNT {{ sampleCount }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
uniform sampler2D sGBuffer;
uniform sampler2D sNoise;
uniform float uSampleRadius;
uniform float uIntensity;
uniform vec2 uNoiseScale;
uniform vec3 uKernel[SAMPLE_COUNT];
@marchelbling
marchelbling / README.md
Last active February 13, 2020 01:00
git hooks

Git hooks for better pivotal integration:

  • pre-commit:
    • prevents commiting on a branch that is not suffixed by an issue number. Some special branches (develop, master) and hotfixes are not constrained
    • lints modified python files and exits upon non correctly formatted modules
    • other formats (js, scss) have pending code that is not currently called as the workflow for front code is not clear
  • prepare-commit-msg: prepend issue number to commit message if it's missing and if it is set in the branch name (see pre-commit hook)
  • post-checkout: [optional] automatically update submodules when checkouting a branch (requires to define the AUTO_SUBMODULE_UPDATE environment variable)

For easy setup:

@pierreant-p
pierreant-p / sketchfab-cocao.m
Created November 26, 2013 23:22
Upload to Sketchfab with Cocoa
//
// AppDelegate.m
// Upload to Sketchfab sample code
//
// Created by Pierre-Antoine Passet on 11/26/13.
// Copyright (c) 2013 Sketchfab. All rights reserved.
//
#import "AppDelegate.h"
#import "AFHTTPRequestOperation.h"