Skip to content

Instantly share code, notes, and snippets.

View onevcat's full-sized avatar
🐭

Wei Wang onevcat

🐭
View GitHub Profile
@onevcat
onevcat / gist:3754895
Created September 20, 2012 09:27
local block
// Use the __block storage modifier to allow changes to 'price'
__block float price = 1.99;
float (^finalPrice)(int) = ^(int quantity)
{
return quantity * price;
};
int orderQuantity = 10;
price = .99;
@onevcat
onevcat / gist:3754903
Created September 20, 2012 09:28
uianimation 3.x style
[UIView beginAnimations:@"ToggleSiblings"context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIViewsetAnimationDuration:1.0];
// Make your changes
[UIView commitAnimations];
@onevcat
onevcat / gist:3754908
Created September 20, 2012 09:30
uianimation block style
[UIView animateWithDuration:5.0animations:^{
view.opacity = 0.5;
}];
@onevcat
onevcat / gist:3754919
Created September 20, 2012 09:33
block ins
unary_operation_t square;
square = ^(double operand) {
return operand * operand;
}
@onevcat
onevcat / gist:3754928
Created September 20, 2012 09:37
add constraint
[NSLayoutConstraint constraintWithItem:button
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-padding]
@onevcat
onevcat / gist:3754934
Created September 20, 2012 09:38
Visual Format Language Constraint
[NSLayoutConstraint constraintsWithVisualFormat:@"[cancelButton]-[acceptButton]"
options:0
metrics:nil
views:viewsDictionary];
@onevcat
onevcat / gist:3754939
Created September 20, 2012 09:39
NSDictionaryOfVariableBindings
UIButton *cancelButton = ...
UIButton *acceptButton = ...
viewsDictionary = NSDictionaryOfVariableBindings(cancelButton,acceptButton);
@onevcat
onevcat / gist:3754943
Created September 20, 2012 09:40
layout ani
[UIView animateWithDuration:0.5 animations:^{
[view layoutIfNeeded];
}];
my $array = decode_json($json_out);
get {
var freeObject = (from item in objectList
where item.active == false
select item).FirstOrDefault();
if (freeObject == null) {
freeObject = Object.Instantiate(objectToRecycle);
objectList.Add(freeObject);
}
return freeObject;
}