code-formatting

Python “best formatting practice” for lists, dictionary, etc

让人想犯罪 __ 提交于 2019-11-28 22:37:12
I have been looking over the Python documentation for code formatting best practice for large lists and dictionaries, for example, something = {'foo' : 'bar', 'foo2' : 'bar2', 'foo3' : 'bar3'..... 200 chars wide, etc..} or something = {'foo' : 'bar', 'foo2' : 'bar2', 'foo3' : 'bar3', ... } or something = { 'foo' : 'bar', 'foo2' : 'bar2', 'foo3' : 'bar3', ... } How do I handle deep nesting of lists/dictionaries? My preferred way is: something = {'foo': 'bar', 'foo2': 'bar2', 'foo3': 'bar3', ... 'fooN': 'barN'} danlei aaronasterling's indentation style is what I prefer. This, and several other

Split Ruby regex over multiple lines

故事扮演 提交于 2019-11-28 21:00:16
This might not be quite the question you're expecting! I don't want a regex that will match over line-breaks; instead, I want to write a long regex that, for readability, I'd like to split onto multiple lines of code. Something like: "bar" =~ /(foo| bar)/ # Doesn't work! # => nil. Would like => 0 Can it be done? SilentGhost You need to use the /x modifier, which enables free-spacing mode . In your case: "bar" =~ /(foo| bar)/x mthorley Using %r with the x option is the prefered way to do this. See this example from the github ruby style guide regexp = %r{ start # some text \s # white space char

Disable Visual Studio code formatting in Razor

人走茶凉 提交于 2019-11-28 20:59:08
This has been asked before: Why doesn't Visual Studio code formatting work properly for Razor markup? But that question is a couple years old. And Razor formatting is still completely unacceptable. I have given up on fixing it. Can I disable ALL Visual Studio formatting for CSHTML files? If not, can I disable all Visual Studio formatting entirely? Any 3rd party hacks I can use? There's got to be something! I've upgraded to 2013 and the formatting is just as bad. [EDIT]: 2015 is god-awful as well. I REALLY wish they would fix this. [EDIT]: 2017 is god-awful as well. I REALLY wish they would fix

How to format PHP files with HTML markup in Visual Studio Code?

我的梦境 提交于 2019-11-28 19:26:07
I'm using Laravel so all the views are .blade.php files. Visual Studio Code won't format the HTML because of the PHP extension. I removed the blade part of the filename, but it still isn't formatting the files properly (via Alt + Shift + F ). I also tried about five extensions but none of them do the reformatting. How can I format .blade.php files in Visual Studio Code? The extension beautify just do it very well, either add php and any other file extension type to the config as said above here is an example : go to user settings (CTRL + comma) search for beautify in the field above, and

How do I comment in CoffeeScript? “/* this */” doesn't work

人盡茶涼 提交于 2019-11-28 19:24:16
问题 In what ways can you comment in CoffeeScript? The documentation say you can use three hash symbols to start and close a comment block: ### Comments go here ### I've found that I can sometimes use the following two formats `// backticks allow for straight-JavaScript, // but the closing backtick can't be on a comment line (I think?) ` Are there a simpler way to insert short comments in CoffeeScript? Do NOT use this style** Since this is getting a lot of views, I want to emphasize that /*

How do I set up VSCode to put curly braces on a new line?

核能气质少年 提交于 2019-11-28 19:12:18
Let's say I type in the following code and format it. if (condition) { /* Hello! */ } If this is C# code, it is formatted like this: if (condition) { // Hello! } If it is JavaScript, VSCode formats it like this: if (condition) { // Hello! } So how can I use the first formatting style (curly braces on new lines) for all languages? I can't find a setting or something similar. Suggestions? Emmanuel Lozoya I think that in a condition statement there are no side effects, but in a return statement there is a problem. Check this link: https://web.archive.org/web/20160421051556/http://encosia.com/in

In Emacs, how to line up equals signs in a series of initialization statements?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 18:16:32
I saw this somewhere, but cannot find it now. Is there a built-in function in emacs, or does someone have elisp, to line up all the equals signs in a series of inititialization statments in cc-mode? Before: int t=9; Graphics g = new Graphics(); List<String> list = new List<String>(); After: int t = 9; Graphics g = new Graphics(); List<String> list = new List<String>(); Use M-x align-regexp (here, M-x align-regexp RET = RET ). You can also add an "alignment rule" to the variable align-rules-list , so that in future M-x align will do it. See the documentation ( C-h f align ) for details. This is

SQL string formatter [closed]

安稳与你 提交于 2019-11-28 18:10:37
Does anyone know of a program, a utility, or some programmatic library, preferably for Linux, that takes an unformatted SQL string and pretty prints it? For example I would like the following select * from users where name = 'Paul' be changed to something like this select * from users where name = 'Paul' The exact formatting is not important. I just need something to take a large SQL string and break it up into something more readable. http://www.sqlinform.com/ This tool reformats SQL code. I've used it with awesome results. It's free as a webapp and has a downloadable version as well. Check

JavaScript Chart.js - Custom data formatting to display on tooltip

喜欢而已 提交于 2019-11-28 17:11:21
I have looked at various documentation and similar questions on here, but cannot seem to find the particular solution. Apologies if I have missed anything obvious or have repeated this question! As a bit of background info, I have implemented 4 graphs using the Chart.js plugin and passed in the required data using PHP from a database. This is all working correctly and is fine. My problem is I need to display the data in the tooltips as formatted data aka. as numeric with %. As an example, one of my data from database is -0.17222. I have formatted it as a percentage to display in my table and

Directory layout for pure Ruby project

笑着哭i 提交于 2019-11-28 16:53:59
I'm starting to learn ruby. I'm also a day-to-day C++ dev. For C++ projects I usually go with following dir structure / -/bin <- built binaries -/build <- build time temporary object (eg. .obj, cmake intermediates) -/doc <- manuals and/or Doxygen docs -/src --/module-1 --/module-2 -- non module specific sources, like main.cpp - IDE project files (.sln), etc. What dir layout for Ruby (non-Rails, non-Merb) would you suggest to keep it clean, simple and maintainable? Bundler includes the necessary infrastructure to generate a gem: $ bundle gem --coc --mit --test=minitest --exe spider Creating gem