Skip to content

Instantly share code, notes, and snippets.

View HakanL's full-sized avatar

Hakan Lindestaf HakanL

View GitHub Profile
@HakanL
HakanL / ListViewControl.xaml
Last active May 3, 2022 23:26
XAML UserControl showing ListView with DataTrigger for boolean replacement
<UserControl x:Class="TestApplication.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ListView>
<ListView.View>
<GridView>
@HakanL
HakanL / HighPrecisionTimer
Created January 30, 2013 00:34
C# code for a High Precision Timer (avg <1 ms for 25 ms interval). Fair use of CPU time. Uses NLog to log accuracy
using NLog;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Animatroller.Framework.Utility
{
public class HighPrecisionTimer : IDisposable
{
@HakanL
HakanL / pingpair_ack
Created May 5, 2015 20:24
Sample Arduino code to send a known NRF24 packet for sniffing
/*
// March 2014 - TMRh20 - Updated along with High Speed RF24 Library fork
// Parts derived from examples by J. Coliz <maniacbug@ymail.com>
*/
/**
* Example for efficient call-response using ack-payloads
*
* This example continues to make use of all the normal functionality of the radios including
* the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well.
* This allows very fast call-response communication, with the responding radio never having to
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29905.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Iot.Device.Bindings", "Iot.Device.Bindings\Iot.Device.Bindings.csproj", "{D512B7BA-7A2F-4547-82BA-985BF2CABE01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Device.Gpio", "System.Device.Gpio\System.Device.Gpio.csproj", "{68358886-9767-4D3F-A07F-C0C8AB6EFFBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mcp9808.Samples", "devices\Mcp9808\samples\Mcp9808.Samples.csproj", "{8CD00379-CC10-4FC5-92F4-D702A11FCEFF}"
@HakanL
HakanL / XboxWakeupSharp.cs
Created December 27, 2017 18:11
C# code for waking up Xbox on UWP
public static async Task XboxWake(IPAddress ipAddress, string liveId, int retries = 5)
{
using (var socket = new DatagramSocket())
{
var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
await socket.BindServiceNameAsync("", connectionProfile.NetworkAdapter);
using (var stream = await socket.GetOutputStreamAsync(new HostName(ipAddress.ToString()), "5050"))
{
using (var writer = new DataWriter(stream))
@HakanL
HakanL / Chunker.cs
Created January 12, 2016 22:09
Chunk/batch a list of items
using System;
using System.Collections.Generic;
using System.Linq;
public static class Extentions
{
public static List<List<T>> ChunkBy<T>(this ICollection<T> source, int chunkSize)
{
return source
.Select((x, i) => new { Index = i, Value = x })
@HakanL
HakanL / PropertyHelper.cs
Created April 19, 2017 22:49
Property setting for Data Model/Business Object transformations with dirty/modified tracking
using System;
using System.Linq.Expressions;
using System.Reflection;
namespace Haukcode.DataAccess.Util
{
internal static class PropertyHelper
{
public static void Set<T, TProp>(T target, Expression<Func<T, TProp>> memberLamda, TProp sourceValue, ref bool isDirty)
{
Start
01
--
Device descriptor:
Descriptor Length: 12
Descriptor type: 01
USB version: 0200
@HakanL
HakanL / ListMergerExample1.cs
Created January 12, 2016 22:12
Example of how to use the ListMergerUtils.cs
// Map answers
Util.MapImmutableOneToMany(
currentData: target.Answer,
newData: source.Answers,
equality: (a, b) => a.ExternalId == b.AnswerId,
insert: i =>
{
var newEntity = new DataModel.Answer();
TransformAnswer(newEntity, i);
target.Answer.Add(newEntity);
@HakanL
HakanL / ListMergerUtils.cs
Created January 12, 2016 22:11
Utils to merge lists, good to use when saving stuff into a database with child objects, etc
using System;
using System.Collections.Generic;
using System.Linq;
public static class Util
{
public static void MapManyToManyAssociation<T>(
ICollection<T> currentData,
ICollection<T> newData,
Func<T, T, bool> equality,