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 / 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);
@euyuil
euyuil / findstr.cmd
Created July 3, 2014 06:17
Cmd: find string in files
findstr /s /i /m "stringToFind" *
@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 / home.html
Created April 1, 2014 05:11
CSS: fixed-width sidebar with fluid-width content container.
<div id="content-wrapper">
<div id="content">
<!-- blah blah blah -->
</div>
</div>
<div id="sidebar">
<ul>
<!-- blah blah blah -->
</ul>
@euyuil
euyuil / EventTest.cs
Created February 25, 2014 02:54
C#: event polymorphism test. Avoid 'overriding' events of parent class.
namespace EventTest
{
using System;
class Parent
{
public event Action Event;
public virtual void DoEvent()
{
@euyuil
euyuil / 395A.cpp
Created February 21, 2014 03:19
Codeforces 395A: Skis. 2-Sum problem. 1 solution for both 395A1 and 395A2. (http://codeforces.com/problemset/problem/395/A1, http://codeforces.com/problemset/problem/395/A2)
// 395A1 & 395A2 - Skis
// http://codeforces.com/problemset/problem/395/A1
// http://codeforces.com/problemset/problem/395/A2
#include <cstdlib>
#include <iostream>
#include <algorithm>
const int N = 1111111;