Skip to content

Instantly share code, notes, and snippets.

View vendruscolo's full-sized avatar

Alessandro Vendruscolo vendruscolo

View GitHub Profile
@vendruscolo
vendruscolo / README.md
Created October 28, 2012 15:13
100MB read test

Using this file http://code.google.com/p/jquery-speedtest/downloads/detail?name=100MB.txt

This is one line full of 0s, so there are 104857600 0s.

wget http://jquery-speedtest.googlecode.com/files/100MB.txt

main.m reads the whole file at once. Doing so it occupies more than 200MB of memory (100MB for the NSString, another 100MB for the char array), as you can see here http://d.pr/i/jopC

main_memory_mapped.m maps the file in-memory, incrementally reading it; therefore its far less memory aggressive, as you can see here http://d.pr/i/YYzi

//
// CameraView.swift
// ALCameraViewController
//
// Created by Alex Littlejohn on 2015/06/17.
// Copyright (c) 2015 zero. All rights reserved.
//
import UIKit
import AVFoundation
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:

<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];
@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];