Skip to content

Instantly share code, notes, and snippets.

View lordofscripts's full-sized avatar

Lord of Scripts ™ lordofscripts

View GitHub Profile
@lordofscripts
lordofscripts / LayoutOptions.cs
Created May 16, 2017 19:28
How to control Layout features in ASP.NET MVC
/// <summary>
/// Application features that need rendering control at Layout level (used in ~/Shared/_Layout.cshtml
/// </summary>
public class LayoutOptions
{
/// <summary>
/// get/set whether Layout will render Google Map support features
/// </summary>
public bool HasMap { get; set; }
/// <summary>
@lordofscripts
lordofscripts / AnyPersonModel.cs
Created September 14, 2017 18:41
Using Data Annotations to configure WinForm controls as per the constraint set in the model
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace LordOfScripts.Gists.Windows.Forms.Models
{
// This is your entity model, not necessarily for Entity Framework
public class AnyPersonModel
{
@lordofscripts
lordofscripts / uniqueRandomNumbers.go
Created December 1, 2023 16:12
Generates a list of unique random numbers but gives the freedom to use a reproduceable list (using math/rand) or a truly random list.
/* -----------------------------------------------------------------
* L o r d O f S c r i p t s (tm)
* Copyright (C)2023 Lord of Scripts
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Creates Unique Random Numbers
*-----------------------------------------------------------------*/
import (
crand "crypto/rand" // Not reproduceable. For sensitive apps
"fmt"
"math/big"
@lordofscripts
lordofscripts / buttonPatternOnOff.go
Created December 14, 2023 17:54
A proper GUI pattern for Enable/Disable in Go Fyne
// Go's Fyne GUI framework has some not-so-fine ways of making simple things more difficult than they should.
// The problem lies in the OnTapped events that are declared for widgets such as Buttons. These, unlike .NET
// have no way of determining the source/owner of the event because these functions have no parameters to
// acomplish that.
// As a use case, imagine a Go Fyne form with Enable & Disable buttons that operate on other widgets. How
// would you go about disabling the button once it has been tapped (proper GUI behavior)?
// 1. Declare the Button instances. Chicken & Egg problem, at this point we don't have an object instance to
// use in the OnTapped callback to reconfigure the buttons.
btnDisable := widget.NewButton("Disable", nil)