Skip to content

Instantly share code, notes, and snippets.

@sakrist
sakrist / build_gmp.sh
Last active November 9, 2022 06:27
GMP and MPFR compile for iOS
#!/bin/bash
#===============================================================================
# Filename: build_gmp.sh
# Created by Volodymyr Boichentsov on 18/09/2015.
# Copyright © 2015 3D4Medical. All rights reserved.
# Property of 3D4Medical.
#===============================================================================
#-emit-obj -fembed-bitcode -disable-llvm-optzns -O3
#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];

image

I've been interested in computer vision for a long time, but I haven't had any free time to make any progress until this holiday season. Over Christmas and the New Years I experimented with various methodologies in OpenCV to detect road signs and other objects of interest to OpenStreetMap. After some failed experiments with thresholding and feature detection, the excellent /r/computervision suggested using the dlib C++ module because it has more consistently-good documentation and the pre-built tools are faster.

After a day or two figuring out how to compile the examples, I finally made some progress:

Compiling dlib C++ on a Mac with Homebrew

  1. Clone dlib from Github to your local machine:
@sakrist
sakrist / gist:f97499de2dd6687d6403
Last active April 22, 2020 06:40
Objective-C Language Enhancements

Objective-C APIs can now express the “nullability” of parameters, return types, properties, variables, etc. For example, here is the expression of nullability for several UITableView APIs:

-(void)registerNib:(nonnull UINib *)nib forCellReuseIdentifier:(nonnull NSString *)identifier;
-(nullable UITableViewCell *)cellForRowAtIndexPath:(nonnull NSIndexPath)indexPath;
@property (nonatomic, readwrite, retain, nullable) UIView *backgroundView;

The nullability qualifiers affect the optionality of the Objective-C APIs when in Swift. Instead of being imported as implicitly-unwrapped optionals (e.g., UINib!), nonnull-qualified types are imported as non-optional (e.g., UINib) and nullable-qualified types are imported as optional (e.g., UITableViewCell?), so the above APIs will be seen in Swift as:

func registerNib(nib: UINib, forCellReuseIdentifier identifier: String)
@sakrist
sakrist / GLKMathUtils
Last active March 8, 2017 12:02
GLKMathProject and GLKMathUnproject
GLKVector3 GLKMathProject(GLKVector3 object, GLKMatrix4 model, GLKMatrix4 projection, int *viewport) {
assert(viewport);
GLKVector4 v4 = GLKVector4MakeWithVector3(object, 1.0);
GLKVector4 v = GLKMatrix4MultiplyVector4(model, v4);
v = GLKMatrix4MultiplyVector4(projection, v);
v.v[3] = 1.0/v.v[3];
v.v[0] *= v.v[3];
v.v[1] *= v.v[3];
typedef struct FontHeader {
int32_t fVersion;
uint16_t fNumTables;
uint16_t fSearchRange;
uint16_t fEntrySelector;
uint16_t fRangeShift;
}FontHeader;
typedef struct TableEntry {
uint32_t fTag;
// warping hexagons, WIP. @psonice_cw
// I'm sure there's a less fugly way of making a hexagonal grid, but hey :)
// Maybe - Try this...
// Simplify!
#ifdef GL_ES
precision mediump float;
#endif
@sakrist
sakrist / gist:7912905
Created December 11, 2013 15:55
FXAA algorithm
float FXAA_SPAN_MAX = 8.0;
float FXAA_REDUCE_MUL = 1.0/8.0;
float FXAA_REDUCE_MIN = 1.0/128.0;
vec3 rgbNW=texture2D(buf0,texCoords+(vec2(-1.0,-1.0)/frameBufSize)).xyz;
vec3 rgbNE=texture2D(buf0,texCoords+(vec2(1.0,-1.0)/frameBufSize)).xyz;
vec3 rgbSW=texture2D(buf0,texCoords+(vec2(-1.0,1.0)/frameBufSize)).xyz;
vec3 rgbSE=texture2D(buf0,texCoords+(vec2(1.0,1.0)/frameBufSize)).xyz;
vec3 rgbM=texture2D(buf0,texCoords).xyz;
typedef struct FontHeader {
int32_t fVersion;
uint16_t fNumTables;
uint16_t fSearchRange;
uint16_t fEntrySelector;
uint16_t fRangeShift;
}FontHeader;
typedef struct TableEntry {
uint32_t fTag;
/*/../bin/ls > /dev/null
COMPILED=${0%.*}
clang $0 -o $COMPILED -framework Foundation;
$COMPILED; rm $COMPILED; exit;
*/
#import <Foundation/Foundation.h>
@class CNSObject;