Skip to content

Instantly share code, notes, and snippets.

View dasdom's full-sized avatar

Dominik Hauser dasdom

View GitHub Profile
@dasdom
dasdom / DDHLanguageDetection.m
Last active August 23, 2018 14:39
Language detection in iOS. This code is used to add the language to a post in my ADN client hAppy. This is pubic domain. To with it what every you like!
NSString *languageGuessedString;
if (postString.length < 60) {
languageGuessedString = nil;
} else {
NSArray *componentsArray = [postString componentsSeparatedByString:@" "];
NSMutableString *mutablePostString = [NSMutableString string];
for (NSString *string in componentsArray) {
if ([string rangeOfString:@"@"].location != NSNotFound) {
continue;
@dasdom
dasdom / gist:7355562
Last active December 27, 2015 16:29
Code to move the cursor in a UITextView with a pan.
- (void)panHappend:(UIPanGestureRecognizer*)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
self.startRange = self.postTextView.selectedRange;
}
NSRange selectedRange = {MAX(self.startRange.location+(NSInteger)([sender translationInView:self.view].x/8.0f), 0), 0};
self.postTextView.selectedRange = selectedRange;
}
#!/usr/bin/perl -w
use strict;
if (not defined($ARGV[1])) {
die "usage: $0 <class name> <file with property names>\n";
}
open(PROP, $ARGV[1]) || die "could not open property names file: $!\n";
@dasdom
dasdom / createButton.swift
Last active August 29, 2015 14:16
A closure to reuse button creation code.
import UIKit
let makeButton = { (title: String) -> UIButton in
let button = UIButton.buttonWithType(.System) as UIButton
button.setTranslatesAutoresizingMaskIntoConstraints(false)
button.layer.cornerRadius = 5
button.layer.borderWidth = 1.0
button.layer.borderColor = UIColor.yellowColor().CGColor
button.setTitle(title, forState: .Normal)
return button
import AddressBookUI
let picker = ABPeoplePickerNavigationController()
picker.peoplePickerDelegate = self
presentViewController(picker, animated: true, completion: nil)
import UIKit
@objc protocol TransitionInfoProtocol {
var view: UIView! { get set }
func viewsToAnimate() -> [UIView]
func copyForView(subView: UIView) -> UIView
optional func frameForView(subView: UIView) -> CGRect
}
@dasdom
dasdom / gist:c323ef1ccdc52a8ca563
Last active August 29, 2015 14:26
Variable-height UITableView tableHeaderView with autolayout
// in a UITableViewController (or any other view controller with a UITableView)
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, 0)];
header.translatesAutoresizingMaskIntoConstraints = NO;
// [add subviews and their constraints to header]
NSLayoutConstraint *headerWidthConstraint = [NSLayoutConstraint
@dasdom
dasdom / uiappearance-selector.md
Last active August 29, 2015 14:26 — forked from mattt/uiappearance-selector.md
A list of methods and properties conforming to `UIAppearance` as of iOS 8.0

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

UIActivityIndicatorView

@dasdom
dasdom / preprocessor_fun.h
Last active August 26, 2015 09:34 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@IBOutlet weak var labelTopConstraint: NSLayoutConstraint!
@IBOutlet weak var labelUsernameConstraint: NSLayoutConstraint!
@IBOutlet weak var usernamePasswordConstraint: NSLayoutConstraint!
@IBOutlet weak var passwordButtonConstraint: NSLayoutConstraint!