Skip to content

Instantly share code, notes, and snippets.

@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 / MediaGalleryHelper.cs
Created November 6, 2014 03:13
Xamarin: Quickly add or remove an item from Android device's gallery
using Android.Content;
using Android.Media;
using Android.Provider;
using Android.Util;
using Uri = Android.Net.Uri;
namespace Classes.Helpers
{
/// <summary>
@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 / ExportBlobToFile.sql
Created July 16, 2014 04:18
Export BLOB field from SQL Server to file on disk
-- because I keep having to do this at odd times and I keep having to look it up
use master
go
EXEC sp_configure 'show advanced options', 1
GO
Reconfigure
go
@wislon
wislon / keymap.cson
Last active May 7, 2021 22:06
Atom key bindings for numeric keypad
# some additional keybindings that let you use the keypad as arrows (old-school)
'.editor':
'num-left': 'core:move-left'
'num-right': 'core:move-right'
'num-up': 'core:move-up'
'num-down': 'core:move-down'
'num-end' : 'editor:move-to-end-of-screen-line'
'num-home' : 'editor:move-to-first-character-of-line'
'num-pageup': 'core:page-up'
@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 / 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 / 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: