Skip to content

Instantly share code, notes, and snippets.

View rogerluan's full-sized avatar
🚀

Roger Oba rogerluan

🚀
View GitHub Profile
@nicklockwood
nicklockwood / gist:7446228
Last active December 28, 2015 04:59
Why having a single success/error callback block is better than having separate ones

Suppose you have a network method that only uses a single block callback

typedef void (^Handler)(BOOL success, id response, NSError *error);

- (void)makeRequestWithHandler:(Handler)handler;

But you have to make this request dozens of times, and you want to reuse the same failure handler in most cases? Easy, just have a factory function that returns a block:

typedef void (^SuccessHandler)(id response);

typedef void (^ErrorHandler)(NSError *error);

@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

@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:

@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

@remi
remi / .gitconfig
Created March 20, 2012 19:20
Find the most used verbs in your Git commit messages
[alias]
verbs = !git log --pretty=format:'%s' | cut -d \" \" -f 1 | sort | uniq -c | sort -nr
@closerminds
closerminds / post_archive_script.sh
Last active February 14, 2020 10:46
Swift 5 universal framework with workaround for Xcode10.2 issue #48635615
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@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] }
}
}
@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
@jofi
jofi / ruby_files_in_load_paths.rb
Last active May 22, 2021 21:10
Quick tricks to expand load paths in ruby
# expand_path is genuine and DOES KNOW ABOUT absolute and relative paths
File.expand_path('relative/path/to/dir_or_file', '/start/path') # "/start/path/relative/path/to/dir_or_file"
File.expand_path('../application', __FILE__) # "/absolute/path/to/FILE/../application"
File.expand_path('/path/to/dir_or_file', '/start/path') # "/path/to/dir_or_file"
File.expand_path('../path/to/dir_or_file', '/start/path') # "/start/path/to/dir_or_file"
# join seems to be STUPID. It just joins strings (and adds file separator if needed)
File.join('some/path/', '/other/path.rb') # "some/path/other/path.rb"
# modify the global load path: