Skip to content

Instantly share code, notes, and snippets.

View mattrajca's full-sized avatar

Matt Rajca mattrajca

View GitHub Profile
@mattrajca
mattrajca / logsumexp.c
Last active March 15, 2016 16:06
A vectorized, numerically-stable implementation of logsumexp on top of Accelerate.framework
#include <Accelerate/Accelerate.h>
static double vsum(const double *vector, size_t length) {
double *const ones = (double *)malloc(sizeof(double) * length);
const double one = 1;
vDSP_vfillD(&one, ones, 1, length);
double sum = 0;
vDSP_dotprD(ones, 1, vector, 1, &sum, length);
@mattrajca
mattrajca / AppDelegate.m
Created October 11, 2015 19:55
MetalComputeOSX
//
// AppDelegate.m
// MetalComputeOSX
//
#import "AppDelegate.h"
@import Metal;
#define IMAGE_SIZE 128
@mattrajca
mattrajca / blur.swift
Created March 7, 2015 23:49
Blurring images with UIVisualEffectView
//
// BlurredImageGenerator.swift
//
// Copyright (c) 2015 Matt Rajca. All rights reserved.
//
import UIKit
func generateBlurredImageFromImage(image: UIImage) -> UIImage {
let sourceImageRect = CGRectMake(0, 0, image.size.width, image.size.height)
@mattrajca
mattrajca / lis.swift
Created March 6, 2015 15:58
Compute length of longest increasing subsequence in Swift
// Playground - noun: a place where people can play
let array = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 8, 4, 6, 2, 7]
// Computes the length of the longest increasing subsequence in the list of integers.
func lis(list: [Int]) -> Int {
return lis(0, list, nil)
}
func lis(index: Int, list: [Int], largestValue: Int?) -> Int {
@mattrajca
mattrajca / OSAtomic-Semaphore.c
Last active August 29, 2015 13:57
An OS X and iOS implementation of semaphores that uses OSAtomic functions (libkern/OSAtomic.h) to guarantee thread safety
//
// main.c
//
// Copyright (c) 2014 Matt Rajca. All rights reserved.
//
#include <stdio.h>
#include <dispatch/dispatch.h>
#include <libkern/OSAtomic.h>
#include <sched.h>
@mattrajca
mattrajca / NSUserDefaults+Subscripting.h
Last active December 22, 2015 03:58
Category which adds keyed subscripting to NSUserDefaults
//
// NSUserDefaults+Subscripting.h
//
// Created by Matt on 9/2/13.
// Copyright (c) 2013 Matt Rajca. All rights reserved.
//
#import <Foundation/Foundation.h>
/* keys must be NSStrings */
@mattrajca
mattrajca / pinstripes.js
Created August 5, 2012 18:42
Generating pinstripes with JSTalk and Acorn
var acorn = [JSTalk application:"Acorn"];
var w = 640;
var h = 960;
var stripeW = 20;
var spaceW = 20;
var foregroundColor = [NSColor redColor];
var backgroundColor = [NSColor blueColor];
@mattrajca
mattrajca / imp.m
Created June 7, 2012 23:20
playing with imp_implementationWithBlock
//
// imp.m
// imp
//
// Copyright (c) 2012 Matt Rajca. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>