Skip to content

Instantly share code, notes, and snippets.

View somapatrik's full-sized avatar

Patrik Šoma somapatrik

View GitHub Profile
@somapatrik
somapatrik / corona.py
Last active September 19, 2020 06:49
Získání podrobnějších dat z API Ministerstva zdravotnictví (nakažení v okrese)
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
@somapatrik
somapatrik / copyfile.cmd
Created December 4, 2020 14:44
Pre-Build Event to copy correct dll file to output directory. Everything must be without empty lines or errors will occur.
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 / dad.cs
Last active December 29, 2020 19:29
Basic drag & drop
// ------------------- Drag side -----------------------
// -----------------------------------------------------
Point StartPosition;
private void PLC_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point mousePos = e.GetPosition(null);
@somapatrik
somapatrik / gist:3bae93abf0ece3faf0b10fe29578dc74
Created January 17, 2021 08:46 — forked from hansmaad/gist:9187633
WPF Flat Combo Box Style
<!-- 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 / snmplistener.cs
Created April 29, 2021 13:42
SNMP listener
// 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
@somapatrik
somapatrik / MultipleTasks.cs
Last active November 11, 2021 10:33
Parallel execution of several tasks
// 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);
<!-- Example of conditional styling -->
<Label Grid.Row="2" Grid.Column="1" Text="{Binding Material.ITEM_STATE_FORMAT}" HorizontalOptions="Center" Style="{StaticResource detailText}">
<Label.Triggers>
<DataTrigger Binding="{Binding Material.State}" TargetType="Label" Value="B">
<Setter Property="Style" Value="{StaticResource detailText}" />
</DataTrigger>
<DataTrigger Binding="{Binding Material.State}" TargetType="Label" Value="N">
<Setter Property="Style" Value="{StaticResource detailTextError}" />
</DataTrigger>
</Label.Triggers>
<Color x:Key="Primary">#0b5ed7</Color>
<Color x:Key="GridBackground">#4F000000</Color>
<Color x:Key="NexenColor">#9d1c9d</Color>
<Color x:Key="SomaDarkDark">#22272e</Color>
<Color x:Key="SomaDarkLight">#434c57</Color>
<Color x:Key="GithubDark">#24292f</Color>
<Color x:Key="GithubLight">#f6f8fa</Color>
<Color x:Key="GithubRed">#cf222e</Color>
<Color x:Key="GithubGreen">#2da44e</Color>
@somapatrik
somapatrik / test.cs
Created September 26, 2023 07:06
Run WPF inside Forms
MyWpfProject.MainWindow mw = new MyWpfProject.MainWindow();
ElementHost.EnableModelessKeyboardInterop(mw);
mw.Show();
@somapatrik
somapatrik / PrimeViewModel.cs
Created November 20, 2023 10:15
ViewModel parent class
public class PrimeViewModel : INotifyPropertyChanged
{
protected bool SetProperty<T>(ref T backingStore, T value,
[CallerMemberName] string propertyName = "",
Action onChanged = null)
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
backingStore = value;