Skip to content

Instantly share code, notes, and snippets.

View acerosalazar's full-sized avatar

Felix J. Acero acerosalazar

View GitHub Profile
@acerosalazar
acerosalazar / FileReader.swift
Last active July 7, 2018 10:11
A bidirectional, memory efficient file reader. Good for uses cases where only a portion of the file needs to be read – e.g read last 10 lines of the file.
import Foundation
// MARK: -
class FileReader: Sequence, IteratorProtocol {
// MARK: - Private Members
private let file: URL
private let delimiter: Data
@acerosalazar
acerosalazar / NSError+Extensions.swift
Last active July 16, 2018 16:52
A set of extensions for NSError to make it easy to create and manage nested NSErrors
import Foundation
// MARK: -
extension NSError {
func contains(domain: String, code: Int, checkUnderlyingErrors: Bool = true) -> Bool {
return first(withDomain: domain, code: code, checkUnderlyingErrors: checkUnderlyingErrors) != nil
@acerosalazar
acerosalazar / CustomURLProtocol.swift
Last active June 30, 2018 19:10
CustomURLProtocol for intercepting the HTTP and HTTPS requests made by a macOS/iOS application.
import Foundation
/*:
# Description
Can be used to intercept HTTP and HTTPS calls made
by the application and introduce custom logic: e.g:
logging, custom caching, etc.
@acerosalazar
acerosalazar / Logger.swift
Created June 14, 2018 16:11
A quick and simple logger for Mac. Useful for quick prototypes and POCs
import Foundation
private let logFile = "Library/Logs/\(Date().timeIntervalSince1970).log"
func log(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
let formattedMessage = "\(Date()) [\(URL(fileURLWithPath: file).lastPathComponent):\(function):\(line)] \(message)"
let task: Process = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", "echo '\(formattedMessage)' >> '\(logFile)'"]
task.launch()
#! /usr/bin/env bash
#
# This script acts as a wrapper of carthage and as such it will handle
# the same commands handled by carthage, doing aditional work in some
# cases (e.g bootstrap) and simply relaying the invokations to carthage
# in the others.
#
# Decorated Commands:
# - bootstrap:
# When invoking for the first time, the script will let Carthage run
@acerosalazar
acerosalazar / gist:3618ae1fdb3ae47d883d9ee0f605d567
Created July 15, 2017 16:10
Pre-push hook for checking swift and bash files using swiftlint and shellcheck
#! /usr/bin/env bash
# set -o xtrace
set -o errexit
set -o nounset
set -o pipefail
function error() {
local -r TAG="$1"
@acerosalazar
acerosalazar / IFMLAppPresenterImpl.m
Created October 11, 2014 15:41
Forwarding methods to underlying ViewElements
#pragma mark - Runtime Methods
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
for(NSObject *vElem in self.viewElements) {
if([vElem respondsToSelector:selector]){
return [vElem methodSignatureForSelector:selector];
}
@acerosalazar
acerosalazar / IFMLCodeGenerator - Manifest.mf
Last active August 29, 2015 14:07
Dependencies required by the 'IFMLCodeGeneration' Eclipse Plugin Project.
// Manifest.mf
Require-Bundle:
com.google.guava,
com.google.inject;bundle-version="3.0.0",
org.eclipse.xtend.lib;bundle-version="2.7.2",
org.eclipse.emf.common;bundle-version="2.10.1",
org.eclipse.emf.ecore;bundle-version="2.10.1",
org.eclipse.emf.ecore.xmi;bundle-version="2.10.1",
org.eclipse.xtext.xbase.lib,
IFMLEditor;bundle-version="1.0.0"
@acerosalazar
acerosalazar / IFMLCodeGenerator-Main.xtend
Last active April 27, 2017 21:24
A template for creating an Xtend based CodeGenerator using the Ecore implementation of the IFML metamodel and a sample model.
package generator
// This code is based on this stackoverflow answer:http://stackoverflow.com/questions/12458852/load-emf-model-instance-in-xtend
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
import org.eclipse.emf.ecore.EPackage
@acerosalazar
acerosalazar / hack.sh
Created June 20, 2012 22:32 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#