Skip to content

Instantly share code, notes, and snippets.

@lothrop
lothrop / gist:8186857
Last active October 2, 2017 21:04
Xamarin.iOS shake animation
public static async Task AnimateShakeAsync(UIView view)
{
await AnimateHorizontalMovementAsync(view, -10);
await AnimateHorizontalMovementAsync(view, 20);
await AnimateHorizontalMovementAsync(view, -20);
await AnimateHorizontalMovementAsync(view, 20);
await AnimateHorizontalMovementAsync(view, -15);
await AnimateHorizontalMovementAsync(view, 10);
await AnimateHorizontalMovementAsync(view, -5);
}
IObservable<double> pos
= from joint in joints
select
(joint[JointType.FootLeft].Position.Y
+ joint[JointType.FootRight].Position.Y) / 2.0;
public async Task<bool> DoSomethingAsync()
{
return true;
}
public async Task<bool> DoesWebContentMatchPatternAsync(Uri uri, Regex pattern)
{
HttpClient client = new HttpClient();
string html = await client.GetStringAsync();
bool matches = pattern.Matches(html);
return matches;
}
@lothrop
lothrop / firstattempt.cs
Last active August 29, 2015 14:19
Reading messages from the serial port using reactive extensions
IObservable<byte> serialPortSource = Observable.FromEventPattern<
SerialDataReceivedEventHandler,
SerialDataReceivedEventArgs>
(
handler => _serialPort.DataReceived += handler,
handler => _serialPort.DataReceived -= handler
).SelectMany(_ =>
{
var buffer = new byte[1024];
var ret = new List<byte>();
private UIScrollView _scrollView;
private UIView _contentView;
public override void ViewDidLoad()
{
base.ViewDidLoad();
_scrollView = new UIScrollView
{
ShowsHorizontalScrollIndicator = false,
using MvvmCross.Binding.BindingContext;
using MvvmCross.iOS.Views;
using iOSViewDemo.Core.ViewModels;
using UIKit;
namespace iOSViewDemo.iOS.Views
{
public class CodeViewController : MvxViewController<FirstViewModel>
{
private UILabel UiLabel { get; } = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false };
@lothrop
lothrop / CLib.Platform.c
Last active August 5, 2023 20:00
Using C libraries in Xamarin projects
#include <stdint.h>
#include "CLib.h"
int32_t clib_add(int32_t left, int32_t right)
{
return clib_add_internal(left, right);
}
@lothrop
lothrop / parse.cs
Created June 1, 2017 16:22
Parse API usage example
public AppDelegate ()
{
// Initialize the Parse client with your Application ID and .NET Key found on
// your Parse dashboard
ParseClient.Initialize("YOUR APPLICATION ID", "YOUR .NET KEY");
}
@lothrop
lothrop / certpinning.cs
Created March 9, 2018 05:59
Code describing certificate pinning for .NET.
// Put this line in initialization code
ServicePointManager.ServerCertificateValidationCallback = CheckCertificate;
private static bool CheckCertificate(
object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslpolicyerrors)
{
// public key for www.microsoft.com
const string rxpectedPublicKey = "3082010A0282010100CCEAE2843C1BA9352E015D159D854E91CDAC153F6EE5168E1E8803A5A041DA5D83350E83D4271C6DFAECA1C2493CC8864528B2BD00A5F4AADA935453A1DD3164EFBB8624A95FCAE82956CFB9B0619F7E1774CB67064B23A5B492DC7FFBF7D6D46378DFF1362F42787B5C2B8EA4B2A829F647530DDD48BB10CEF5F378E4B44F66446E3A9372C9700794CC950CEE177E0B7C0981FFB2C9ABD59A98AFDF1D3BD880894F9E16BCFA86E0420097C5CCC5D6CE76E9C2BB1DE354E3139CCF2641DA07D04E2AE2D9C927C44212117B07B116D257953F3C2A3E927C8A1EDA7699C6A0D6FED415573471203D3DDA65DD5448CBD8C67A1A870D935A4F7B3A98F303948E003B0203010001";