Skip to content

Instantly share code, notes, and snippets.

@dcastro
dcastro / gist:2816014
Created May 27, 2012 21:46
Current Unix Time in Objective-c
//current date
NSDate* date = [NSDate date];
//conversion to unix representation
NSTimeInterval time = [date timeIntervalSince1970];
@dcastro
dcastro / gist:2835703
Created May 30, 2012 11:36
iOS 3 types of crossfade animations
[UIView animateWithDuration:0.3 animations:^() {
self.commentContentLabel.alpha = (editing)? 0.0 : 1.0;
}];
////////////////
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.commentContentLabel cache:YES];
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=1;
theAnimation.repeatCount=2;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:-60];
[view.layer addAnimation:theAnimation forKey:@"animateLayer"];
@dcastro
dcastro / Snapped AppBar Button Styles.xaml
Created October 13, 2012 14:59
Snapped AppBar Button Styles
<Style x:Key="SnappedAppBarButtonStyle" TargetType="ButtonBase">
<Setter Property="Foreground" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="AutomationProperties.ItemType" Value="App Bar Button"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ButtonBase">
@dcastro
dcastro / Textless AppBar button style.xaml
Created October 31, 2012 22:28
Textless AppBar button style
<!-- StandardStyles.xaml -->
<Style x:Key="TextlessAppBarButtonStyle" TargetType="ButtonBase">
<Setter Property="Foreground" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="AutomationProperties.ItemType" Value="App Bar Button"/>
<Setter Property="Template">
@dcastro
dcastro / gist:9093000
Created February 19, 2014 14:17
Build an Expression that instantiates an Anonymous Type
public void CreateExpression()
{
Type argType = typeof (MyClass);
string propertyName = "Name";
ParameterExpression paramExpression = Expression.Parameter(argType, "item");
//Create "item.Name" and "item.GetType()" expressions
var propertyAccessExpression = Expression.Property(paramExpression, propertyName);
var getTypeExpression = Expression.Call(paramExpression, "GetType", Type.EmptyTypes);
@dcastro
dcastro / Git hook - prefix commit message
Created March 13, 2014 10:53
Git hook - prefix commit message
PREFIX="SVC-41+2: "
ORIG_MSG_FILE="$1"
T="/tmp/git-temp-commit-msg"
(printf "%s" "$PREFIX"; cat "$ORIG_MSG_FILE") > "$T"
cat "$T" > "$ORIG_MSG_FILE"
@dcastro
dcastro / NUnit Resharper Templates
Created July 16, 2014 09:25
NUnit Resharper Templates
[NUnit.Framework.TestAttribute]
public void $TestMethodName$()
{
$END$
}
@dcastro
dcastro / Enumerable.ZipAll
Created August 18, 2014 07:58
Enumerable.ZipAll
// https://dotnetfiddle.net/INhbdg
public static class EnumerableEx
{
public static IEnumerable<TReturn> ZipAll<T1, T2, TReturn>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
Func<T1, T2, TReturn> f,
T1 seed1,
T2 seed2)
@dcastro
dcastro / TakeWhileInclusiveAsync
Last active August 29, 2015 14:24
TakeWhileInclusive Async - using IAsyncEnumerable
/**
* Using Interactive Extensions Async / Ix-Async
* https://www.nuget.org/packages/Ix-Async/
* https://github.com/Reactive-Extensions/Rx.NET
*/
var tasks = Enumerable.Range(0, 10).Select(i => Task.Run(() =>
{
Debug.WriteLine("evaluating " + i);