Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Thomvis / TVPopTestsViewController.m
Created May 1, 2014 08:34
An attempt to reproduce 'pid controller' behavior (http://www.mobypicture.com/user/thomvis88/view/16585968) with the Facebook pop framework (https://github.com/facebook/pop).
//
// TVPopTestsViewController.m
// TVPopTests
//
// Created by Thomas Visser on 30/04/14.
//
//
#import "TVPopTestsViewController.h"
@Thomvis
Thomvis / gist:e4a30008c3b685d8c8fd
Created June 16, 2014 09:33
Make a view 'pop' in place
CGAffineTransform initialTransform = label.transform;
label.transform = CGAffineTransformScale(initialTransform, 0.99, 0.99);
[UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1000 options:0 animations:^{
label.transform = initialTransform;
} completion:nil];
@Thomvis
Thomvis / gist:732a944475062d0d721c
Created June 17, 2014 07:21
Replacing self in initWithCoder: does not work, fails with: "This coder requires that replaced objects be returned from initWithCoder:"
- (id)initWithCoder:(NSCoder *)coder
{
Class class = [currentConfiguration() customViewClassForViewClass: [self class]];
if (class != [self class]) {
id customSubclass = [[class alloc] initWithCoder: coder];
return customSubclass;
} else {
self = [super initWithCoder:coder];
@Thomvis
Thomvis / ReverseStringTest.swift
Created June 26, 2014 14:57
ReverseView<String> to String
extension ReverseView {
func __conversion() -> String {
var res = ""
for char in self {
res += char as Character
}
return res
}
future(fibonacci(10)).onSuccess {
println("The 10nth fibonacci number is \($0)")
}
// A naive fibonacci implementation
func fibonacci(n: Int) -> Int {
switch n {
case 0...1:

On iOS 8 beta 4, this constraint:

[NSLayoutConstraint constraintWithItem:_galleryView 
                             attribute:NSLayoutAttributeLeading 
                             relatedBy:NSLayoutRelationEqual 
                                toItem:self.view 
                             attribute:NSLayoutAttributeLeft 
                            multiplier:1.0f 
 constant:0];
@Thomvis
Thomvis / gist:9357dd16cfd1b2a6f304
Created August 5, 2014 14:16
This algorithm does something
let n = 10;
var sum = 0.0;
for k in 1...n {
let term = pow(-1,Double(k+1)) / Double(2*k - 1)
sum += term*4
sum
}
@Thomvis
Thomvis / b6-recgenhang.swift
Created August 20, 2014 06:30
This snippet hangs the execution indefinitely on Xcode 6 beta 6
public class A<T> {
var callbacks: A<T>?
}
A<Int>()
Using ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.1]

--------------------------------------------------------------------------------
Running the specs
--------------------------------------------------------------------------------
Pod::Command::Init
 ✓ complains if project does not exist (7 ms)
@Thomvis
Thomvis / CGFloatEquals1000
Last active August 29, 2015 14:10
Comparing floats
inline BOOL CGFloatEquals1000(CGFloat a, CGFloat b) {
return fabsf(a - b) <= (1.0f/1000.0f);
}