Skip to content

Instantly share code, notes, and snippets.

View ncarandini's full-sized avatar

Nicolò Carandini ncarandini

View GitHub Profile
@ncarandini
ncarandini / HueColorDemo.linq
Last active November 26, 2018 15:38
[Meadow mocked pseudocode] Cycle hue on onboardLed
// Copyright(c) 2018 Nicolò Carandini (aka TPCWare)
// Content
// ======================================================================================================
// This "not for production code" is just an example on how to run an async task that can be cancelled.
// Moreover, in this example there is an implementation of HSL to RGB color conversion.
// Build and test
// =========================================================================================================
// Run it on LinqPad (https://www.linqpad.net/) or use the code to create a Console app on Visual Studio.
// Hi Francesco,
// here is my code... :-)
@ncarandini
ncarandini / gist:a901564a1944bb07e680c43205254911
Last active January 2, 2020 22:59
Random list from a list
void Main()
{
// Deve essere compreso tra 1 e il numero di quitz
const int numOfQuitzzes = 3;
// Chiamo il servizio che mi genera la lista di quitz
List<string> RandomQuitzList = QuitzService.GetQuitzList(numOfQuitzzes);
// Mostro il risultato
for(int i = 0; i < numOfQuitzzes; i++)
@ncarandini
ncarandini / Main.cs
Created March 29, 2020 18:57
Solve the Giorgio Di Nardo quiz
void Main()
{
List<Item> items = new List<UserQuery.Item>
{
new Item { Id = 1, Nome = "Giorgio" },
new Item { Id = 1, Nome = "Luca" },
new Item { Id = 1, Nome = "Marco" },
new Item { Id = 1, Nome = "Nicolò" }
};
@ncarandini
ncarandini / EditItem.razor
Last active February 17, 2022 07:21
[Blazor] Using IValidatableObject for form validation
<EditForm Model="@Item" OnValidSubmit="@(e => OnSave.InvokeAsync(Item))">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="form-group">
<label for="Title">Name:</label>
<InputText id="Title" @bind-Value="Item.name" class="form-control" />
</div>
<div class="form-group">
@ncarandini
ncarandini / EditTicket.razor
Last active April 7, 2020 14:30
Use a string property to edit decimal value
@page "/EditTicket"
@using System.Globalization
<h3>Edit Ticket # @Ticket.Id</h3>
<EditForm Model="Ticket" OnSubmit="Save">
<InputText @bind-Value="Ticket.Title" />
@ncarandini
ncarandini / mypage.razor
Last active April 9, 2020 23:39
A double for cycle to solve
@page "/MyPage"
<h3>Show images</h3>
@for (int i = 0; i < LabImages.Count; i += imagesPerRow)
{
<div class="card-deck">
@for(int j = i; j < i + imagesPerRow && j < LabImages.Count; j++)
{
<div class="card">
@ncarandini
ncarandini / Workaround.cs
Created April 29, 2020 11:48
Google Maps workaround
try
{
var hasFixedGoogleBug154855417 = GetSharedPreferences("google_bug_154855417", global::Android.Content.FileCreationMode.Private);
if (!hasFixedGoogleBug154855417.Contains("fixed"))
{
var corruptedZoomTables = new Java.IO.File(this.ApplicationContext.FilesDir, "ZoomTables.data");
var corruptedSavedClientParameters = new Java.IO.File(this.ApplicationContext.FilesDir, "SavedClientParameters.data.cs");
var corruptedClientParametersData =
new Java.IO.File(
this.ApplicationContext.FilesDir,
@ncarandini
ncarandini / AllMustBeTrueMultiConverter,cs
Created June 11, 2020 20:12
AllMustBeTrueMultiConverter,cs
using System;
using System.Globalization;
using Xamarin.Forms;
namespace App2
{
class AllMustBeTrueMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{