Skip to content

Instantly share code, notes, and snippets.

Avatar

Alejandro Ramirez janodev

View GitHub Profile
@janodev
janodev / BouncyButton.swift
Created Mar 16, 2018
A delegate implemented with generics and a static method
View BouncyButton.swift
// From “Better Strategies Through Types”
// http://www.figure.ink/blog/2018/3/11/better-strategies-through-types
import UIKit
protocol BouncyDelegate {
static func animateBounce(for view: UIView)
}
enum ShakeStrategy: BouncyDelegate
@janodev
janodev / PackageApplication
Created May 31, 2017
PackageApplication script from Xcode 8.2.1
View PackageApplication
#!/usr/bin/perl
#
# PackageApplication
#
# Copyright (c) 2009-2012 Apple Inc. All rights reserved.
#
# Package an iPhone Application into an .ipa wrapper
#
use Pod::Usage;
@janodev
janodev / Person.m
Created May 16, 2017
Right and wrong ways to call a block property
View Person.m
#import <Foundation/Foundation.h>
#undef X
typedef void (^salute_t)();
@interface Person : NSObject
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) salute_t salute;
View Colors.swift
enum Colors: Int64
{
case black = 0x000000ff
case white = 0xffffffff
func color() -> UIColor
{
let red = CGFloat((self.rawValue >> 24) & 0xff) / 255.0
let green = CGFloat((self.rawValue >> 16) & 0xff) / 255.0
let blue = CGFloat((self.rawValue >> 8) & 0xff) / 255.0
View AppDelegate.swift
import UIKit
import PluggableApplicationDelegate
@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate
{
override var services: [ApplicationService] {
return [
LoggerApplicationService()
]
@janodev
janodev / resign.sh
Created Mar 28, 2017 — forked from mcxiaoke/resign.sh
A simple tool for resigning an iOS app ipa with a new certificate/mobileprovision
View resign.sh
#!/usr/bin/env bash
if [[ ! ( # any of the following are not true
# 1st arg is an existing regular file
-f "$1" &&
# ...and it has a .ipa extension
"${1##*.}" == "ipa" &&
# 2nd arg is an existing regular file
-f "$2" &&
# ...and it has an .mobileprovision extension
@janodev
janodev / Optional+Extension.swift
Created Feb 18, 2017
Chainable closures for optional types.
View Optional+Extension.swift
import Foundation
extension Optional
{
@discardableResult
func ifSome(_ handler: (Wrapped) -> Void) -> Optional {
switch self {
case .some(let wrapped): handler(wrapped); return self
case .none: return self
}
@janodev
janodev / diff.mdown
Created Jan 13, 2017 — forked from ndarville/diff.mdown
Paul Heckel's Diff Algorithm
View diff.mdown

[Isolating Differences Between Files][paper]

Advantage over Other Algorithms

The diff output is more specific:

[I]f a whole block of text is moved, then all of it, rather than just the beginning and end, is detected as changed.

>The algorithm described here avoids these difficulties. It detects differences that correspond very closely to our intuitive notion of difference.

@janodev
janodev / gist:76588cc804bc34766328dc5962b10f15
Created Jan 4, 2017
Kill dupes in Open With context menu
View gist:76588cc804bc34766328dc5962b10f15
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user;killall Finder
@janodev
janodev / BaseConverter.swift
Created Aug 20, 2016
A base converter in Swift 3. For instance, BaseConverter.representNumber(number: 3405691582, inBase: 16) is "cafebabe"
View BaseConverter.swift
import Foundation
public struct BaseConverter
{
static let alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // 62 digits
static func representNumber(n: Int, asciiAlphabet: String) -> String
{
let base = asciiAlphabet.lengthOfBytes(using: String.Encoding.utf8)
if (n < base){