Skip to content

Instantly share code, notes, and snippets.

@wislon
wislon / test.cs
Last active August 29, 2015 14:08
Write int32 to binary file
/*stick this in linqpad and then open the resulting file in a hex editor (or sublime text)*/
Int32 bob = 640036;
using (var fs = new FileStream("d:\\temp.dat", FileMode.Create, FileAccess.ReadWrite))
{
var br = new BinaryWriter(fs);
br.Write(bob); // writes out 24 c4 09 00
fs.Flush();
fs.Close();
@wislon
wislon / FacebookOAuth2Helper.cs
Created February 7, 2015 01:09
OAuth2 Facebook Authentication with Xamarin.Auth component example
using System;
using System.Threading.Tasks;
using Android.Content;
using Xamarin.Auth; // install this component from the component store or nuget
namespace Mobile.Droid.Classes
{
public static class FacebookOAuth2Helper
{
/// <summary>
@wislon
wislon / ViewExtensions.cs
Last active August 29, 2015 14:15
Animation code samples
using Android.Content;
using Android.Views;
using Android.Views.Animations;
namespace Mobile.Droid.Extensions
{
// invoke with anyView.BringViewInWithAnimation/TakeViewOutWithAnimation
// where animation param is predefined animations from xml, code, etc.
// e.g. inAnimation = AnimationUtils.LoadAnimation(Activity, Resource.Animation.bottom_slide_in);
@wislon
wislon / datatemplate_itemtemplate_xaml_template.md
Last active September 25, 2015 05:46
Xamarin Forms XAML Dynamic ListView ItemTemplate Selection

Sample Grid XAML DataTemplate with a Grid layout

Has a basic 5-column, 6-row layout, with padding/spacing columns/rows delineated with coloured boxviews (since gridview cells don't have borders, we can't see where one cell stops and another begins)

Note, to get the design-time intellisense for the DataContext binding, you'll need to add the following namespaces to the top of your XAML file (can go beneath the usual xamarin forms namespaces, order isn't really important):

 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@wislon
wislon / webapi_httpclient_ssl_demo.cs
Created February 22, 2013 12:11
Web API HttpClient SSL demo (concept only - using extremely naiive server SSL certificate validation)
// See:
// http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/d80eb3c7-8d1b-4284-a157-ba415cfbcc14 (taicomjp's solution)
// http://blog.aggregatedintelligence.com/2010/06/wcf-ssl-certificates-and-certificate.html
// http://msdn.microsoft.com/en-us/library/system.net.security.remotecertificatevalidationcallback.aspx
// also see http://www.iis.net/learn/manage/configuring-security/how-to-set-up-ssl-on-iis
// to quickly set up a test certificate on a local website in IIS
// All this does is happily accept any certificate thrown at it, regardless of whether it's got the right
// domain name, etc.
// you'll need to add references/usings for:
@wislon
wislon / QDGetMethodNamesUsingReflection.cs
Last active December 19, 2015 14:58
Quick and dirty using System.Reflection to get method names from class/type in assembly
// For better way which actually allows you to retrieve the method body and parse it, have a look at Mono.Cecil
// and links below:
// see http://stackoverflow.com/questions/5741350/look-if-a-method-is-called-inside-a-method-using-reflection
// and http://stackoverflow.com/questions/4372205/how-to-inject-call-to-system-object-equals-with-mono-cecil
// and http://www.codeproject.com/Articles/499960/Accessing-Assembly-Metadata-with-Reflection-or-Mon
private static IEnumerable<MethodInfo> GetTheMethods()
{
string assemblyFile = Assembly.GetAssembly(typeof (YourClass)).Location;
Assert.IsTrue(File.Exists(assemblyFile));
@wislon
wislon / IcmpEchoSample.cs
Created March 25, 2014 05:24
C# ICMP Echo example
// Add a reference to (and using) System.Net.NetworkInformation
string addressOrIp = "127.0.0.1";
Ping ping = new Ping();
PingReply reply = ping.Send(addressOrIp);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine ("Address: {0}", reply.Address.ToString ());
Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
@wislon
wislon / Android Privacy Policy Template
Created March 12, 2017 01:22 — forked from alphamu/Android Privacy Policy Template
A template for creating your own privacy policy for Android apps. Look for "[" and "<!--" to see where you need to edit this app in order to create your own privacy olicy.
<html>
<body>
<h2>Privacy Policy</h2>
<p>[Individual or Company Name] built the [App Name] app as a [open source | free | freemium | ad-supported | commercial] app. This SERVICE is provided by [Individual or company name] [at no cost] and is intended
for use as is.</p>
<p>This page is used to inform website visitors regarding [my|our] policies with the collection, use, and
disclosure of Personal Information if anyone decided to use [my|our] Service.</p>
<p>If you choose to use [my|our] Service, then you agree to the collection and use of information in
relation with this policy. The Personal Information that [I|we] collect are used for providing and
improving the Service. [I|We] will not use or share your information with anyone except as described
@wislon
wislon / boxstarter01.ps1
Last active September 15, 2017 05:32
BoxStarter scripts For initial windoze setup
##################
# Blatantly swiped from
# - Nick Craver's gist at https://gist.github.com/NickCraver/7ebf9efbfd0c3eab72e9
# - Jess Frazelle's at https://gist.github.com/jessfraz/7c319b046daa101a4aaef937a20ff41f
##################
# To run this locally, do
# Install-BoxstarterPackage -PackageName <this.RAW.gist.url> -DisableReboots
# i.e. Install-BoxstarterPackage -PackageName https://gist.githubusercontent.com/wislon/a2a7716fad4dccf58961d1d408d74b89/raw/bdb7f16939800586cef71bd4df7c9596370506ed/boxstarter01.ps1 -DisableReboots
# If you allow reboots, you will likely be prompted for your password so it can reboot/relog in as necessary.
@wislon
wislon / BluetoothHelper.cs
Created November 22, 2017 21:20
Android Bluetooth Helper (power up/down adapter, build config based on SDK level etc.)
public static class BluetoothHelper
{
private static readonly BluetoothManager _manager;
private static readonly BluetoothAdapter _adapter;
static BluetoothHelper()
{
var context = Application.Context;
_manager = (BluetoothManager)context.GetSystemService("bluetooth");
_adapter = _manager.Adapter;