Skip to content

Instantly share code, notes, and snippets.

@shakesoda
shakesoda / png.cpp
Created August 22, 2013 23:24
some old libpng code
#include <GL/glfw3.h>
#include <png.h>
#include "managers/FileManager.h"
#include "PNGFile.h"
#include "utils/Logger.h"
Texture PNGFile::Load(std::string _path)
{
Texture tex;
@shakesoda
shakesoda / findvar.js
Created June 12, 2013 22:55
snippet for parsing a get variable out of a url
function findVar(attr) {
var url = location.href.split("#")[0];
var search = new RegExp(attr + "=.*?(?=[#&]|$)");
var result = search.exec(url);
if (result !== null) {
result = result[0].split("=")[1];
if (/^-?\d+(\.\d+)?$/.test(result))
return Number(result);
else
return result;
@shakesoda
shakesoda / openhmd.h
Last active December 17, 2015 20:59
OpenHMD API mockup
/*
* OpenHMD - Free and Open Source API and drivers for immersive technology.
* Copyright (C) 2013 Fredrik Hultin.
* Copyright (C) 2013 Jakob Bornecrantz.
* Distributed under the Boost 1.0 licence, see LICENSE for full text.
*/
#ifndef OPENHMD_H
#define OPENHMD_H
@shakesoda
shakesoda / foo.cpp
Created May 29, 2013 08:44
GL/AL/similar extension pretty printing.
void pretty_print_extensions(std::vector<std::string> &extensions)
{
// derived from the extension pretty printing from StepMania.
using namespace std;
sort( extensions.begin(), extensions.end() );
size_t next = 0;
while( next < extensions.size() )
{
size_t last = next;
-- size 3
-- going up 1 3 5
-- going down 5 3 4 4 1 2 2 3 3
-- size 5
-- going up 1 3 5 7 9
-- going down 9 7 8 8 5 6 6 7 7 3 4 4 5 5 1 2 2 3 3 4 4
-- string.format is quite a bit of typing
_ = string.format;
all:
cp foo.o bar.o
@echo "or if you're the silent type..."
@cp bar.o baz.o
@echo "copied bar.o to baz.o"
function split(s, v)
local pos = s:find(v)
local ret = {}
local idx = 1
for i=1,string.len(s) do
local c = s:sub(i,i)
local token = s:sub(i, i+v:len()-1)
if token:find(v) then
idx = idx + 1
else
@shakesoda
shakesoda / foo.cpp
Created April 9, 2012 21:18
uniform setter thing
class Uniform
{
public:
// todo: macroify, make m_program actually a thing.
void set_uniform_float(std::string key, float data)
{
using namespace std;
unsigned location = 0;
map<string, unsigned>::iterator it;
@shakesoda
shakesoda / jcl.sh
Created March 6, 2012 17:23
Quick and dirty shell script to remove some junk files from JOE
#!/usr/bin/env bash
if [[ $# != "1" ]]; then
echo "Not enough arguments. Usage: jcl <path>"
exit
fi
# remove trailing slash
path=`echo $1 | sed 's/\/*$//'`
@shakesoda
shakesoda / gist:1871736
Created February 20, 2012 21:52
OpenGL Error macro
#define CheckError()\
{\
GLenum err = glGetError();\
if (unlikely(err != GL_NO_ERROR))\
{\
for (; err != GL_NO_ERROR; err = glGetError())\
{\
switch (err)\
{\
case GL_INVALID_ENUM: LOG->Error("GL_INVALID_ENUM"); break;\