Skip to content

Instantly share code, notes, and snippets.

View vendruscolo's full-sized avatar

Alessandro Vendruscolo vendruscolo

View GitHub Profile
import Foundation
// https://twitter.com/peres/status/1353810351264034818
func daysBetweenDates(start: Date, end: Date, calendar: Calendar) -> [Date] {
guard let diff = cal.dateComponents([.day], from: start, to: end).day else {
return []
}
// if you need to include end in the array, use 0...diff+1
return (0...diff).compactMap {

Keybase proof

I hereby claim:

  • I am vendruscolo on github.
  • I am vendruscolo (https://keybase.io/vendruscolo) on keybase.
  • I have a public key ASDw2bY1SCPd92Uv_-AEM_ZpWBwNDBxVjk4Wsn5vVZgu3go

To claim this, I am signing this object:

//
// CameraView.swift
// ALCameraViewController
//
// Created by Alex Littlejohn on 2015/06/17.
// Copyright (c) 2015 zero. All rights reserved.
//
import UIKit
import AVFoundation
@vendruscolo
vendruscolo / playground.swift
Created October 20, 2015 09:23
Type alias example
//: Playground - noun: a place where people can play
struct Foo<T> {
typealias FooHandler = (data: T) -> Void
let bar: T
var handler: FooHandler?
init(bar: T) {
- (instancetype)initWithCoder:(NSCoder *)coder {
if ((self = [self init])) {
NSDictionary *pointValue = [coder decodeObjectForKey:@"point"];
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)pointValue, &_point);
_number = [coder decodeDoubleForKey:@"number"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder {
typedef void (^pspdf_setter)(id self, SEL _cmd, id value);
static pspdf_setter pspdf_setterForKey(NSString *key) {
return ^(id self, SEL _cmd, id value) {
// The ivar name, from the original key: fooBar -> _fooBar
// It's a convention: don't break it
const char * ivarName = [[@"_" stringByAppendingString:[key capitalizedString]] UTF8String];
- (void)doStuff {
// Using a weak ref, we allow self to be deallocated before
// the block gets called. If in the block we used `self`
// directly, we'd create a retain cycle.
__weak typeof(self) weakSelf = self;
[self doSomethingElseWithBlock:^{
// Now keep a strong reference to self. This will fail
<html>
<head>
<noscript>&lt;META http-equiv="refresh" content="0;URL=http://CSS-Tricks.com"&gt;</noscript>
<script>location.replace("http:\/\/CSS-Tricks.com")</script>
</head>
</html>
#import TTTAttributedLabel.h
@interface MyAttributedLabel : TTTAttributedLabel
@end
- (void)setTextAlignment:(NSTextAlignment)textAlignment {
NSTextAlignment oldTextAlignment = self.textAlignment;
[super setTextAlignment:textAlignment];
if (textAlignment != oldTextAlignment) {
// update link attributes
if (self.linkAttributes) {
NSMutableDictionary *mutableLinkAttributes = [self.linkAttributes mutableCopy];
NSMutableDictionary *mutableActiveLinkAttributes = [self.activeLinkAttributes mutableCopy];