Skip to content

Instantly share code, notes, and snippets.

View nuthatch's full-sized avatar

Stephen Ryner Jr. nuthatch

View GitHub Profile
#!/bin/bash
# Install sleepwatcher
cd /tmp
curl -O http://www.bernhard-baehr.de/sleepwatcher_2.2.tgz
tar -zxvf sleepwatcher_2.2.tgz
cd sleepwatcher_2.2
sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8
sudo cp sleepwatcher /usr/local/sbin
sudo cp sleepwatcher.8 /usr/local/share/man/man8
sudo cp config/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents
@Shilo
Shilo / DeviceManager.h
Last active April 18, 2018 01:36
Objective-C methods for retrieving iOS device models. (More info here: http://www.everyi.com/by-identifier/ipod-iphone-ipad-specs-by-model-identifier.html)
#import <Foundation/Foundation.h>
@interface DeviceManager : NSObject
+ (NSString *)deviceModelName;
+ (NSString *)deviceSimpleModelName;
@end
@kristopherjohnson
kristopherjohnson / Stopwatch.swift
Last active July 13, 2022 11:24
Swift classes for calculating elapsed time, similar to .NET's System.Diagnostics.Stopwatch class
// Copyright (c) 2017 Kristopher Johnson
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
@chrismiles
chrismiles / cggradient.swift
Created August 7, 2014 12:02
Core Graphics gradient drawing with Swift? No problem.
let colorSpace = CGColorSpaceCreateDeviceRGB()
let componentCount : UInt = 4
let components : [CGFloat] = [
0, 0, 0, 0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
0, 0, 0, 0
]
@nicklockwood
nicklockwood / Hacking UIView Animation Blocks.md
Last active January 12, 2024 06:15
This article was originally written for objc.io issue 12, but didn't make the cut. It was intended to be read in the context of the other articles, so if you aren't familiar with concepts such as CALayer property animations and the role of actionForKey:, read the articles in that issue first.

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

@raphaelschaad
raphaelschaad / RSPlayPauseButton.h
Last active July 25, 2016 21:44
Edit: this Gist has now a proper repo and even a CocoaPod: https://github.com/raphaelschaad/RSPlayPauseButton
//
// RSPlayPauseButton.h
//
// Created by Raphael Schaad on 2014-03-22.
// This is free and unencumbered software released into the public domain.
//
#import <UIKit/UIKit.h>
@octocat
octocat / .gitignore
Created February 27, 2014 19:38
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;{
CGFloat heightForRowAtIndexPath = 44.f;
NSString * cellID = [self cellIdForIndexPath:indexPath];
UITableViewCell <XXApplicationTableViewCellConfiguring> * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if([cell conformsToProtocol:@protocol(XXApplicationTableViewCellConfiguring)]) {
[cell configureCellWithApplicationModel:self.application];
[cell layoutSubviews];
heightForRowAtIndexPath = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}
@PadraigK
PadraigK / gist:8481266
Created January 17, 2014 20:53
Your nightmare of double borders at the bottom of table views after selecting a cell is now over.
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
// Fix double cell border after highlight
if (indexPath.row == self.fetchedResultsController.fetchedObjects.count-1) {
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
UIView *tableScrollView = [[cell subviews] lastObject];
UIView *separator = [[tableScrollView subviews] lastObject];
[separator setBackgroundColor:[UIColor clearColor]];
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.