Skip to content

Instantly share code, notes, and snippets.

@th-in-gs
th-in-gs / gist:907479
Created April 7, 2011 10:07
Scottish Ruby Conference Charity Tutorial
def counter(start=0, increment=1)
lambda do
ret = start
start += increment
ret
end
end
result = counter(10, 2);
result2 = counter(10, 2);
@th-in-gs
th-in-gs / AppServerSetup.rb
Created April 7, 2011 10:46
Scottish Ruby Conference Charity Tutorial Exercise #2
class AppServer
attr_accessor :port, :admin_password
end
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
def app_server
if block_given?
if @app_server.nil?
@th-in-gs
th-in-gs / ArvoPrioritisedBlockOperation.h
Created November 16, 2012 14:11
NSOperation subclass with customisable dispatch_queue_priority
//
// ArvoPrioritisedBlockOperation.h
// Arvo
//
// Created by James Montgomerie on 16/11/2012.
// Copyright (c) 2012 Things Made Out Of Other Things. All rights reserved.
//
#import <Foundation/Foundation.h>
@th-in-gs
th-in-gs / gist:4161072
Created November 28, 2012 12:58
Response to "Surprising ARC performance characteristics" (http://blog.securemacprogramming.com/?p=668)
[myDictionary enumerateKeysAndObjectsUsingBlock: ^(id key, id object, BOOL *stop) {
//...
}];
to:
for(id key in myDictionary) {
id object = myDictionary[key];
//...
}
@th-in-gs
th-in-gs / gist:4722001
Last active December 12, 2015 05:28
LLVM Bug Report Response, "Static analyzer false positive when iterating C array"

Hi James,

This is a courtesy email regarding Bug ID# 13107141.

Engineering has provided a workaround that you can use while we continue working on a resolution of the issue:

In this case, the analyzer does not know that both the loop which initializes the values and the loop that uses them will be executed the same number of times. You can hint to the analyzer that that is the case, by adding the following assert before the second loop: assert(numbersIndex == numbersCount);

Alternatively, you could use numbersIndex instead if numbersCount in the second loop.

Coolson's Beta: A Word on Game Center.

Beta apps like Coolson's use a different, separate Game Center to the real one that apps from the App Store use. Apple calls it the "Sandbox" Game Center. You will need to create a Sandbox Game Center account when you first play Coolson's - it will prompt you. The Sandbox Game Center is entirely separate from the real one. You can use the same AppleID as you usually use, and hopefully your usual Game Center nickname will still be available in the Sandbox - if it's not, you'll need to choose another, I'm afraid!

An iPad can only be logged in to either the sandbox or the real Game Center. Launching Coolson's will automatically log you out of Game Center into Sandbox Game Center. Launching an App Store app that uses Game Center will log you out of the Sandbox Game Center and into Game Center. Launching the iPad's preinstalled "Game Center" app will not change which Game Center you're logged into; it will show the Sandbox if you previously played Coolson's, and the

//
// NSObject+KVOWeakPropertyDebug.h
// KVOWeakPropertyDebug
//
// Created by Vladimir Grichina on 12.01.13.
// Copyright (c) 2013 Vladimir Grichina. All rights reserved.
//
#import <Foundation/Foundation.h>
@th-in-gs
th-in-gs / AIM Icon (OS X).gif
Last active December 23, 2022 00:10
Buddy icon gifs from AIM
AIM Icon (OS X).gif
@th-in-gs
th-in-gs / README.md
Created May 2, 2023 00:53
Subethaedit Markdown Formatting Scripts

Paste these into Script Editor and save them as "Markdown Italicize.scpt" and "Markdown Boldise.scpt" in SubEthaEdit's Script folder (find it by opening it from the Script menu).

on seescriptsettings()
	return {keyboardShortcut:"@i", shortDisplayName:"Markdown Italicize", displayName:"Markdown Italicize"}
end seescriptsettings

tell application "SubEthaEdit"
	begin undo group
	set thetext to the the contents of the selection
@th-in-gs
th-in-gs / packedStrings.cpp
Created May 28, 2023 02:17
Packed PROGMEM Strings
#include "packedStrings.h"
const uint8_t str7CharAtIndex(const uint8_t *data, const uint8_t index) {
const size_t bitPosition = index * 7;
const uint8_t startByte = bitPosition / 8;
const uint8_t startBit = bitPosition % 8;
uint8_t ch = pgm_read_byte(&data[startByte]) << startBit;
if(startBit > (8-7)) {
ch |= pgm_read_byte(&data[startByte + 1]) >> (8 - startBit);
}