Case

3,821 次浏览

Quick Tips: Open CMD here | 在当前位置打开命令行

We can right-click the mouse with Shift key to find the "Open command here" or "Open PowerShell window here" item to open the command line at current location.

But we often need to run the command line as an administrator, so you could register the following value to Windows Register to add a new item "Open command (as Admin) here" to Windows Explorer right-click menu.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
"Icon"="c:\\windows\\system32\\cmd.exe"
"MUIVerb"="Open command (as Admin) here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\folder\shell\runas]
"Icon"="c:\\windows\\system32\\cmd.exe"
"MUIVerb"="Open command (as Admin) here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\folder\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

Open the Notepad and paste the text of above, save the file as OpenCMDHere.reg, and then double click this file, and click the "Yes" button in the message box.

The meaning of the above code is that we will create a new Windows shell item called "runas" at folder and the empty space in a folder, and set the Icon and propmt text.

HKEY_CLASSES_ROOT\Directory\shell, the context menu when you right-click on a folder
HKEY_CLASSES_ROOT\Directory\background, the context menu when you right-click on the "background" empty space while in a folder 

Then to define the running command of "runas" item:

cmd.exe /s /k pushd \"%V\"

That means to run the cmd.exe at the current working folder, the /k carries out the command specified by the following string so it executes the command pushd %V and since the only argument pushd accepts is a path it follows that %V a variable delivered by explorer that contains the path of the folder right clicked.

See more:
cmd command, https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490880(v%3dtechnet.10)
Pushd command, https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490978(v=technet.10)


我们可以在 Windows 的任意位置,通过 按下 Shift + 鼠标右键,来在当前位置启动 CMD 或 PowerShell。

但是,我们经常需要以管理员身份取运行 CMD,所以我们可以通过加载上述的值到注册表,来为右键菜单添加一个新的选项。将上述值保存到一个记事本中,并保存为 .reg 文件,然后双击运行,在后续提示中都选择 是,即可。

2,754 次浏览

SQL Server 下 K-V 形式存储 1亿条 数据对于查询效率的影响

这是一篇2年多以前带过的实习生 Peflapos 所整理的小文,拿出来缅怀下,也希望他在新的公司一切顺利。


对1亿条 K-V 型记录查询效率的验证

关于 K-V 型存储

1. 为什么考虑 K-V 存储形式?

假设有一个 Request 类如下:

	public class Request
	{
		public Guid RequestId {get; set;};
		public string RequestName {get; set;};
		public string RequestOwner {get; set;};
	}
	

我们可以按照如下的结构把它存入数据库:

Continue reading

2,486 次浏览

JavaScript: 注册粘贴事件,将剪切板中的内容去除HTML标签,并粘贴到光标位置

$("#Subject").bind('paste', function (e) {
        var pasteData = "";
        if (e.originalEvent.clipboardData) {
            pasteData = e.originalEvent.clipboardData.getData('text');
        } else {
            // for IE
            pasteData = window.clipboardData.getData("Text");
        }
        var self = this;

        // 在等待一段时间后,在当前光标位置,粘贴处理后的文本
        setTimeout(function () {
            var selection = document.getSelection();
            var cursorPos = selection.anchorOffset;
            var oldContent = selection.anchorNode.nodeValue;
        // 通过 Jquery的text() 去除所有样式
            var toInsert = $("<div>" + pasteData + "</div>").text();
            var newContent = oldContent.substring(0, cursorPos) + toInsert + oldContent.substring(cursorPos);
            selection.anchorNode.nodeValue = newContent;            
        }, 200);
        return false;
    });

1,512 次浏览
45,741 次浏览

通过 Excel 使用 VBA 计算协方差

作为一名执著的 C# 程序员,当一位学经济的老友从国外找来,让我帮他写完 VBA 作业的时候,一开始,其实我是拒绝的。
各路VB大神,不要嘲笑在下啊,我可是足足用了一个小时才在 Excel 里到了编写 VB 代码的地方 (默认 Office 2013 的那个开发者选项是隐藏的…)
我把一夜写的代码在这里Mark一下,万一以后再有类似的VB任务也不至于抓瞎,哈哈,我是一晚上没睡觉活活憋出来的,以下代码在Excel里计算协方差。
不过话说话来,感觉各种语言都是相同的,学会一种,换成另一种也不会太恐怖。

下载这个 Excel VBA 文件:Spreadsheeting assi
Continue reading

1,372 次浏览
3,051 次浏览

C#: 一个方法执行超时 timeout 检查的实现

我们经常有这样的需求:如果一个方法的执行,超过了一个设定时间(timeout)就需要立即返回不再继续,这里我利用 C# 异步委托的 AsyncWaitHandle 来尽量简便的实现这一需求。

具体实现如下。注意,这里需要被调用的方法遵守 delegate TR TimeOutDelegate(T param); 形式的方法签名,如有其他需要,可以自行定制也很方便。

namespace TimeOutHelper
{
    #region using directives

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Threading;

    #endregion using directives

    internal class Program
    {
        public delegate TR TimeOutDelegate<in T, out TR>(T param);

        private static void Main()
        {
            Dictionary<Guid, string> result;
            Console.WriteLine(TimeoutFunction.Execute(Test, "Hello, World!", out result, TimeSpan.FromSeconds(3)));
            Console.WriteLine("Hello, World!");
            Console.ReadKey();
        }

        public static Dictionary<Guid, string> Test(string sourceString)
        {
            var result = sourceString.ToDictionary(
                character => Guid.NewGuid(),
                character => character.ToString(CultureInfo.InvariantCulture));
            Thread.Sleep(4000);
            return result;
        }

        public static class TimeoutFunction
        {
            /// <summary>
            ///     Execute a method with timeout check
            /// </summary>
            /// <typeparam name="T">Target method parameter type</typeparam>
            /// <typeparam name="TR">The result type of execution</typeparam>
            /// <param name="timeoutMethod">Target method</param>
            /// <param name="param">Target method parameter</param>
            /// <param name="result">The result of execution</param>
            /// <param name="timeout">Set timeout length</param>
            /// <returns>Is timeout</returns>
            public static Boolean Execute<T, TR>(
                TimeOutDelegate<T, TR> timeoutMethod, T param, out TR result, TimeSpan timeout)
            {
                var asyncResult = timeoutMethod.BeginInvoke(param, null, null);
                if (!asyncResult.AsyncWaitHandle.WaitOne(timeout, false))
                {
                    result = default(TR);
                    return true;
                }
                result = timeoutMethod.EndInvoke(asyncResult);
                return false;
            }
        }
    }
}
1,413 次浏览

IE 无法正常打开,刚启动就关闭

如果你的电脑出现了 IE 无法正常启动,总是刚一点击就自动关闭的情形。那么你可以通过以下步骤进行修改,开始 -> 运行 -> regedit ,进入注册表,在其中找到:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer

的 Main 主键,右键单击Main主键,选择“权限”,在弹出的权限设置对话框里点“高级”按钮,在高级窗口里点击下面的“启用继承”按钮,即可。