Skip to content

Instantly share code, notes, and snippets.

View euyuil's full-sized avatar
🎯
Focusing

Liu Yue euyuil

🎯
Focusing
View GitHub Profile
@euyuil
euyuil / MyUserControl.xaml.cs
Last active September 13, 2018 10:37
WPF: in custom UserControl, create custom DependencyProperty, where you can bind some value to.
public partial class MyUserControl : UserControl
{
// The dependency property definition.
public static readonly DependencyProperty MyStateProperty =
DependencyProperty.Register
(
"MyState", // Name of dependency property.
typeof(string), // Type of dependency property.
typeof(MyUserControl), // Type of the class who owns the dependency property.
new FrameworkPropertyMetadata
@euyuil
euyuil / StringUtils.cs
Last active October 21, 2016 10:22
C#: String named format parameters.
// Modified based on http://stackoverflow.com/questions/1322037/
public static class StringUtils
{
private static Regex FormatPattern =
new Regex(@"(\{+)([^\}]+)(\}+)", RegexOptions.Compiled);
public static string Format(this string pattern, object template)
{
if (template == null)
@euyuil
euyuil / disable-alt-drag.sh
Last active October 21, 2016 10:19
Gnome: Change the shortcut to move window from Alt-Drag to Super-Drag.
gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"
@euyuil
euyuil / MyUserControl.xaml
Last active January 3, 2016 10:39
WPF: in custom UserControl, expose its children's DependencyProperties.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:my="clr-namespace:MyProject"
x:Class="MyProject.MyUserControl"
mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="640"
>
@euyuil
euyuil / Update-Package-Reinstall.ps1
Created February 15, 2015 09:15
NuGet: reinstall all the packages
# If you want to reinstall the packages for a project
Update-Package -Reinstall -ProjectName Your.Project.Name
# If you want to reinstall the packages for a solution
Update-Package -Reinstall
@euyuil
euyuil / undo-last-commit.sh
Created November 30, 2014 10:36
Git: undo last commit
# 这个还能保留上一次的更改。
git reset --soft HEAD^
# 这个不能保留上一次的更改。
git reset --hard HEAD^
@euyuil
euyuil / MountIso.ps1
Created September 16, 2014 01:01
Windows: mount ISO through PowerShell
Mount-DiskImage -ImagePath X:\cn_windows_server_2012_r2_with_update_x64_dvd_4048415.iso
# Note that ImagePath must be absolute path.
@euyuil
euyuil / AutoAttach.ps1
Last active August 29, 2015 14:06
Storage Spaces: automatically attach virtual disk in PowerShell
Set-VirtualDisk -FriendlyName "September Disk" -IsManualAttach 0
@euyuil
euyuil / RichTypeTableEntity.cs
Created September 8, 2014 04:31
Azure: support more types in azure table entities.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
/// <summary>
/// The table entities that extend from this type will have rich support in property types.
/// </summary>
@euyuil
euyuil / Guard.cs
Created July 4, 2014 08:13
C#: check null arguments in an elegant way
// Copied from:
// http://www.minddriven.de/index.php/technology/dot-net/c-sharp/efficient-expression-values
public static class Guard
{
public static void AssertNotNull<T>(Expression<Func<T>> selector)
{
var memberSelector = (MemberExpression)selector.Body;
var constantSelector = (ConstantExpression)memberSelector.Expression;
var value = ((FieldInfo)memberSelector.Member).GetValue(constantSelector.Value);