Skip to content

Instantly share code, notes, and snippets.

View 942v's full-sized avatar
🎯
Focusing

Guillermo Sáenz 942v

🎯
Focusing
View GitHub Profile
Say you have a list of a random hashable type (the same type throughout), in an arbitrary order.
How do you find the most common item in the list (along with its count) after the first instance of a given item?
Examples:
[1, 1, 1, 2, 3, 4, 4, 1], 2 -> (4, 2)
[1, 1, 1, 2, 3, 4, 4, 1], 1 -> (1, 3)
["red", "green", "blue", "green", "blue"], "green" -> ("blue", 2)
What we're really looking for here is not just a working solution, but well-crafted, idiomatic Swift.
We want to see an API that fits with Swift APIs, with clear separation of concerns and well-named functions and variables.
@Nikeshsuwal
Nikeshsuwal / sublime-command-line.md
Created February 19, 2018 04:03
Launch Sublime Text from the command line on OSX

Launch Sublime Text from the command line on OSX

Sublime Text includes a command line tool, subl, to work with files on the command line. This can be used to open files and projects in Sublime Text, as well working as an EDITOR for unix tools, such as git and subversion.

Requirements

  • Sublime text 2 or 3 installed in your system within Applications folder

Setup

// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)
@sundeepgupta
sundeepgupta / create-fat-framework.sh
Last active December 16, 2024 20:58
Script to create a universal or "fat" binary for an iOS framework.
#!/bin/bash
# Adapted from http://stackoverflow.com/questions/24039470/xcode-6-ios-creating-a-cocoa-touch-framework-architectures-issues/26691080#26691080
# and https://gist.github.com/cromandini/1a9c4aeab27ca84f5d79
# Create a new aggregate target.
# For the automatically generated scheme, change its build config to "release".
# Ensure this target's "product name" build setting matches the framework's.
# Add a run script with `source "${PROJECT_DIR}/path_to_this_script`
@brennanMKE
brennanMKE / README.md
Last active July 18, 2023 17:53
Check Bitcode support with Static Libraries

Check Bitcode

It is important to enable Bitcode in all libraries if the app is going to enable Bitcode. These scripts check each static library for Bitcode and echo a string which shows up as a warning in the build log. It is an easy way to always check that the dependencies have what is needed.

Usage

Place check_bitcode.sh in your project directory. Then add a Run Script in Build Phasese with the script named RunScript.sh. Name that new section as Check Bitcode and run the build. It may be necessary to make the shell script executble using chmod u+x check_bitcode.sh on the command-line.

Frameworks vs Static Libraries

@nepsilon
nepsilon / git-change-commit-messages.md
Last active November 19, 2024 18:18
How to change your commit messages in Git? — First published in fullweb.io issue #55

How to change your commit messages in Git?

At some point you’ll find yourself in a situation where you need edit a commit message. That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

Not pushed + most recent commit:

git commit --amend

This will open your $EDITOR and let you change the message. Continue with your usual git push origin master.

//
// UIBarButtonItem+Badge.swift
// PiGuardMobile
//
// Created by Stefano Vettor on 12/04/16.
// Copyright © 2016 Stefano Vettor. All rights reserved.
//
import UIKit
@mrackwitz
mrackwitz / Podfile.rb
Last active June 14, 2018 13:13
Force Duplicate Pod Targets by Pre Install Hook
# This will enforce that the pods with the names in the list below will be duplicated.
targets_to_duplicate = %w(AFNetworking)
pre_install do |installer|
pod_targets = installer.pod_targets.flat_map do |pod_target|
targets_to_duplicate.include?(pod_target.name) ? pod_target.scoped : pod_target
end
installer.aggregate_targets.each do |aggregate_target|
aggregate_target.pod_targets = pod_targets.select do |pod_target|
pod_target.target_definitions.include?(aggregate_target.target_definition)
end
@xbeta
xbeta / README.md
Last active October 7, 2025 02:19
Macbook Pro Bluetooth + WiFi 2.4GHz interference fix for Mavericks
@ccabanero
ccabanero / Count lines of code in Xcode project
Created August 9, 2014 12:14
Count lines of code in Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.[hm]" -print0 | xargs -0 wc -l