Emacs: how to disable ‘file changed on disk’ checking?


Emacs is really trying to help you here. Read the info page on Protection against Simultaneous Editing.

But, if you still want to avoid that message/prompt, you can redefine the function that is doing the prompting:

(defun ask-user-about-supersession-threat (fn)
  "blatantly ignore files that changed on disk"
(defun ask-user-about-lock (file opponent)
  "always grab lock"

The second function there is for when two people are using Emacs to edit the same file, and would provide a similar prompt (but not the one you seemed to refer to in the question).

I’d advise against overriding the two routines, but it’s there if you want.

On the off chance global-auto-revert-mode is on, you could disable that. Add this to your .emacs:

(global-auto-revert-mode -1)

You can tell if the mode is on by looking at the variable of the same name:

C-h v global-auto-revert-mode RET

If the value is t, then the mode is on, otherwise it is off.


Changing highlight line color in emacs


That would be an easy fix if you customize your init file (~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el)

Turn on hl-line:

(global-hl-line-mode 1)

Set any color as the background face of the current line:

(set-face-background 'hl-line "#3e4446")

To keep syntax highlighting in the current line:

(set-face-foreground 'highlight nil)

How can I open a command prompt in current folder with a keyboard shortcut?


Use this keyboard shortcut: Shift + Menu, W, Enter

  1. Shift + Menu (alternatively, Shift + F10), (opens extended right-click menu in current folder)
  2. W (selects “Open Command Window Here”),
  3. Enter (activates selection; required since “New” is also selectable with W)

The Menu key refers to the special key introduced by Microsoft, usually to the right of the right Winkey.

This shortcut is available on a default installation of Windows (7) without any 3rd party software.

The AHK way. You just need to press Win + C (or whatever you want to define it as.):

SetTitleMatchMode RegEx

; Stuff to do when Windows Explorer is open
#IfWinActive ahk_class ExploreWClass|CabinetWClass

    ; create new text file
    #t::Send !fwt

    ; open 'cmd' in the current directory

; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
    ; This is required to get the full path of the file from the address bar
    WinGetText, full_path, A

    ; Split on newline (`n)
    StringSplit, word_array, full_path, `n

    ; Find and take the element from the array that contains address
    Loop, %word_array0%
        IfInString, word_array%A_Index%, Address
            full_path := word_array%A_Index%

    ; strip to bare address
    full_path := RegExReplace(full_path, "^Address: ", "")

    ; Just in case - remove all carriage returns (`r)
    StringReplace, full_path, full_path, `r, , all

    IfInString full_path, \
        Run,  cmd /K cd /D "%full_path%"
        Run, cmd /K cd /D "C:\ "

As a bonus, the script above also creates a new text file with this shortcut: Win + T

Credit to: Eli Bendersky

shareimprove this answer

Running a SQL Stored Procedure from Excel (No VBA)


Today’s author is Mike Alexander, an Excel MVP who shows us how to run a Stored Procedure to get data from a SQL server. For more useful articles and videos, visit www.datapigtechnologies.com

We all know we can use MS Query to get data from a SQL server. Typically though, we pull from a Table or a View. Well in some organizations, the IT department wants all interaction with the server to be done through Stored Procedure. This adds a level of risk management and makes the DBAs feel better.

So today, I’ll show you how to easily make Excel run a Stored Procedure to get data.

Step 1: Data tab – > From Other Sources -> From SQL Server 


Step 2: Enter Credentials. Your server name can be an IP address 

Step 3: Choose any old table or view. Pick a small one because we’ll discard it later anyway.


Step 4: Excel will pop up the Import Data dialog box. Click Properties here (NOT THE OK BUTTON).


Step 5: Click on the Definition tab. There, change Command Type to SQL, and then enter your Stored Procedure name in the Command Text input. 

Step 6: Excel complains about something….blah…blah…blah. Click Yes – (as in yes I know what I’m doing). 

Step 7: Excel will activate the Import Data dialog box again. This time click OK to fire the Stored Procedure and return the results.


Step 8: Marvel at your results



  • Excel will fire the Stored Procedure each time you “Refresh”
  • If you have to pass a parameter, you can enter it in the command text like this:


  • If you have to pass dynamic parameters you’ll have to turn to VBA. I’ll do a post on this later this week.
  • I assume you can do this with ORACLE databases too.
  • I’ve yet to test whether this will fire a Stored Procedure that doesn’t return data. In other words, Stored Procedures that perform Insert, Update or Delete actions. I assume that if you can, there is the possibility of updating SQL from Excel through a simple connection. Pretty cool. 

Left join and Left outer join in SQL Server


What is the difference between left join and left outer join?


As per the documentation: FROM (Transact-SQL):

<join_type> ::= 
    [ { INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } } [ <join_hint> ] ]

The keyword OUTER is marked as optional (enclosed in square brackets), and what this means in this case is that whether you specify it or not makes no difference. Note that while the other elements of the join clause is also marked as optional, leaving them out will of course make a difference.

For instance, the entire type-part of the JOIN clause is optional, in which case the default is INNER if you just specify JOIN. In other words, this is legal:


Here’s a list of equivalent syntaxes:


Also take a look at the answer I left on this other SO question: SQL left join vs multiple tables on FROM line?.

enter image description here


Using Roslyn to build a simple C# interactive script engine


The .NET Compiler Platform (a.k.a. Roslyn) version 1.0-rc2 was recently released and got go-live license which means the API’s are to be considered fairly stable. In this post I’ll demonstrate how to build a simple C# interactive scripting* editor using the Scripting API (like the F# interactive window which been around in Visual Studio since…like forever). The idea is to be able to evaluate some code in a REPL but also have the possibility to submit code to it from an editor. Let’s start building the core component of the application and then put on a nice GUI on top of it.

The simple script engine looks like this:

public class CSharpScriptEngine
    private static Script _previousInput;
    private static Lazy&lt;object&gt; _nextInputState = new Lazy&lt;object&gt;();
    public static object Execute(string code)
        var script = CSharpScript.Create(code, ScriptOptions.Default).WithPrevious(_previousInput);
        var endState = script.Run(_nextInputState.Value);
        _previousInput = endState.Script;
        _nextInputState = new Lazy&lt;object&gt;(() =&gt; endState);
        return endState.ReturnValue;

The Execute method uses the CSharpScript.Create method to build a script from the the previously submitted code with the current submitted one.
With this in place we can try out the script engine:

class Program
    static void Main(string[] args)
            //This could be code submitted from the editor
            public class ScriptedClass
                public String HelloWorld {get;set;}
                public ScriptedClass()
                    HelloWorld = ""Hello Roslyn!"";
        //And this from the REPL
        Console.WriteLine(CSharpScriptEngine.Execute("new ScriptedClass().HelloWorld"));
//Output: "Hello Roslyn!"

Let’s now put a simple editor and a REPL on top of the script engine. The REPL will be a self-hosted Web API console application to which the user can submit code from the editor but also write expressions in the command prompt. The setup of the REPL project is fairly straight-forward and I will only show the interesting parts for brevity (no error handling etc). The Main function sets up the Web API part and then listen for input from the user while the Post method in the controller listens for submitted code from the editor:

static void Main(string[] args)
    string baseAddress = "http://localhost:9000/"; 
    // Start OWIN host 
    using (WebApp.Start&lt;Startup&gt;(url: baseAddress))
        while (true)
            var str = Console.ReadLine();

public class CodeController : ApiController
    // POST api/code 
    public void Post([FromBody]string code)

The code editor in this case is a simple Windows Form application with a multiline text box as the editor window.
When the user has written a script she selects it and presses Alt + Enter and the code is submitted to the REPL application:

private void CodeEdit_KeyDown(object sender, KeyEventArgs e)
    if (CodeEdit.SelectedText.Length &gt; 0 &amp;&amp; e.KeyCode == Keys.Enter &amp;&amp; e.Alt)
        string baseAddress = "http://localhost:9000/";
        using (var client = new HttpClient())
            var response = client.PostAsJsonAsync(baseAddress + "api/code", CodeEdit.SelectedText).Result;

The code editor can now be used to run the scripts as shown above:


Roslyn makes it really easy to build tools around C#/VB.NET. In this post I have shown how you, with just a few lines of code, can build an interactive C# script application.
The complete application code is available here.
Learn more about Roslyn on its Github repo.

* The scripting API’s are not yet available in the v1.0-rc2 “Go-Live” release and aren’t available on NuGet. They can however be fetched from the Rosyln myget feed

How can I call (Iron)Python code from a C# app?


The process is simple, especially in a C#/.NET 4 application where support for dynamic languages have been improved via usage of the dynamic type. But it all ultimately depends on how you intend to use the (Iron)Python code within your application. You could always run ipy.exe as a separate process and pass your source files in so they may be executed. But you probably wanted to hostthem in your C# application. That leaves you with many options.

  1. Add a reference to the IronPython.dll and Microsoft.Scripting.dll assemblies. You’ll usually find them both in your root IronPython installation directory.
  2. Add using IronPython.Hosting; to the top of your source and create an instance of the IronPython scripting engine using Python.CreateEngine().
  3. You have a couple of options from here but basically you’d create a ScriptScope or ScriptSource and store it as a dynamic variable. This allows you to execute it or manipulate the scopes from C# if you choose to do so.

Option 1:

Using CreateScope() to create an empty ScriptScope to use directly in C# code but usable in Python sources. You can think of these as your global variables within an instance of the interpreter.

dynamic scope = engine.CreateScope();
scope.Add = new Func<int, int, int>((x, y) => x + y);
Console.WriteLine(scope.Add(2, 3)); // prints 5

Option 2:

Using Execute() to execute any IronPython code in a string. You can use the overload where you may pass in a ScriptScope to store or use variables defined in the code.

var theScript = @"def PrintMessage():
    		          print 'This is a message!'

// execute the script

// execute and store variables in scope
engine.Execute(@"print Add(2, 3)", scope);
// uses the `Add()` function as defined earlier in the scope

Option 3:

Using ExecuteFile() to execute an IronPython source file. You can use the overload where you may pass in a ScriptScope to store or use variables defined in the code.

// execute the script

// execute and store variables in scope
engine.ExecuteFile(@"C:\path\to\script.py", scope);
// variables and functions defined in the scrip are added to the scope

Option 4:

Using GetBuiltinModule() or the ImportModule() extension method to create a scope containing the variables defined in said module. Modules imported this way must be set in the search paths.

dynamic builtin = engine.GetBuiltinModule();
// you can store variables if you want
dynamic list = builtin.list;
dynamic itertools = engine.ImportModule("itertools");
var numbers = new[] { 1, 1, 2, 3, 6, 2, 2 };
Console.WriteLine(builtin.str(list(itertools.chain(numbers, "foobar"))));
// prints `[1, 1, 2, 3, 6, 2, 2, 'f', 'o', 'o', 'b', 'a', 'r']`

// to add to the search paths
var searchPaths = engine.GetSearchPaths();

// import the module
dynamic myModule = engine.ImportModule("mymodule");

You can do quite a lot hosting Python code in your .NET projects. C# helps bridging that gap easier to deal with. Combining all the options mentioned here, you can do just about anything you want. There’s of course more you can do with the classes found in the IronPython.Hosting namespace, but this should be more than enough to get you started.