Skip to content

Instantly share code, notes, and snippets.

@kizzx2
kizzx2 / bare_opengl_es.m
Created April 20, 2011 16:20
Barebone OpenGL ES initialization with iOS
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
@interface OGLESView : UIView {
EAGLContext * glContext;
GLuint framebuffer;
GLuint renderbuffer;
}
@kizzx2
kizzx2 / c++_compile_time_strlen.cpp
Created April 20, 2011 16:26
Compile time (static) length of string literal
#include <iostream>
template <size_t N>
inline void foo(const char (&)[N])
{
std::cout << "strlen(x) = " << N << std::endl;
}
int main()
{
@kizzx2
kizzx2 / c++_has_function.cpp
Created April 20, 2011 16:27
C++ static "has_function" with SFINAE
#include <iostream>
struct Foo
{
void One();
};
struct Baz : Foo
{
void Two();
@kizzx2
kizzx2 / c++_has_member.cpp
Created April 20, 2011 16:27
C++ compile time detection of member variable with SFINAE
#include <iostream>
struct Foo
{
int one;
};
struct Bar
{
char one;
@kizzx2
kizzx2 / K2WordNumber.hs
Created August 9, 2011 14:55
Word Numbers brute force (Haskell profiling exercise)
-- Problem: Find the 51000000000-th character of the string (wordNumber Infinity)
-- where a wordNumber is defined as
--
-- wordNumber 1 = "one"
-- wordNumber 2 = "onetwo"
-- wordNumber 3 = "onetwothree"
-- wordNumber 15 = "onetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteen"
-- ...
--
-- The answer should be presented as ( sum of all numbers up to that point
@kizzx2
kizzx2 / FunDep.hs
Created September 3, 2011 03:24
Haskell type-level programming using functional dependencies and type families
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
-- Type-level functions using functional dependencies
@kizzx2
kizzx2 / Solitaire.hs
Created September 4, 2011 09:00
Solitaire Cipher in Haskell
-- Solitaire Cipher
-- http://www.rubyquiz.com/quiz1.html
module Solitaire where
import Data.Sequence ((><), (|>), (<|))
import qualified Data.Sequence as S
import Debug.Trace
import Control.Arrow
@kizzx2
kizzx2 / Worddy.hs
Last active September 27, 2015 08:17
Solution to Word Numbers (Haskell)
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NamedFieldPuns #-}
-- Chris Yuen <chris@kizzx2.com>
-- ITA Software's "Word Numbers" puzzle (http://www.itasoftware.com/careers/puzzle_archive.html)
import Data.Function
import Data.List
-- | For this problem we'll trie like structure. An "umbrella" value is
@kizzx2
kizzx2 / Rakefile
Created December 29, 2011 15:28
Use premake4 to generate iOS .xcodeproj files
# Usage:
# In premake4.lua use StaticLib for libraries; ConsoleApp for applications.
# Then run `rake xcode && rake xcodebuild`
ENV_DEFAULTS = {
'CONFIGURATION' => "Debug",
'SDK' => "iphonesimulator",
}
SDK_TO_ARCH = {
@kizzx2
kizzx2 / fun.cpp
Created January 11, 2012 14:29
Illustrative C++ Lua binding example/tutorial
// fun.cpp
extern "C"
{
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <iostream>