code-snippets

How to edit existing VS Code Snippets

半世苍凉 提交于 2019-11-27 20:31:26
问题 Is there a way to remove or edit some of the default code snippets in Visual Studio CODE ? For example when i type req+TAB i need require not requestAnimationFrame 回答1: The suggestion item requestAnimationFrame is coming from the JavaScript language service. It's not coming from the snippets. However, you can define your own snippets and tell Visual Studio Code to show the snippets first. How to do it: Go to File -> Preferences -> User Snippets and select JavaScript in order to edit snippets

Why does this C# code return what it does

我们两清 提交于 2019-11-27 19:37:45
Can someone please help me understand why this code snippet returns "Bar-Bar-Quux"? I'm having a hard time understanding this even after reading up on interfaces. interface IFoo { string GetName(); } class Bar : IFoo { public string GetName() { return "Bar"; } } class Baz : Bar { public new string GetName() { return "Baz"; } } class Quux : Bar, IFoo { public new string GetName() { return "Quux"; } } class Program { static void Main() { Bar f1 = new Baz(); IFoo f2 = new Baz(); IFoo f3 = new Quux(); Console.WriteLine(f1.GetName() + "-" + f2.GetName() + "-" + f3.GetName()); } } Mike Zboray There

Quick and dirty way to profile your code

自古美人都是妖i 提交于 2019-11-27 18:12:44
What method do you use when you want to get performance data about specific code paths? Motti This method has several limitations, but I still find it very useful. I'll list the limitations (I know of) up front and let whoever wants to use it do so at their own risk. The original version I posted over-reported time spent in recursive calls (as pointed out in the comments to the answer). It's not thread safe, it wasn't thread safe before I added the code to ignore recursion and it's even less thread safe now. Although it's very efficient if it's called many times (millions), it will have a

Insert current datetime in Visual Studio Snippet

丶灬走出姿态 提交于 2019-11-27 17:52:22
问题 Does anyone know of a way that I can insert the current date & time in a visual studio 2008 snippet? What I want is something like this in the body of my .snippet file... <Code Language="csharp"> <![CDATA[ // $DateTime$ // more code here for my snippet... </Code> 回答1: There are no DateTime functions available for snippets but here is a macro that will insert the current DateTime: Sub PrintDateTime() If (Not IsNothing(DTE.ActiveDocument)) Then Dim selection As TextSelection = DTE

Manage code snippets in Notepad++

↘锁芯ラ 提交于 2019-11-27 17:27:09
Is there any way to manage code snippets with backup for the database and code highlighting in Notepad++? Francisco Alvarado There is a good plugin to manage code snippets: SnippetPlus .NET 3.5 Required! Code snippet and Surround With plugin for Notepad++. Write snippet name and replace it with real code or select some text and surround it with something like IF,TryCatch,Table,Div or whatever.Will give you hint if you don't remember the snippet name Note that the latest version may be shown, even though you have an older version installed. Reinstall to ensure you have the latest version.

Short (and useful) python snippets [closed]

陌路散爱 提交于 2019-11-27 16:37:53
In spirit of the existing "what's your most useful C/C++ snippet" - thread: Do you guys have short, monofunctional Python snippets that you use (often) and would like to share with the StackOverlow Community? Please keep the entries small (under 25 lines maybe?) and give only one example per post. I'll start of with a short snippet i use from time to time to count sloc (source lines of code) in python projects: # prints recursive count of lines of python source code from current directory # includes an ignore_list. also prints total sloc import os cur_path = os.getcwd() ignore_set = set(["_

How to determine whether a string is valid JSON?

…衆ロ難τιáo~ 提交于 2019-11-27 14:18:42
问题 Does anyone know of a robust (and bullet proof) is_JSON function snippet for PHP? I (obviously) have a situation where I need to know if a string is JSON or not. Hmm, perhaps run it through a JSONLint request/response, but that seems a bit overkill. 回答1: If you are using the built in json_decode PHP function, json_last_error returns the last error (e.g. JSON_ERROR_SYNTAX when your string wasn't JSON). Usually json_decode returns null anyway. 回答2: What about using json_decode, which should

Change default XML comment snippet in Visual Studio

北城以北 提交于 2019-11-27 13:33:49
When I hit /// in Visual Studio, is it possible to change the resulting snippet from this: /// <summary> /// /// </summary> to this?: /// <summary></summary> Here is the solution working in at least VS2010. Save the bottom code as a file summ.snippet. Visual Studio 2010 / Tools / Code Snippet Manager Click import, browse to file. Save with default options. Now goto your code window and type summ + tab + tab Result /// <summary> </summary> with the cursor in the middle of the tag, ready to type. Here is the contents of the summ.snippet <CodeSnippets xmlns="http://schemas.microsoft.com

How to hide code in RMarkdown, with option to see it

做~自己de王妃 提交于 2019-11-27 12:06:09
问题 I'm writing an RMarkdown document in which I'd like to re-run some chunks (5 to 9). There's no need to display these chunks again, so I considered using ```{r echo=FALSE} to make the rerun chunks invisible, as described in another stackoverflow question. This is fine, and outputs the desired results (improved fit of second iteration - see this solution implemented here). In an ideal world, however, the code would be expandable so the user could see exactly what's going on if they want to for

Xcode built-in snippets edit

跟風遠走 提交于 2019-11-27 11:47:45
问题 Is there a way to edit Xcode's built-in snippets? There is an edit button, but pressing it doesn't seem to allow changing the snippet's text. Any insight is appreciated. 回答1: You still can't edit the built-in system snippets. You can, however, edit "user" snippets. The simplest solution in my mind was to create copies of all the default snippets, but modify them so that they are "user" snippets and override the default versions. I wrote a little Python script to do the job. It's very simple,