Skip to content

Instantly share code, notes, and snippets.

View Arlodotexe's full-sized avatar

Arlo Arlodotexe

View GitHub Profile
@WamWooWam
WamWooWam / .net-standard-2.0-uwp.md
Last active February 12, 2025 16:17
How to use .NET Standard 2.0 under UWP <= 10.0.15063

Enabling .NET Standard support on UWP apps targeting 15063 or below is relatively simple.

Step 1

Set your project's TargetPlatformMinVersion to anything above 15063, for this I've always used 16299 but other SDKs should work the same way

step-1

Step 2

Open your .csproj file in a text editor (right click, "Unload project", right click again, "Edit project file"), and add the following 2 lines to the first property group.

@Sergio0694
Sergio0694 / ReadOnlySpanEnumerator.cs
Last active January 6, 2020 00:19
A fast and allocation-free method to enumerate items in a collection
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System
{
/// <summary>
/// A <see langword="ref"/> <see langword="struct"/> that enumerates the items in a given <see cref="ReadOnlySpan{T}"/> instance
/// </summary>
/// <typeparam name="T">The type of items to enumerate</typeparam>
@passiondroid
passiondroid / OpacityHex.markdown
Last active February 20, 2025 19:10
Opacity percentage in a Hex color code

Android uses hexadecimal ARGB values, which are formatted as #AARRGGBB. That first pair of letters, the AA, represent the alpha channel. You must convert your decimal opacity values to a hexadecimal value. Here are the steps:

Alpha Hex Value Process

  • Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5

  • The fraction won't convert to hexadecimal, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55.

  • Enter your decimal value in a decimal-to-hexadecimal converter, like http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values.

@yetanotherchris
yetanotherchris / in-memory-http-server.cs
Last active February 4, 2024 14:00
In memory http server for C# unit and integration tests
public static Task BasicHttpServer(string url, string outputHtml)
{
return Task.Run(() =>
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add(url);
listener.Start();
// GetContext method blocks while waiting for a request.
HttpListenerContext context = listener.GetContext();
@alexsorokoletov
alexsorokoletov / uwp_image_convert_to_jpeg_quality.cs
Created May 23, 2016 02:03
How to convert image to JPEG and specify quality (q) parameter in UWP C# XAML
/// <summary>
/// Converts source image file to jpeg of defined quality (0.85)
/// </summary>
/// <param name="sourceFile">Source StorageFile</param>
/// <param name="outputFile">Target StorageFile</param>
/// <returns></returns>
private async Task<StorageFile> ConvertImageToJpegAsync(StorageFile sourceFile, StorageFile outputFile)
{
//you can use WinRTXamlToolkit StorageItemExtensions.GetSizeAsync to get file size (if you already plugged this nuget in)
var sourceFileProperties = await sourceFile.GetBasicPropertiesAsync();
@sw897
sw897 / TextSelectionReader.cs
Created May 13, 2016 01:28
Class that can be used to retrieve the currently selected text (if any) from an active control in the active window. It does this by trying several methods internally (UIAutomation, API calls using SendMessage + WM_GETTEXT, Clipboard). Be sure to reference UIAutomationClient and UIAutomationTypes!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Automation;
using System.Windows.Forms;
//WARNING: The code below is NOT for the faint of heart. Exceptions are swallowed freely, sendkeys
@aliostad
aliostad / gist:3202814
Created July 30, 2012 00:18
Serialisation and deserialisation of HTTP request and response messages in ASP.NET Web API
public interface IHttpMessageSerializer
{
void Serialize(HttpResponseMessage response, Stream stream);
void Serialize(HttpRequestMessage request, Stream stream);
HttpResponseMessage DeserializeToResponse(Stream stream);
HttpRequestMessage DeserializeToRequest(Stream stream);
}
public class MessageContentHttpMessageSerializer : IHttpMessageSerializer
@lsauer
lsauer / gist:2819387
Created May 28, 2012 14:11
Javascript - Replacing the escape character in a string literal
//www.lsauer.com 2012
//Answer to: http://stackoverflow.com/questions/1376440/javascript-replacing-the-escape-character-in-a-string-literal/10785991#10785991
//To better demonstrate and understand the string-escaping behavior of JS, take the following example:
//You can see what the string looks like in memory after being parsed by the JS-engine by splitting the string,
//thus also offering potential (ugly) solutions around this issue:
'file:///C:\funstuff\buildtools\viewer.html'.split('')
//>
["f", "i", "l", "e", ":", "/", "/", "/", "C", ":", "", "u", "n", "s", "t", "u",