Skip to content

Instantly share code, notes, and snippets.

@zeux
zeux / string_to_double.cpp
Last active August 28, 2015 17:10
Fast and correct (?) string to double.
// convert string to double
PUGI__FN double string_to_double(const char_t* value)
{
static const double digits[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
static const double powers[] = { 1e0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 1e+21, 1e+22 };
const char_t* s = value;
// skip whitespace
while (PUGI__IS_CHARTYPE(*s, ct_space))
zeux@zeux-laptop ~/BlogCode/2014/2/TestDisk $ sudo ./test_disk 4096 128 .
Creating file: './largeFile' size: 4294967296 bytes
file created, let's do some testing!
Testing block size: 65536 bytes, will read 2048 blocks.
cache is cleared
Wall elapsed: 2.11037
Avg time per block: 1.03045 ms
Ignore: 18446744073657203244
Testing block size: 131072 bytes, will read 1024 blocks.
cache is cleared
@zeux
zeux / gist:8888772
Created February 8, 2014 19:22
set_value overload madness
#include <stdio.h>
void set_value(int rhs)
{
printf("int\n");
}
void set_value(unsigned int rhs)
{
printf("uint\n");
@zeux
zeux / Makefile
Created February 9, 2014 21:29
Create folders for output files using things you can learn from 'man make'
# Before
$(BUILD)/%.o: %
@mkdir -p $(dir $@)
$(CXX) $< $(CXXFLAGS) -MMD -MP -o $@
-include $(OBJECTS:.o=.d)
# After
.SECONDEXPANSION:
@zeux
zeux / gist:9119256
Created February 20, 2014 17:40
SSAO loop
for (int i_3 = 0; i_3 < 8; i_3++) {
vec2 offsetDepth_14;
vec2 tmpvar_15;
tmpvar_15 = (rotation_8 * OFFSETS1_7[i_3]);
offsetDepth_14.x = texture2D (xlu_depthBuffer, (uv_1 + (tmpvar_15 * radiusTex_5))).x;
offsetDepth_14.y = texture2D (xlu_depthBuffer, (uv_1 - (tmpvar_15 * radiusTex_5))).x;
float tmpvar_16;
tmpvar_16 = (float((i_3 + 1)) / 10.0);
vec2 tmpvar_17;
tmpvar_17 = (((offsetDepth_14 - vec2(baseDepth_9)) / (0.006 *
@zeux
zeux / default.material
Created February 24, 2014 17:07
Oh horror
vertex_program DefaultVPParams null
{
default_params
{
param_named_auto CameraPosition camera_position
param_named_auto ViewProjection viewproj_matrix
param_named_auto Lamp0Dir light_direction 0
param_named_auto Lamp1Dir light_direction 1
param_named_auto Lamp0Color light_diffuse_colour 0
@zeux
zeux / gapi.hpp
Created February 24, 2014 17:13
class Renderbuffer: public Resource
{
public:
Texture::Format getFormat() const { return format; }
unsigned int getWidth() const { return width; }
unsigned int getHeight() const { return height; }
};
class Framebuffer: public Resource
@zeux
zeux / rbxglew.cpp
Created March 7, 2014 18:49
Yay for modern GL! Wait, what?
#pragma comment(lib, "opengl32.lib")
#include "glew.c"
template <typename T, typename U> static void patchUnsafe(T& t, U& u)
{
if (!t && u)
t = reinterpret_cast<T>(u);
}
static inline void patch_shader_ucode(void* dest, const void* source, unsigned int size, const qword* constants)
{
const uint16_t* table = (const uint16_t*)source;
char* ucode = (char*)dest;
char* ucode_end = ucode + size;
// each 128b of shader ucode correspond to 1 qword of table data; dictionary is right after table
const qword* dictionary = (const qword*)source + (size + 127) / 128;
// constants/dictionary are 16b aligned, so discard 4 LSB to fit in 16 bits
static inline void patch_shader_ucode(void* dest, const void* source, unsigned int size, const qword* constants)
{
const uint16_t* table = (const uint16_t*)source;
qword* ucode = (qword*)dest;
// each 128b of shader ucode correspond to 1 qword of table data; dictionary is right after table
const qword* dictionary = (const qword*)source + (size + 127) / 128;
for (unsigned int i = 0; i < size / sizeof(qword); ++i)
{