Skip to content

Instantly share code, notes, and snippets.

View SoulFireMage's full-sized avatar

Richard Griffiths SoulFireMage

View GitHub Profile
@SoulFireMage
SoulFireMage / BmpToSQL.py
Last active February 16, 2024 16:51
Ascii Art in SQL!
#how to make a silly image like thing for use in datagrids like DevExpress. Friday snap special
from PIL import Image
image = Image.open('C:\Downloadstmp\LeftAktarian75 - Copy.bmp').convert('L') # Convert to grayscale
image = image.resize((64, 64))
# Threshold value to distinguish between '1' and ' '
threshold = 128
@SoulFireMage
SoulFireMage / Octonion.cs
Created May 27, 2023 07:50
Octonions - A GPT 4 built implmentation
///In an effort to get some kind of intuition around what an octonion even is - I'm not a mathematician! - I asked GPT4 for help.
///During this conversation it gave me the outline of an octonion in C#. Running with this, I prompted for the main operations and built
///this up, sparked by the fact there wasn't an implementation out there (according to GPT4 - which probably is not true).
///Still, posting this up for my future reference as I'm interested in the notion of using such in a neural network
///Though I'm more likely to review abstracts of others who have actually code such CNNs already! :)
public struct Octonion
{
public double w, x, y, z, u, v, t, s; // the eight components of the octonion
@SoulFireMage
SoulFireMage / ExamStore Python Example 2
Last active May 7, 2023 13:49
Python TKInter Forms Data Saving DATABASE version
import tkinter as tk
# Define the UserExamStore class
class UserExamStore:
def __init__(self, id, name, date, exams=None, languages=None, formats=None):
self.id = id
self.name = name
self.date = date
self.exams = exams if exams is not None else set()
self.languages = languages if languages is not None else set()
@SoulFireMage
SoulFireMage / ExamStore Python Example 1
Created May 7, 2023 11:37
Showing how to use simple OOP with TK to build a list of objects populated by a second form.
import tkinter as tk
# Define the UserExamStore class
class UserExamStore:
def __init__(self, id, name, date):
self.id = id
self.name = name
self.date = date
self.exams = []
self.languages = []
@SoulFireMage
SoulFireMage / MarkovOne.cs
Last active April 13, 2023 13:56
Tensor flow to output 1
This code generates a sequence of random numbers and applies a transformation to each number,
such that the probability of the number being transformed to 1 increases as the sequence progresses.
This is done using a Markov chain with a transition matrix that depends on the sequence index.
```csharp
// Install TensorFlow.NET NuGet package
#load "nuget: TensorFlow.NET, 0.11.0"
using System;
using System.Collections.Generic;
@SoulFireMage
SoulFireMage / Bulk insert VB
Last active June 13, 2022 19:28
Chunk data into 2k chunks and update in Sql.
'''This code just saved 6700 mergecodes across to the db in a few second compared to long minutes via EF :)
Public Shared Sub SaveMany(Items As List(Of BranchContact))
If Items Is Nothing Then Return
Using db As New LogIQEntities
Dim chunkedItems = ChunkData(Items, 500) 'I've not tested to see the upper/lower bounds of benefits/deficits on this figure :P
For Each chunkedList In chunkedItems
Dim Query = New StringBuilder
For Each i In chunkedList
Query.Append($"update BranchContacts set Mergecodes = '{i.Mergecodes}' where Emailid = {i.Emailid} and Branch = '{i.Branch}';")
Next
@SoulFireMage
SoulFireMage / BaseClass.cs
Created February 28, 2018 10:44
Generic Save for our Reverse Poco TT file
public interface ICrud //Used to allow the texttemplate in the Model Layer to work. Needs a revisit.
{
int Id { get; set; }
}
public abstract class BaseModel : INotifyPropertyChanged
{
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Equals(storage, value))
@SoulFireMage
SoulFireMage / EF.Reverse.POCO.COre.ttinclude
Last active July 4, 2018 10:24
TT.Include for ReversePoco generator with NotifyPropertyChanged setup
<#@ include file="EF.Reverse.POCO.Core.ttinclude" #>
<#
// v2.35.0
// Please make changes to the settings below.
// All you have to do is save this file, and the output file(s) is/are generated. Compiling does not regenerate the file(s).
// A course for this generator is available on Pluralsight at https://www.pluralsight.com/courses/code-first-entity-framework-legacy-databases
// Main settings **********************************************************************************************************************
Settings.ConnectionStringName = "RedDiamondConnectionString"; // Searches for this connection string in config files listed below in the ConfigFilenameSearchOrder setting
// ConnectionStringName is the only required setting.
@SoulFireMage
SoulFireMage / YourDBContext.tt
Last active June 14, 2018 02:22
Reverse Poco TT file for including private backing fields
<#@ include file="EF.Reverse.POCO.Core.ttinclude" #>
<#
//*** Line 402 - 407 Marked //*** for the Private field code mods. Also included are the common static methods we add (379 - 385)
//*** Please note the Interface ICrud is merely for the static methods ( is just int Id { get; set; } )
//*** Appropriate Baseclass and (if wanted) Generic Save is in another gist.
// v2.35.0
// Please make changes to the settings below.
// All you have to do is save this file, and the output file(s) is/are generated. Compiling does not regenerate the file(s).
// A course for this generator is available on Pluralsight at https://www.pluralsight.com/courses/code-first-entity-framework-legacy-databases
@SoulFireMage
SoulFireMage / T4 Model Generator
Created January 15, 2018 17:35
T4 Model Generator (Use with Datalayer.dll!)
For the model layer I use Automapper (for use in MVC Projects) so this file will need you to have successfully compiled a datalayer DLL and make it available.
It will add attributes that it finds from the Datalayer file (these were inserted via the custom Datalayer T4 file).
I had plenty of fun with reflection to make this work, but it does make adding new tables quite trivial!
<#@ template debug="true" hostspecific="true" language="C#"#>
<#@ output extension=".cs"#>
<#@ assembly name="System.Core"#>