Skip to content

Instantly share code, notes, and snippets.

View andreashanft's full-sized avatar

Andreas Hanft andreashanft

View GitHub Profile
@andreashanft
andreashanft / GenericDataSource.swift
Last active August 12, 2022 17:33
Simple Generic UITableView Data Source
//
// GenericTableManager.swift
// Copyright © 2020 andreashanft.de. All rights reserved.
//
import Foundation
import UIKit
import Reusable
/*
@andreashanft
andreashanft / MethodWeakCapture.swift
Created April 26, 2020 14:02
Method Reference Issue
class CaptureClass {
var action: ((Int) -> Void)?
init() {
// Passing a method reference to an escaping closure implicitly captures self
// and in this case causes a refernce cycle!
addAction(takesInt)
// To avoid memory leak:
@andreashanft
andreashanft / CombineMVVMPlayground.swift
Last active August 12, 2022 17:32
Combine MVVM Demo Playground
//: A UIKit based Playground for presenting user interface
/// Add an event publisher to UIControls
/// From: https://forums.swift.org/t/a-uicontrol-event-publisher-example/26215/19
extension UIControl {
private class EventObserver {
let control: UIControl
let event: UIControl.Event
raspi-config
sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
(reboot)
sudo apt-get install vlc
sudo apt-get install iceweasel
sudo apt-get install xfce4
@andreashanft
andreashanft / config
Created July 16, 2013 10:10
SVN global ignores setting (~/.subversion/config)
### Section for configuring miscelleneous Subversion options.
[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output, and
### while importing or adding files and directories.
### '*' matches leading dots, e.g. '*.rej' matches '.foo.rej'.
global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store Pods Podfile.lock xcuserdata *.xcuserdatad
@andreashanft
andreashanft / Podfile
Created June 14, 2013 16:11
[CocoaPods] Podfile post install hook hack - get rid of those noobish NSLogs in mediocre libs imported by cocoapods. Silences them in release builds and add class and line number info to target that sucker in debug builds
post_install do | installer |
prefix_header = installer.config.project_pods_root + 'Pods-prefix.pch'
text = prefix_header.read + <<-EOS
#if DEBUG
#define NSLog(fmt, ...) NSLog((@"[DEBUG] %s [Line %d] " fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define NSLog(fmt, ...) (void)0
#endif
EOS
prefix_header.open('w') { |file| file.write(text) }
@andreashanft
andreashanft / gist:5161808
Created March 14, 2013 14:32
Prints the hierarchy of elements in a data structure (NSDictionary, NSArray and UIView).
static int depth = 0;
+ (void) traverseAndPrintDataStructure:(id)object
{
NSMutableString* indent = [NSMutableString string];
for (int i = 0; i < depth; i++)
{
[indent appendString:@"\t"];
}
@andreashanft
andreashanft / gist:5116781
Created March 8, 2013 14:29
Handling output of a NSTask
NSTask* task = [[NSTask alloc] init];
{
[task setStandardOutput:[NSPipe pipe]];
[task setStandardError:[NSPipe pipe]];
[task setLaunchPath:...];
[task setArguments:...];
[task setTerminationHandler:^(NSTask* task)
{
if ([task terminationStatus] == 0)
{