Skip to content

Instantly share code, notes, and snippets.

@papinko
papinko / syno-vpn-keepalive.sh
Created September 19, 2024 10:59 — forked from hannesbe/syno-vpn-keepalive.sh
Script to keep VPN alive on Synology DSM. Checks if IP is pingable and if not: disconnect VPN, reconnect VPN & add routes
# syno-vpn-keepalive.sh
# ---
# Script to keep VPN alive on Synology DSM.
# Checks if IP is pingable and if not:
# disconnect VPN, reconnect VPN & add routes
# ---
# Modify vars:
# - CHECKIP: IP to check to be pingable before reconnecting VPN
# - NAME (Synology VPN name),
# - ID (Synology VPN ID), SSH to NAS & run this to find ID
@papinko
papinko / CustomUserControlView.cs
Created September 10, 2024 04:57
Custom DependencyProperty with RaisePropertyChanged-Event
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
public partial class CustomUserControlView : UserControl, INotifyPropertyChanged
{
public CustomUserControlView()
{
InitializeComponent();
}
@papinko
papinko / RelayCommand.cs
Created September 10, 2024 04:44
The benefit of using relay command is that you can bind commands directly to the ViewModels.
using System;
using System.Windows.Input;
public class RelayCommand : ICommand
{
private Action<object> _execute;
private Func<object, bool> _canExecute;
public event EventHandler CanExecuteChanged
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
public abstract class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(ref Win32Point pt);
[StructLayout(LayoutKind.Sequential)]
struct Win32Point
{
public Int32 X;
public Int32 Y;
};
public sealed class EditableProperty<T> : EditablePropertyBase<T> where T : IComparable
{
protected override Dictionary<Func<bool>, T> ValidationRules { get; } = new Dictionary<Func<bool>, T>();
public EditableProperty()
: base(default(T))
{
}
public EditableProperty(T value)