Skip to content

Instantly share code, notes, and snippets.

View programmingthomas's full-sized avatar

Programming Thomas programmingthomas

View GitHub Profile
//At the top of the file
#import "mandelbrot.cl.h"
//Inside the @autoreleasepool in int main()
//1
dispatch_queue_t dq = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, NULL);
if (!dq) {
fprintf(stdout, "Unable to create a GPU-based dispatch queue.\n");
exit(1);
@programmingthomas
programmingthomas / mandelbrot.cl
Last active July 15, 2021 12:20
Mandelbrot kernel
//mandelbrot.cl
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST;
kernel void mandelbrot(write_only image2d_t output, float width, float height, int iter) {
size_t x = get_global_id(0);
size_t y = get_global_id(1);
float2 z, c;
@programmingthomas
programmingthomas / apache.rb
Last active August 29, 2015 13:56
Recursively iterates over a directory containing Objective-C .h, .m and .pch files to check that their Apache license header is in the correct format (my first Ruby script...)
def copyright(fname, year, programmer)
return "// #{fname}
//
// Copyright #{year} #{programmer}
//
// Licensed under the Apache License, Version 2.0 (the \"License\");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@programmingthomas
programmingthomas / ninepatch.m
Created November 7, 2013 20:27
Using nine patch/sliced images
//Using with an image view
imageView.image = [UIImage imageNamed:@"myimage"];
//Using as the background to another view
//Note that you will need to redraw the background when resizing
//Therefore if you need to animate resizes it may be more sensible to add a UIImageView
//as the background to your view
UIImage * myImage = [UIImage imageNamed:@"myimage"];
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, NO, 0);
[myImage drawInRect:myView.bounds];
@programmingthomas
programmingthomas / RegisterFonts.m
Created November 1, 2013 19:35
A simple Objective-C method that will register all of the TTF font files in your application with Core Text.
+ (void)registerFonts {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSArray * paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:@""];
for (NSString * path in paths) {
NSURL * url = [NSURL fileURLWithPath:path];
CFErrorRef error;
CTFontManagerRegisterFontsForURL((__bridge CFURLRef)url, kCTFontManagerScopeNone, &error);
error = nil;
}
@programmingthomas
programmingthomas / NSString+EnumerateCharacters.m
Created October 6, 2013 16:49
NSString character enumeration category
-(void)enumerateCharacters:(EnumerationBlock)enumerationBlock
{
const unichar * chars = CFStringGetCharactersPtr((__bridge CFStringRef)self);
//Function will return NULL if internal storage of string doesn't allow for easy iteration
if (chars != NULL)
{
NSUInteger index = 0;
while (*chars) {
enumerationBlock(*chars, index);
chars++;
@programmingthomas
programmingthomas / iOSVersion.m
Created August 19, 2013 18:07
Get iOS system version as float
+(float)systemVersion
{
NSArray * versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
float total = 0;
int pot = 0;
for (NSNumber * number in versionCompatibility)
{
total += number.intValue * powf(10, pot);
pot--;
}
@programmingthomas
programmingthomas / adc.py
Created July 29, 2013 07:45
ADC Developer Status Python script - Python 2.7 - Prints a list of all of the Apple Developer services that are currently online
import urllib2
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
entered_status_table = False
in_table_cell_tag = False
status_online = False
services_online = {}
def get_class(self, attrs):
v = ""
@programmingthomas
programmingthomas / Main.cs
Created March 23, 2013 10:27
Estimating syllables
public int numberOfSyllables (String word)
{
int syllabeleCount = 0;
bool lastWasVowel = false;
string lowerCase = word.ToLower ().Replace ("ome", "um").Replace ("ime", "im").Replace ("imn", "imen").Replace ("ine", "in").Replace ("ely", "ly").Replace("ure", "ur").Replace("ery", "ry");
for (int n = 0; n < lowerCase.Length; n++) {
if (isVowel (lowerCase [n])) {
if (!lastWasVowel)
syllabeleCount++;
lastWasVowel = true;
@programmingthomas
programmingthomas / maxifyjs.html
Last active September 13, 2017 09:19
MaxifyJS v0.1 - Minification is cool because it kills whitespace and optimizes your code. Maxification is better; it adds whitespace, unnecessary comments and makes your code inefficient.
<!DOCTYPE html>
<html>
<head>
<title>MaxifyJS 0.1</title>
<style>
textarea
{
height:600px;
max-height:600px;
width:49%;