This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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--;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
var nums: Int[] = [] | |
for var i = 0; i < 10; i++ { | |
nums.append(Int(arc4random()) % 200) | |
} | |
nums | |
func qSort(var arr: Int[]) -> Int[] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Githubs syntax highlighter doesn't see _ spaced numbers correctly | |
println(1_000_000) | |
println(0xFF_FF_FF_FF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "yaml" | |
stash_list = `git stash list`.chomp.split("\n").map {|i| i.chomp } | |
stash_list.map!{|s| | |
b = s.match(/stash@\{([0-9]+)\}: (.*)/) | |
[b[1], b[2]] | |
} | |
stash_list.each do |s| | |
puts "{#{s[0]}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define KMProfile(MSG, CODE_TO_PROFILE) { \ | |
NSDate *KMStartDate = [NSDate date]; \ | |
NSTimeInterval KMduration; \ | |
CODE_TO_PROFILE \ | |
KMduration = [[NSDate date] timeIntervalSinceDate:KMStartDate]; \ | |
NSLog(@"KMProfile: %@ TOOK %.0lfms (%.1lfs) ", MSG,(KMduration*1000) , KMduration); \ | |
} | |
// Usage: (works well with something a bit more intensive but you get the gist) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# 2011-10-10 20:57:53 +1000 | |
def merge_sort a | |
return a if a.size <= 1 | |
l,r = split_array a | |
result = combine merge_sort(l), merge_sort(r) | |
end | |
def split_array a |
OlderNewer