Skip to content

Instantly share code, notes, and snippets.

// Githubs syntax highlighter doesn't see _ spaced numbers correctly
println(1_000_000)
println(0xFF_FF_FF_FF)
@kimhunter
kimhunter / MakeImageTemplate.m
Last active August 29, 2015 14:03
Turn an Image into a single colour template, for use with iOS 7
//
// MakeImageTemplate
// Turn those badly coloured template images into a normalized color
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
@kimhunter
kimhunter / scanner_test.m
Last active August 29, 2015 14:02
timed comparison of nsscanner to an array split parsing task.
//
// main.m
// Scratch
//
// Created by Kim Hunter on 12/06/2014.
// Copyright (c) 2014 Kim Hunter. All rights reserved.
//
// Here I do similar test while the code does some actual task in the loops
// The results: the nsscanner approach takes less than a tenth of the time
import Cocoa
extension Array {
func myMap<A,B>(items: Array<A>, f:((A) -> B)) -> Array<B> {
var xs: Array<A> = items
return xs.count == 0 ? [] : [f(xs.removeAtIndex(0))] + myMap(xs,f)
}
func myMap<B>(f:((T) -> B)) -> Array<B> {
return myMap(self,f)
import Cocoa
var nums: Int[] = []
for var i = 0; i < 10; i++ {
nums.append(Int(arc4random()) % 200)
}
nums
func qSort(var arr: Int[]) -> Int[] {
@kimhunter
kimhunter / NSNumber+FastEnum.m
Created May 29, 2014 23:21
Add FastEnumeration to NSNumber
/*
inspired by ruby's 4.times {} method, created becasue I can and it was fun to do.
Usage:
for (NSNumber *i in @100)
{
NSLog(@"%@", i);
}
*/
@interface NSNumber (FastEnum)<NSFastEnumeration>
@kimhunter
kimhunter / 2048.c
Last active August 29, 2015 13:58 — forked from justecorruptio/2048.c
M[16], X = 16, W, k;
main()
{
T(system("stty cbreak"));
puts(W & 1 ? "WIN" : "LOSE");
}
K[] = { 2, 3, 1 };
s(f, d, i, j, l, P)
{
for (i = 4; i--;)
@kimhunter
kimhunter / testSeeEl.c
Last active December 20, 2015 01:29
Test if any OpenCL GPU device is available.
//
// main.cpp
// testSeeEl
//
// Created by Kim on 21/07/2013.
// Copyright (c) 2013 Kim. All rights reserved.
//
//
// clang -framework OpenCL -o testSeeEl testSeeEl.c && ./testSeeEl
//
@kimhunter
kimhunter / missing_vids.rb
Created June 18, 2013 04:32
Missing wwdc2013 videos from my own renaming format
require 'nokogiri'
doc = Nokogiri::HTML(File.open("Videoswwdc.html"))
items = {}
doc.xpath("//li[@class='session']").each do |session|
session_id = session['id'].sub('-video', '').to_i
title = session.children.xpath("li[@class='title']").text
items[session_id] = title
end
@kimhunter
kimhunter / wwdc_rename.rb
Created June 18, 2013 04:28
WWDC2013 session video renaming script
require 'nokogiri'
doc = Nokogiri::HTML(File.open("Videoswwdc.html"))
items = {}
doc.xpath("//li[@class='session']").each do |session|
session_id = session['id'].sub('-video', '').to_i
title = session.children.xpath("li[@class='title']").text
items[session_id] = title
end