Skip to content

Instantly share code, notes, and snippets.

View rogerluan's full-sized avatar
🚀

Roger Oba rogerluan

🚀
View GitHub Profile
@khanlou
khanlou / Array+EachCons.swift
Last active July 7, 2020 17:48
each_cons from Ruby in Swift as a function on Sequence
extension Collection {
func eachConsecutive(_ size: Int) -> Array<SubSequence> {
let droppedIndices = indices.dropFirst(size - 1)
return zip(indices, droppedIndices)
.map { return self[$0...$1] }
}
}
@insidegui
insidegui / mergegenstrings.py
Created October 4, 2016 23:14 — forked from yoichitgy/mergegenstrings.py
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8
@hborders
hborders / versions.bash
Created September 14, 2016 18:18
A script run within Xcode's `Run Script` build phase that outputs version info into `versions.h`, which we prepend onto our Info.plist template.
#!/bin/bash -euo pipefail
# When we increment TW_BUNDLE_SHORT_VERSION_STRING
# also update TW_BUNDLE_SHORT_VERSION_DATE to the current date/time
# we don't have to be very exact, but it should be updated at least
# once every 18 months because iTunes requires that a CFBundleVersion
# be at most 18 characters long, and DECIMALIZED_GIT_HASH will be
# at most 10 characters long. Thus, MINUTES_SINCE_DATE needs to be
# at most 7 characters long so we can use the format:
# ${MINUTES_SINCE_DATE}.${DECIMALIZED_GIT_HASH}
@hborders
hborders / minutes_since_date.bash
Created September 14, 2016 18:16
Print the number of minutes since a given date
#!/bin/bash -euo pipefail
if [ ${#} -eq 0 ]
then
# read from STDIN
DATE=$( cat )
else
DATE="${1}"
fi
@hborders
hborders / decimalize_git_hash.bash
Last active January 7, 2023 13:56
Print the given git hash + a prepended "1" in decimal form
#!/bin/bash -euo pipefail
if [ ${#} -eq 0 ]
then
# read from STDIN
MAYBE_GIT_HASH=$( cat )
else
MAYBE_GIT_HASH="${1}"
fi
@eddieespinal
eddieespinal / cropCameraImage.swift
Last active April 14, 2021 08:16
Crops a Picture from AVCaptureSession to the bounds of the AVCaptureVideoPreviewLayer (so Preview = CameraImage) - Swift Version
//This is the swift version of the following gist by @shexbeer https://gist.github.com/shexbeer/cb069d36ca8ec5edb515
func cropCameraImage(original: UIImage, previewLayer: AVCaptureVideoPreviewLayer) -> UIImage? {
var image = UIImage()
let previewImageLayerBounds = previewLayer.bounds
let originalWidth = original.size.width
let originalHeight = original.size.height
@crushbowl
crushbowl / NYC-iOS-Companies_Job_board.md
Last active December 10, 2018 03:02
A list of iOS-related positions at companies in the NYC area (Manhattan, Brooklyn, NJ)

Looking for a mentor in iOS?- try this post: http://stephaniehurlburt.com/blog/2016/11/14/list-of-engineers-willing-to-mentor-you

General Job Boards

@IanKeen
IanKeen / gist:a772cbef81884680a501
Last active September 6, 2016 02:47
Put your UIViewcontroller on a diet

Put your UIViewcontroller on a diet

I hate to say it but our view controllers have gotten fat, and it's our fault! We feed them protocol after protocol, business rule after business rule. They don't know any better and they just gobble them all up...

This will be a 3 part "Tune up your table view" series in which we will take an old fat view controller, slim it down with some refactoring, freshen it up with some MVVM and then make it fly with some better asynchronous operation management!

In part 1 using refactoring and a couple of Interface Builder tricks hopefully I can provide some motivation to start your journey towards getting your view controllers back in fighting shape!

The current state of things...

UITableViews are pretty integral to most iOS apps so I'm going to use it as an example of how to change a 'fat' view controller into a 'slim' one.

@IanKeen
IanKeen / gist:5b832230a51bc2295f02
Created September 15, 2015 16:15
Make your UIViewController Awesynchronous!

Make your UIViewController Awesynchronous!

Welcome back for the conclusion of this 3 part series! In part 1 we learnt how to slim down our view controllers to a manageable size. In part 2 we learnt how to strip out all the non-ui related logic. This time we are going to focus solely on the UITableView and how we can properly handle multiple asynchronous operations in its cells for maximum performance!

As always we will be starting with our project from last time.

What's making our table's scrolling so bad?

Our current implementation is very bad... our UITableViewCells are performing an expensive operation, and on the main thread no less!

The following code is currently in the setup method of our cell:

@IanKeen
IanKeen / gist:f585650b48040dec7d37
Created September 15, 2015 16:14
Don't let your UIViewController think for itself...

Don't let your UIViewController think for itself...

Last time I showed you one strategy for trimming the fat from our view controller by seperating out protocols. In part 2 of this 3 part series we are going to use an architecture known as MVVM to dumb down our view controller. View controllers are usually filled with business rules, this is a problem for a number of reasons, two of which being:

  • It makes the code harder to reason about; let the view controller worry about appearance and the business objects worry about the logic, we don't want them thinking for themselves ;)
  • It makes your view controller bloated; business rules don't belong in your view controller

MVVM ?

MVVM stands for Model View ViewModel and is just a way of describing how to break up your interface, business rules and data so that they flow together in a logical, but seperated, way.

This is what that flow looks like