Skip to content

Instantly share code, notes, and snippets.

View patridge's full-sized avatar

Adam Patridge patridge

View GitHub Profile
@patridge
patridge / ScreenshotsFromPowerPointSlides
Last active August 29, 2015 13:56
PowerPoint slide screenshots via AppleScript
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
@patridge
patridge / MainActivity.cs
Created September 19, 2014 15:47
Core reproduction code for `NoSuchMethodError` in Google Analytics code using Google Play Services Xamarin Component (v19.0.0.1)
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;
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");
@patridge
patridge / AppDelegate.cs
Created February 5, 2015 17:05
Sample: BTProgressHUD blocking tab bar
using System;
using Foundation;
using UIKit;
using CoreGraphics;
using BigTed;
using System.Threading.Tasks;
using System.Linq;
using ObjCRuntime;
namespace HudOverTabsSample {
@patridge
patridge / gist:2ca7e309cd53716fb384
Created February 17, 2015 15:38
Android: what ID is that thing?
// 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);
@patridge
patridge / UITableViewWithoutLayoutMargins.cs
Last active August 29, 2015 14:15
UITableView and UITableViewCell without the iOS 7/8 margins.
// 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;
@patridge
patridge / ColorHelpers.cs
Created June 16, 2015 19:03
Xamarin Color Helper
// 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 {
namespace YourNamespace.Controllers {
using System.Web.Mvc;
using System.Web.SessionState;
using System;
[SessionState(SessionStateBehavior.ReadOnly)]
public class AjaxParallelController : Controller {
public JsonResult GetWait(int i = -1) {
System.Threading.Thread.Sleep(5000);
return Json(new { id = i, type = "parallel", ts = DateTime.Now.Ticks }, JsonRequestBehavior.AllowGet);
}
@patridge
patridge / gist:3907891
Created October 17, 2012 20:18
Bug: Custom UITabBarController calling ViewDidLoad from base constructor.
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace TabBarFailTest {
public class Application {
static void Main(string[] args) {
try {
UIApplication.Main(args, null, "AppDelegate");
}
@patridge
patridge / MongoDateTimeExtensions.cs
Created December 9, 2015 16:50
Creating Mongo ObjectIds manually (e.g., for testing) from a given DateTime object.
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;
}