Skip to content

Instantly share code, notes, and snippets.

View Scribbio's full-sized avatar

Joe Di Trolio Scribbio

View GitHub Profile
@Scribbio
Scribbio / dabblet.css
Created June 12, 2020 11:24
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@Scribbio
Scribbio / ReadonlyBool.cshtml
Created March 3, 2020 13:43
Linking readonly to a dynamic boolean in Razor
@* We can link the readonly html attribute to a bool defined in Razor code.
This is a neat trick if you want to use the same view for different purposes.
For example, I have an AddProduct page that also acts as the EditProduct page. In "EditProduct" mode, some of the form fields that are
used to add a new product are no longer editable (such as the product name).
This is achieved using the html readonly attribute in the relevant fields set against a single boolean variable "@editMode".
This variable is defined at the top of the page and can be set multiple ways through the controller: ViewBag/ViewModel, etc.
@Scribbio
Scribbio / Test a successful database connection with entity framework
Last active January 16, 2020 16:23
TestEntityFrameworkDBConnection.cs
The following are functions to test whether an application can successfully connect to a database.
<Context> will correspond to the name of the context you wish to test.
// Simplest (EF6):
using System.Data.Common;
...
public bool TestConnection()
@Scribbio
Scribbio / BlazorTextSize.razor
Last active December 13, 2019 15:14
A Blazor component to dynamically increase or decrease a text size of text with CSS. This example controls the size of tags (special "topic" tags relating to a blog post) depending on a count associated with each tag relative to other tags in a collection.
@inject IExampleService ExampleService
<!-- Blog Post Tag Cloud -->
<div class="row">
<div class="col-lg-8 col-md-10 py-4 mx-auto text-center">
<h2 class="mb-4">Tag Cloud</h2>
@foreach (var item in TagCloudItems)
{
<a href="/search-tag/@item.Tag" class="@ResolveTagCloudCss(item, TagCloudItemsCount) mx-1">@item.Tag</a>
}
@Scribbio
Scribbio / LettertoNumber.cs
Last active November 20, 2019 13:53
Given a string, replace every letter with its position in the alphabet. Nothing for spaces.
return string.Join(" ", text.ToLower().Where(char.IsLetter).Select(x => x - 'a'+1));
@Scribbio
Scribbio / Even&OddArrays.cs
Created November 19, 2019 23:53
Separate an int array by odd and even numbers into two separate arrays
int[] myInts = new int[] {1, 3, 5};
// seperate odd and even numbers into two seperate arrays
int[] aEven = myInts.Where(num => (num & 1) == 0).ToArray();
int[] aOdd = myInts.Where(num => (num & 1) == 1).ToArray();
@Scribbio
Scribbio / PiFromX&Y
Created November 19, 2019 11:14
Approximate PI from xy coordinates in C#
using System;
class Pi {
/// Approximate pi from xy coordinates.
/// <returns>an approximation of pi</returns
public static double Approx(Point x, Point y)
{
Point point = new Point();
@Scribbio
Scribbio / .txt
Last active August 26, 2019 16:15
LOADING ASSETS FROM REFERENCED PROJECTS AND DLLs DYNAMICALLY
LOADING ASSETS FROM REFERENCED PROJECTS DYNAMICALLY
--CONTEXT-------------------------------------------------------------------------------------------------
For example, you have a winforms application and you reference other winform projects which deal
with specific sections of your application.
These sections are accessible through a single menu, in our example a listview (named LvAdministration)