Skip to content

Instantly share code, notes, and snippets.

View adrianstevens's full-sized avatar

Adrian Stevens adrianstevens

View GitHub Profile
string strIn = "2001:DB8::/120";
//Split the string in parts for address and prefix
string strAddress = strIn.Substring(0, strIn.IndexOf('/'));
string strPrefix = strIn.Substring(strIn.IndexOf('/') + 1);
int iPrefix = Int32.Parse(strPrefix);
IPAddress ipAddress = IPAddress.Parse(strAddress);
//Convert the prefix length to a valid SubnetMask
@adrianstevens
adrianstevens / compass-cardinal
Created December 28, 2013 19:29
Compass heading to cardinal direction in c#
public static string DegreesToCardinal(double degrees)
{
string[] caridnals = { "N", "NE", "E", "SE", "S", "SW", "W", "NW", "N" };
return caridnals[ (int)Math.Round(((double)degrees % 360) / 45) ];
}
public static string DegreesToCardinalDetailed(double degrees)
{
string[] caridnals = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N" };
return caridnals[ (int)Math.Round(((double)degrees*10 % 3600) / 225) ];
@adrianstevens
adrianstevens / xamgridheader
Created June 6, 2014 22:40
Xamarin.Forms Grid with headers code snippet
public class GridLayoutPage : ContentPage
{
public GridLayoutPage()
{
var layout = new StackLayout
{
Orientation = StackOrientation.Vertical,
Padding = 20
};
@adrianstevens
adrianstevens / Simple Grove BLE example
Created November 11, 2014 05:40
Seeed Grove BLE with Intel Edison UART (2 way serial)
int incomingByte = 0; // for incoming serial data
const int pinButton = 6; // pin of button define here
const int pinLed = 3; // pin of led define here
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("hello");
@adrianstevens
adrianstevens / XamVisualFormatLan
Created December 5, 2014 05:17
Xamarin Visual Format Language Example for iOS Auto Layouts
using System;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
namespace Code
{
public class MyViewController : UIViewController
{
UIButton button1, button2, button3, button4;
@adrianstevens
adrianstevens / gist:13698d6c7210b3855528
Created January 19, 2015 22:45
WPF execute command line
using System;
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\someapp.exe"; // full path
@adrianstevens
adrianstevens / gist:933d66faaea83e165f5f
Created January 20, 2015 20:09
Xamarin IOS C# NSAttributedString example
/// http://forums.xamarin.com/discussion/18460/uitextview-and-html
/// <summary>
/// Gets the attributed string from html-string.
/// </summary>
/// <returns>The attributed string from html.</returns>
/// <param name="html">Html.</param>
public static NSAttributedString GetAttributedStringFromHtml(string html)
{
NSError error = null;
var htmlString = new NSAttributedString (NSUrl.FromString(html),
@adrianstevens
adrianstevens / gist:19530b8992a3a9107da7
Created March 31, 2015 22:00
Xamarin Forms Stepper
public App ()
{
int count = 0;
var myPage = new ContentPage ();
var stepperlabel = new Label
{
Text = "Stepper value is 0",
HorizontalOptions = LayoutOptions.Center,
@adrianstevens
adrianstevens / gist:5c1c33e20d911cf9121c
Created April 10, 2015 23:49
IOS mapping - distance between two points
using System;
using CoreGraphics;
using Foundation;
using UIKit;
using MapKit;
using CoreLocation;
using System.Diagnostics;
namespace MappingApp
{
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
var password = "9a55W0rd!!";
var salt = Encoding.Unicode.GetBytes("5a1t");
byte[] keymaterial = NetFxCrypto.DeriveBytes.GetBytes(password, salt, 1000, 32);