Skip to content

Instantly share code, notes, and snippets.

View eonist's full-sized avatar
🎯
Focusing

André J eonist

🎯
Focusing
View GitHub Profile
@gwengrid
gwengrid / TypeErasure.swift
Last active September 12, 2018 05:14
Example of type erasure with Pokemon
class Thunder { }
class Fire { }
protocol Pokemon {
typealias PokemonType
func attack(move:PokemonType)
}
struct Pikachu: Pokemon {
typealias PokemonType = Thunder
@sohayb
sohayb / ArrayDeepCopy.swift
Last active October 25, 2024 04:07
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@joepie91
joepie91 / monolithic-vs-modular.md
Last active September 19, 2024 04:07
Monolithic vs. modular - what's the difference?

When you're developing in Node.js, you're likely to run into these terms - "monolithic" and "modular". They're usually used to describe the different types of frameworks and libraries; not just HTTP frameworks, but modules in general.

At a glance

  • Monolithic: "Batteries-included" and typically tightly coupled, it tries to include all the stuff that's needed for common usecases. An example of a monolithic web framework would be Sails.js.
  • Modular: "Minimal" and loosely coupled. Only includes the bare minimum of functionality and structure, and the rest is a plugin. Fundamentally, it generally only has a single 'responsibility'. An example of a modular web framework would be Express.

Coupled?

In software development, the terms "tightly coupled" and "loosely coupled" are used to indicate how much components rely on each other; or more specifically, how many assumptions they make about each other. This directly translates to how easy it is to repla

func openAndSelectFile(filename:String){
let files = [NSURL(fileURLWithPath: filename)];
NSWorkspace.sharedWorkspace().activateFileViewerSelectingURLs(files);
}
@snej
snej / QRCodeScanner.m
Created September 21, 2015 16:45
Snippet showing how to capture QR codes from the device camera on iOS or Mac OS X
- (BOOL) startCapture: (NSError**)outError {
if (!_session) {
_session = [[AVCaptureSession alloc] init];
AVCaptureDevice* video = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
if (!video)
return [self failWithMessage: @"No video camera available" error: outError];
AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice: video
error: outError];
if (!input)
return [self failWithMessage: @"Couldn't acquire input device" error: outError];
@jackreichert
jackreichert / Keychain.swift
Last active January 11, 2017 02:43 — forked from s-aska/Keychain.swift
Swift Keychain class ( supported Xcode Version 7.0 beta 4 (7A165t) )
import UIKit
import Security
class Keychain {
class func save(key: String, data: NSData) -> Bool {
let query = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrAccount as String : key,
kSecValueData as String : data ]
@PurpleBooth
PurpleBooth / README-Template.md
Last active April 24, 2025 18:58
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@wszdwp
wszdwp / How_to_use_ZbarSDK in Swift.md
Last active April 22, 2019 13:48
How to use ZbarSDK in Swift

#How to use ZbarSDK in Swift(XCode 6.2, base SDK iOS 8.2)

##Steps

  1. Download ZbarSDK and drag ZbarSDK folder in Swift project, setup buiding settings according to the zBarSDK tutorial
  2. Add #import "ZBarSDK.h" in YourApp_Bridging_Header file
  3. In your ViewController add ZBarReaderDelegate, setup ZBarReader, receive barcode data

##Posible building issues:

  1. Missing required architecture arm64 in file ...
    Reason: the libzbar.a is not compiled to arm64 architecture
@rbobbins
rbobbins / protocols.md
Last active June 11, 2024 22:11
Notes from "Protocol-Oriented Programming in Swift"

PS: If you liked this talk or like this concept, let's chat about iOS development at Stitch Fix! #shamelessplug

Protocol-Oriented Programming in Swift

Speaker: David Abrahams. (Tech lead for Swift standard library)

  • "Crusty" is an old-school programmer who doesn't trust IDE's, debuggers, programming fads. He's cynical, grumpy.

  • OOP has been around since the 1970's. It's not actually new.

  • Classes are Awesome

    • Encapsulation
    • Access control
@mickmaccallum
mickmaccallum / gist:c2b322e059c9b3379245
Last active February 25, 2017 11:28
Swift recursive flatmap
func recursiveFlatmap<T, U: AnyObject>(list: [U]) -> [T] {
var results = [T]()
results.reserveCapacity(list.count)
for element in list {
if let subList = element as? [U] {
results += recursiveFlatmap(subList)
} else if let element = element as? T {
results.append(element)
}