Skip to content

Instantly share code, notes, and snippets.

@idkaaa
idkaaa / PersonListDialog.cs
Last active August 22, 2023 01:11
Example of Updating UI Asynchronously with Winforms in C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
public async Task DoWork()
{
int res = await Task.FromResult<int>(GetSum(4, 5));
}
private int GetSum(int a, int b)
{
return a + b;
}
public async Task DoWork()
{
//blocking
//int res = await Task.FromResult<int>(GetSum(4, 5));
//non-blocking
int res = await Task<int>.Run(() => GetSum(4, 5));
}
private int GetSum(int a, int b)
@idkaaa
idkaaa / AddPermissionAuthenticatedUsersCreateDb.cs
Created November 21, 2016 21:57
Elevates process using UAC
/// <summary>
/// Adds Create Database permission for the built-in Windows Authenticated Users group if it can.
/// </summary>
public static void AddPermissionAuthenticatedUsersCreateDb(string Server)
{
Log.Trace($"Trying to add create database permission for authenticated users group on server: {Server}");
string SqlcmdLogFile = @"${specialfolder:CommonApplicationData}\" +
Application.CompanyName + @"\" +
Application.ProductName + @"\" +
@"Data\SqlCmd.log";
@idkaaa
idkaaa / Aforge.VFW.CodecOptionsSerializerDeserializer
Created December 2, 2016 01:20
C# Serializer/Deserializer of codec options AVISaveOptions method.
///All of this borrowed from: https://msdn.microsoft.com/en-us/magazine/hh580739.aspx
/// <summary>
/// Writes codec options from codec configuration dialog to a file.
/// </summary>
private static void WriteAviSaveOptions(string FileName, ref AVICOMPRESSOPTIONS Options)
{
using (BinaryWriter Writer = new BinaryWriter(
File.Open(FileName, FileMode.Create)))
{
@idkaaa
idkaaa / MaximizationProblemDiscrete.py
Created September 27, 2017 17:25
Simple python program to find the maximum value for discrete integers
import math
import numpy as np
def OptimizedFunction(x):
return (math.pow((x%6), 2) % (7-math.sin(x)))
MaxValue = 0
MaxIndex = 0
for i in range(1,101):
print("i = " + str(i))
@idkaaa
idkaaa / restart-jira.ps1
Last active February 5, 2018 16:35
A powershell script that forces jira service off and then on again.
$thisDirectory = "C:\JIRA";
$logPath = "$thisDirectory\restartLog.log";
Function LogWrite
{
Param ([string]$logString)
$dateString = "$(Get-Date -Format u)";
$outputString = "$dateString $logString";
Write-Host $outputString;
Add-content $logPath -value $outputString;
}
@idkaaa
idkaaa / plantuml-playground.iuml
Created May 23, 2021 22:31
Playground for PlantUML markdown
@startuml
class FirstClass {
}
@enduml
Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Tee-Object -Variable DefaultRoute
$DefaultRoute