Skip to content

Instantly share code, notes, and snippets.

View ntrpnr's full-sized avatar

Erik Nilsson ntrpnr

View GitHub Profile
@ntrpnr
ntrpnr / extras-partial.py
Last active October 27, 2022 08:49
Merge inpainting model (theta_0) with non-inpainting model (theta_1) - Auto1111
# Set inpainting model as model A
def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_name, interp_method, multiplier, save_as_half, custom_name):
def weighted_sum(theta0, theta1, alpha):
return ((1 - alpha) * theta0) + (alpha * theta1)
def get_difference(theta1, theta2):
return theta1 - theta2
def add_difference(theta0, theta1_2_diff, alpha):
@ntrpnr
ntrpnr / AzureTableStorage.cs
Last active March 2, 2022 12:07
Generic C# .NET Core class to perform CRUD against Azure Table Storage
public class AzureTableStorage<T> where T : ITableEntity, new()
{
private readonly CloudStorageAccount storageAccount;
private readonly CloudTableClient tableClient;
private readonly CloudTable table;
public AzureTableStorage(string connectionString, string tableName)
{
// Retrieve the storage account from the connection string.
storageAccount = CloudStorageAccount.Parse(connectionString);
@ntrpnr
ntrpnr / GameService.cs
Last active June 24, 2018 15:34
Example in C# .NET Core on how to use lock on a specific entity for async operations with SemaphoreSlim
public class GameService
{
// Lock cannot be used async. Instead we use Semaphores.
// We want to avoid race conditions for our game operations.
// With this approach we can make sure that only one operation is performed against a specific game at once.
//This dictionary contains a semaphore for each game's Id.
private readonly Dictionary<Guid, SemaphoreSlim> lockers = new Dictionary<Guid, SemaphoreSlim>();
private SemaphoreSlim GetLocker(Guid id)