This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DateTimeExtensions | |
{ | |
static readonly DateTime Epoch = new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | |
public static string AsObjectIdPrefix (this DateTime dateTime) | |
{ | |
var deltaSinceEpoch = dateTime - Epoch; | |
var seconds = (int)deltaSinceEpoch.TotalSeconds; | |
var secondsAsHex = seconds.ToString ("X").PadLeft (8, '0').ToLowerInvariant (); | |
return secondsAsHex; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you don't want to pull the whole [Splat](https://github.com/paulcbetts/splat) library over just for colors, | |
// here are a couple functions to help. | |
// Store your color values as hex-based `long`s and just convert them to native colors when you use them. | |
// NOTE: iOS uses RGBA floats (0..1) and Android uses ARGB ints (0..255) when converting. | |
// Usage example: | |
SomeView.SetBackgroundColor(MyAppColors.SomeGrayHighlight.AsNative()); | |
// Core library can hold your colors: | |
public static class MyAppColors { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LICENSE: MIT | |
public class UITableViewWithoutLayoutMargins : UITableView { | |
void InitializeWithoutMargins() { | |
// iOS 7 | |
if (RespondsToSelector(new Selector("setSeparatorInset:"))) { | |
SeparatorInset = UIEdgeInsets.Zero; | |
} | |
// iOS 8[+?] | |
if (RespondsToSelector(new Selector("setLayoutMargins:"))) { | |
LayoutMargins = UIEdgeInsets.Zero; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I had to use this to debug why `OnOptionsItemSelected` wasn't triggering for an ActionBar home tap. | |
// Turns out, `Resource.Id.home` and `Resource.Id.homeAsUp` are not related to `Android.Resource.Id.Home`. | |
var projectIdType = typeof(Resource.Id); | |
foreach (var field in projectIdType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)) { | |
if (item.ItemId == (int)field.GetValue(null)) { | |
Console.WriteLine("{0}: {1}", field.Name, item.ItemId); | |
} | |
} | |
var androidIdType = typeof(Android.Resource.Id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Foundation; | |
using UIKit; | |
using CoreGraphics; | |
using BigTed; | |
using System.Threading.Tasks; | |
using System.Linq; | |
using ObjCRuntime; | |
namespace HudOverTabsSample { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TaskHelper { | |
public static Task CompletedTask = AsCompletedTask(true); | |
public static Task<T> AsCompletedTask<T>(T result) { | |
TaskCompletionSource<T> precompletedSource = new TaskCompletionSource<T>(); | |
precompletedSource.SetResult(result); | |
return precompletedSource.Task; | |
} | |
public static void TrySetResultTask<TResult>(this TaskCompletionSource<TResult> tcs, Task<TResult> task) { | |
if (task == null) { | |
throw new ArgumentNullException("task"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.App; | |
using Android.Content; | |
using Android.Gms.Analytics; // via Google Play Services Xamarin Component (v19.0.0.1) | |
using Android.Gms.Analytics.Ecommerce; | |
using Android.Runtime; | |
using Android.Views; | |
using Android.Widget; | |
using Android.OS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Xamarin.iOS (using MonoTouch.UIKit;) | |
static Random rand = new Random(); | |
public static UIColor GetRandomColor() { | |
int hue = rand.Next(255); | |
UIColor color = UIColor.FromHSB( | |
(hue / 255.0f), | |
1.0f, | |
1.0f); | |
return color; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSObject keyboardShowObserver; | |
NSObject keyboardHideObserver; | |
public override void ViewWillAppear(bool animated) { | |
base.ViewWillAppear(animated); | |
keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, (notification) => { | |
NSValue nsKeyboardBounds = (NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.BoundsUserInfoKey); | |
RectangleF keyboardBounds = nsKeyboardBounds.RectangleFValue; | |
float height = View.Bounds.Height - keyboardBounds.Height; | |
if (NavigationController != null && NavigationController.TabBarController != null && NavigationController.TabBarController.TabBar != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Microsoft PowerPoint" | |
activate | |
set slideShow to run slide show slide show settings of active presentation | |
set finalShotSize to 250 | |
set oPres to active presentation | |
set desktopPath to (path to desktop) | |
set N to 1 | |
-- Give presentation enough time to start. | |
delay 0.5 |