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

- (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];
#import TTTAttributedLabel.h
@interface MyAttributedLabel : TTTAttributedLabel
@end
<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>
- (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
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];
- (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 {
@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) {
//
// CameraView.swift
// ALCameraViewController
//
// Created by Alex Littlejohn on 2015/06/17.
// Copyright (c) 2015 zero. All rights reserved.
//
import UIKit
import AVFoundation

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: