Questions tagged [code-snippets]

For issues relating to the creation, use, and maintenance of code snippets.

A snippet is a small region of re-usable source code, machine code or text. Ordinarily, these are formally-defined operative units to incorporate into larger programming modules. Snippets are often used to clarify the meaning of an otherwise "cluttered" function, or to minimize the use of repeated code that is common to other functions.

Snippets can be created and used in many newer IDEs to insert a nearly functional code. With placeholders it is then possible to tab through the missing parts and fill in the variable names of other missing code parts.

For a fast practical use of a theoretical concept it is often preferred to show it on a snippet as an excerpt of the used code with the variable names foo and bar.

1929 questions
702
votes
40 answers

How to detect if JavaScript is disabled?

There was a post this morning asking about how many people disable JavaScript. Then I began to wonder what techniques might be used to determine if the user has it disabled. Does anyone know of some short/simple ways to detect if JavaScript is…
MikeJ
  • 14,430
  • 21
  • 71
  • 87
338
votes
27 answers

Get human readable version of file size?

A function to return human readable size from bytes size: >>> human_readable(2048) '2 kilobytes' >>> How to do this?
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
298
votes
17 answers

Shortcut to create properties in Visual Studio?

I have seen some people creating properties in C# really fast, but how did they do it? What shortcuts are available in Visual Studio (currently using Visual Studio 2010) to create properties? I am using C#. For example, public string myString…
user467058
193
votes
13 answers

How to add custom code snippets in VSCode?

Is it possible to add custom code snippets in Visual Studio Code? And if so, how? VSCode is based on Atom, so it should be possible.
BeastCode
  • 2,463
  • 2
  • 12
  • 11
177
votes
17 answers

Code snippet or shortcut to create a constructor in Visual Studio

What is the code snippet or shortcut for creating a constructor in Visual Studio? Visual Studio 2010 and C#.
user467058
169
votes
11 answers

How do you manage your gists on GitHub?

I love GitHub and their gist service, and that's why I'm keeping a lot of code snippets and even development notes as a gist on my GitHub account. It also makes it easy to share them with my colleagues. The problem is that it doesn't scale!! The…
Allen Bargi
  • 14,674
  • 9
  • 59
  • 58
148
votes
6 answers

Choose File Dialog

Does anyone know of a complete choose file dialog? Maybe one where you can filter out all files except for ones with specific extensions? I have not found anything lightweight enough to implement easily into one of my projects. The only other…
Aymon Fournier
  • 4,323
  • 12
  • 42
  • 59
107
votes
6 answers

Escaping the $ character in snippets

I find myself doing a ton of jQuery these days, so I started to abstract out some of the common things I do into snippets. I look forward to sharing these with the community, but I'm running into an issue right now. The literals in snippets are…
cory-fowler
  • 4,020
  • 2
  • 18
  • 29
82
votes
6 answers

Can't drag (to make code snippet) in Xcode

When I follow all the instructions (including apple's video) to drag text to create a code snippet in xcode, I get a different system behavior: all I see is the selection ibeam... I can't drag. It just ends up selecting text again. Am i missing some…
Jack Bellis
  • 1,177
  • 8
  • 10
72
votes
1 answer

Code snippets in PhpStorm

I use PhpStorm. I want to make snippets of code and then assign shortcuts to them. I can do it in NetBeans, but in PhpStorm I don't know how to make them. For example, to add console.log(); in NetBeans, I only type con + space. con is the shortcut…
Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56
68
votes
31 answers

Handy F# snippets

There are already two questions about F#/functional snippets. However what I'm looking for here are useful snippets, little 'helper' functions that are reusable. Or obscure but nifty patterns that you can never quite remember. Something like: open…
Benjol
  • 63,995
  • 54
  • 186
  • 268
67
votes
8 answers

Code snippets for methods in Visual Studio

In Visual Studio I can type e.g. for TAB TAB and a code snippet pops in. Are there built-in code snippets for private, public, etc. methods as well?
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
66
votes
7 answers

Storing code snippets in eclipse

I'm a recent semi-convert to Eclipse after 20 years of using vi and gvim. One of the things I miss about gvim is that I could cut a bunch of different snippets of code into named buffers, and paste them at will when doing something like repeating a…
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
64
votes
5 answers

Defining scope for custom Sublime Text 2 snippets

While trying to write my own snippets for Sublime Text 2, I ran into the following two problems: Finding scope keys. I figured out that I can look through my packages one by one and find references to a declared "scope" property. For example in…
James Heston
  • 923
  • 1
  • 8
  • 17
61
votes
1 answer

Visual Studio code snippets Cursor

In Visual Studio when you insert a snippet and finish inserting literals the cursor jumps to the beginning of the snippet. Now I'd like to tell visual studio where the cursor should go afterwards. I've searched the web and actually hold little hope…
Stormenet
  • 25,926
  • 9
  • 53
  • 65
1
2 3
99 100