Skip to content

Instantly share code, notes, and snippets.

View HakanL's full-sized avatar

Hakan Lindestaf HakanL

View GitHub Profile
@HakanL
HakanL / es_shrink.txt
Created August 20, 2024 13:25
Shrink an ElasticSearch Index
PUT /XXXXX/_settings
{
"settings": {
"index.blocks.write": true
}
}
POST /XXXXX/_split/XXXXX_split
{
"settings": {
@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>
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 / 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,
@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 / WhiteBlackOut.cs
Created December 29, 2015 23:13
White out/Black out functionality
public static System.Drawing.Color AdjustColor(System.Drawing.Color input)
{
var hsv = new HSV(input);
// Test values for white out and black out
double whiteOut = 0.5;
double blackOut = 0.5;
hsv.Saturation = hsv.Saturation + (HSV.White.Saturation - hsv.Saturation) * whiteOut;
hsv.Value = Math.Min(1.0, hsv.Value + whiteOut) * (1 - blackOut);