Skip to content

Instantly share code, notes, and snippets.

View NSArray+BinarySearch.h
//
// NSArray+BinarySearch.h
// BinarySearch
//
// Created by Ole Begemann on 19.04.10.
// Copyright 2010 Ole Begemann. All rights reserved.
//
#import <Foundation/Foundation.h>
@ole
ole / CDStructures.h
Created Oct 1, 2012
MailCompositionService.app class dump from the iOS 6.0 Simulator
View CDStructures.h
/*
* Generated by class-dump 3.3.4 (64 bit).
*
* class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2011 by Steve Nygard.
*/
#pragma mark Named Structures
struct CGPoint {
float _field1;
@ole
ole / FunctionalBankAccount.m
Created Feb 11, 2013
FunctionalBankAccount: a simple implementation of a blocks-based object model in (Objective-)C, inspired by a similar Scheme implementation in "Structure and Interpretation of Computer Programs". See http://oleb.net/blog/2013/02/building-blocks-based-object-system-in-objective-c/ for an explanation.
View FunctionalBankAccount.m
#import <Foundation/Foundation.h>
typedef id(^BankAccount)(char *cmd);
typedef id(^CurrentBalanceMethod)(void);
typedef id(^DepositMethod)(double);
typedef id(^WithdrawMethod)(double);
BankAccount CreateBankAccount(double initialBalance)
{
// Initialization
@ole
ole / update_storyboard_strings.sh
Last active May 9, 2018
Automatically extract translatable strings from Xcode storyboards and update .strings files. Original version by MacRumors forum user mikezang (http://forums.macrumors.com/showpost.php?p=16060008&postcount=4). Slightly updated by Ole Begemann. NOTE: this Gist moved to a regular repo at https://github.com/ole/Storyboard-Strings-Extraction.
View update_storyboard_strings.sh
# (File moved to https://github.com/ole/Storyboard-Strings-Extraction)
@ole
ole / osm_cycle_routes.xml
Created Apr 22, 2013
A query script for the Open Street Map API explorer at http://overpass-turbo.eu/ to render all the cycle routes in the current map bounding box.
View osm_cycle_routes.xml
<query type="relation" into="hr">
<has-kv k="route" v="bicycle"/>
<bbox-query {{bbox}}/>
</query>
<query type="way" into="hrp">
<recurse from="hr" type="relation-way"/>
<bbox-query {{bbox}}/>
</query>
<union>
<item set="hr"/>
@ole
ole / geocode_coordinates.rb
Created Jan 23, 2014
Geocodes addresses on the command line and print the geo coordinates (latitude and longitude). See http://oleb.net/blog/2014/01/geocoding-automator-service/ for more info on how I am using this script.
View geocode_coordinates.rb
#!/usr/bin/env ruby
# Determines the coordinates (latitude and longitude) of the places or
# addresses passed as arguments (either on the command line or via stdin)
# and prints the results.
# This script requires the Ruby Geocoder gem by Alex Reisner
# (http://www.rubygeocoder.com).
# To install the gem, run this command from a Terminal session:
#
View keybase.md

Keybase proof

I hereby claim:

  • I am ole on github.
  • I am olebegemann (https://keybase.io/olebegemann) on keybase.
  • I have a public key whose fingerprint is 8110 7FC7 27F7 56F5 3693 BA7A 90C7 D328 64A1 CEDF

To claim this, I am signing this object:

@ole
ole / RSSReaderExample.swift
Last active Aug 29, 2015
Equatable protocols in Swift. A reply to Brent Simmons’s post "Secret Projects Diary #2: Swift 2.0 Protocols" (http://inessential.com/2015/07/19/secret_projects_diary_2_swift_2_0_prot).
View RSSReaderExample.swift
//: Playground - noun: a place where people can play
import Cocoa
protocol Feed : Equatable {
var url: String {get}
}
protocol Folder {
// This is new:
@ole
ole / stack.swift
Created Sep 8, 2016
Compiler segmentation fault in Xcode 8 GM using ExpressibleByArrayLiteral
View stack.swift
// Save this to stack.swift, then run
//
// $ xcrun swift stack.swift
//
// Does it compile or does the compiler segfault?
struct Stack<Element> {
var elements: [Element] = []
}
@ole
ole / CharacterArray.swift
Last active Oct 24, 2016
Two options for converting character ranges into arrays
View CharacterArray.swift
// We can't use `Character` or `String` ranges directly because they aren't countable
// Create a countable range of ASCII values instead
let range = UInt8(ascii: "a")...UInt8(ascii: "z") // CountableClosedRange<UInt8>
// Convert ASCII codes into Character values
range.map { Character(UnicodeScalar($0)) } // Array<Character>
// → ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
You can’t perform that action at this time.