Skip to content

Instantly share code, notes, and snippets.

View MartinZikmund's full-sized avatar
⌨️
Coding

Martin Zikmund MartinZikmund

⌨️
Coding
View GitHub Profile
@MartinZikmund
MartinZikmund / ByteFinalVersion.cs
Created January 6, 2019 08:25
Final version of byte conversion
var result = (ushort)((data[position + 1] << 8) | data[position]);
@MartinZikmund
MartinZikmund / Singleton.cs
Created January 8, 2019 07:01
Singleton pattern for Unity3D
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
private static readonly Lazy<T> LazyInstance = new Lazy<T>(CreateSingleton);
public static T Instance => LazyInstance.Value;
private static T CreateSingleton()
{
var ownerObject = new GameObject($"{typeof(T).Name} (singleton)");
var instance = ownerObject.AddComponent<T>();
@MartinZikmund
MartinZikmund / ForArrayFill.cs
Last active January 11, 2019 10:19
Array fill with for loop
var prime = new bool[1000];
for ( int i = 0; i < isPrime.Length; i++ )
{
prime[i] = true;
}
@MartinZikmund
MartinZikmund / EnumerableArrayFill.cs
Last active January 8, 2019 16:01
Array fill with LINQ Enumerable
var prime = Enumerable.Repeat(true, 1000).ToArray();
@MartinZikmund
MartinZikmund / CoreArrayFill.cs
Created January 8, 2019 15:28
Array fill in .NET Core 2.0 and newer.
var data = new bool[1000];
Array.Fill(data, true);
@MartinZikmund
MartinZikmund / NetCoreArrayFillImpl.cs
Last active January 8, 2019 15:54
.NET Core Array.Fill implementation
public static void Fill<T>(T[] array, T value)
{
if (array == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
for (int i = 0; i < array.Length; i++)
{
array[i] = value;
@MartinZikmund
MartinZikmund / ArrayFillOverride.cs
Created January 8, 2019 15:57
Array.Fill override
public static void Fill<T> (T[] array, T value, int startIndex, int count);
@MartinZikmund
MartinZikmund / InvalidMigration.cs
Created January 21, 2019 16:33
Invalid migration - this is not really what we wanted...
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Cows");
migrationBuilder.DropPrimaryKey(
name: "PK_Horses",
table: "Horses");
migrationBuilder.DropColumn(
@MartinZikmund
MartinZikmund / BeforeTextChangingTextBox.xaml
Created January 22, 2019 22:16
Applying BeforeTextChanging to TextBox
<TextBox BeforeTextChanging="TextBox_OnBeforeTextChanging" />
@MartinZikmund
MartinZikmund / TextBoxBeforeTextChangingHandler.cs
Created January 22, 2019 22:18
Handling the TextBox BeforeTextChanging event
private void TextBox_OnBeforeTextChanging(TextBox sender,
TextBoxBeforeTextChangingEventArgs args)
{
args.Cancel = args.NewText.Any(c => !char.IsDigit(c));
}