Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrik Šoma somapatrik

View GitHub Profile
@somapatrik
somapatrik / MultipleTasks.cs
Last active Nov 11, 2021
Parallel execution of several tasks
View MultipleTasks.cs
// Create tasks, must use Task.Run() not new Task()
Task expireTask = Task.Run(()=> { ExpireCheck(); });
Task agingTask = Task.Run(() => { AgingCheck(); });
Task fifoTask = Task.Run(() => { FIFOCheck(); });
Task novalidTask = Task.Run(() => { NoValidCheck(); });
Task nolifeTask = Task.Run(() => { NoLifeCheck(); });
// Add them to list
List<Task> tasks = new List<Task>();
tasks.Add(expireTask);
@somapatrik
somapatrik / restclientget.cs
Created Jul 20, 2021
Xamarin REST API Client get async
View restclientget.cs
public static async Task<string> GetLastVersionDate()
{
string returnDate = "";
Uri uri = new Uri(apiUrl);
HttpResponseMessage responseMessage = await client.GetAsync(uri).ConfigureAwait(false); // avoids deadlock
if (responseMessage.IsSuccessStatusCode)
{
string content = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); // avoids deadlock
returnDate = JsonConvert.DeserializeObject<string>(content);
View snmplistener.cs
// Prototype server for SNMP
Socket socket;
EndPoint ep;
byte[] buffer;
ManualResetEvent manualevent = new ManualResetEvent(false);
private void btnListener_Click(object sender, RoutedEventArgs e)
{
// Construct a socket and bind it to the trap manager port 162
View gist:3bae93abf0ece3faf0b10fe29578dc74
<!-- Flat ComboBox -->
<SolidColorBrush x:Key="ComboBoxNormalBorderBrush" Color="#e3e9ef" />
<SolidColorBrush x:Key="ComboBoxNormalBackgroundBrush" Color="#fff" />
<SolidColorBrush x:Key="ComboBoxDisabledForegroundBrush" Color="#888" />
<SolidColorBrush x:Key="ComboBoxDisabledBackgroundBrush" Color="#eee" />
<SolidColorBrush x:Key="ComboBoxDisabledBorderBrush" Color="#888" />
<ControlTemplate TargetType="ToggleButton" x:Key="ComboBoxToggleButtonTemplate">
<Grid>
<Grid.ColumnDefinitions>
@somapatrik
somapatrik / dad.cs
Last active Dec 29, 2020
Basic drag & drop
View dad.cs
// ------------------- Drag side -----------------------
// -----------------------------------------------------
Point StartPosition;
private void PLC_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point mousePos = e.GetPosition(null);
@somapatrik
somapatrik / copyfile.cmd
Created Dec 4, 2020
Pre-Build Event to copy correct dll file to output directory. Everything must be without empty lines or errors will occur.
View copyfile.cmd
if $(PlatformName) == x86 (
echo "Copy dll for x86"
xcopy "$(ProjectDir)MyFolder\FolderForX86\mylib.dll" /Y
) else (
echo "Copy dll for x64"
xcopy "$(ProjectDir)MyFolder\FolderForX64\mylib.dll" /Y
)
@somapatrik
somapatrik / corona.py
Last active Sep 19, 2020
Získání podrobnějších dat z API Ministerstva zdravotnictví (nakažení v okrese)
View corona.py
import requests, json
import datetime
yesterday = datetime.date.today() - datetime.timedelta(days=1)
url = "https://onemocneni-aktualne.mzcr.cz/api/v1/covid-19/osoby.json"
data = json.loads(requests.get(url).content)
filterdata = [x for x in data["data"] if (
(x["OkresKodBydliste"] == "CZ0422") and #laud kod