Skip to content

Instantly share code, notes, and snippets.

View AnselmeKotchap's full-sized avatar

Anselme AnselmeKotchap

View GitHub Profile
@AnselmeKotchap
AnselmeKotchap / gist:f5111282b431ecb94102676a20c9c2e1
Created August 19, 2018 22:55 — forked from bwhiteley/gist:049e4bede49e71a6d2e2
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet private var contentView:UIView?
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
@AnselmeKotchap
AnselmeKotchap / godaddydomain.md
Created November 22, 2017 15:38 — forked from yancyn/godaddydomain.md
Setup Godaddy Domain for GitHub Page

Setup Godaddy Domain for GitHub Page

  1. Create a new file CNAME and put the domain.com in the file.
  2. Login GoDaddy > Manage domain > DNS Zone File.
  3. Under A (Host) change @ point to 192.30.252.153.
  4. Under CName (Alias) change www point to website.github.io.

see also GitHub Pages + GoDaddy

@AnselmeKotchap
AnselmeKotchap / beautiful_idiomatic_python.md
Created October 5, 2016 10:58 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@AnselmeKotchap
AnselmeKotchap / Stopwatch.swift
Created July 21, 2016 12:53 — forked from kristopherjohnson/Stopwatch.swift
Swift type for calculating elapsed time
import Foundation
import QuartzCore
/// Calculates elapsed time.
///
/// Typical usage is to construct an instance at the start of an operation,
/// and then call `elapsedTimeInterval()` or `elapsedTimeString()` at
/// the end to determine how much time has passed.
///
/// The underlying time reference is `mach_absolute_time()`
@AnselmeKotchap
AnselmeKotchap / executionTimeInterval.swift
Created July 21, 2016 12:51 — forked from kristopherjohnson/executionTimeInterval.swift
Calculate execution time for a block of Swift code
import QuartzCore
func executionTimeInterval(block: () -> ()) -> CFTimeInterval {
let start = CACurrentMediaTime()
block();
let end = CACurrentMediaTime()
return end - start
}
@AnselmeKotchap
AnselmeKotchap / UIViewController+Deselection.swift
Created June 8, 2016 21:01 — forked from ZevEisenberg/LICENSE
Smoothly deselect table and collection view cells on dismissal, including interactive dismiss and interactively-partially-dismiss-then-cancel-then-dismiss-again
extension UIViewController {
func rz_smoothlyDeselectRows(tableView tableView: UITableView?) {
let selectedIndexPaths = tableView?.indexPathsForSelectedRows ?? []
if let coordinator = transitionCoordinator() {
coordinator.animateAlongsideTransitionInView(parentViewController?.view, animation: { context in
selectedIndexPaths.forEach {
tableView?.deselectRowAtIndexPath($0, animated: context.isAnimated())
}
@AnselmeKotchap
AnselmeKotchap / gist:d09631266c10fd634f521d5c2194c371
Created May 16, 2016 09:37 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}