How do I comment out a block of code in Stan? - syntax

This feels like a duplicate question, but I can't find it anywhere here or elsewhere!
So, in R, you can comment out a block of code with Ctrl + Shift + C/Cmd + Shift + C. Does anyone know how to perform the equivalent action in Stan? All I know is that Stan uses // in place of R's #. I've tried Ctrl + Shift + //Cmd + Shift + /, to no avail.
Thanks so much for any help! :)

You can create a comment within your Stan code by using the following:
/* this is a comment block
as opposed to a single
line block */
Please see, https://mc-stan.org/docs/2_18/reference-manual/bracketed-comments.html

Related

Python keeps saying invalid syntax

I'm currently trying to correct a code for a class and I when I try to the run the module it keeps saying invalid syntax. Please Help!
This is the code.
print (myName + ',thank you for taking this quiz. Your score was ' + myScore 'out of 3. ')
myName = "Jay"
myScore = 1
print ('%s thank you for taking this quiz. Your score was out %d of 3. ') %(myName, myScore)
This is a better way do it. The reason your code doesn't work is because you are missing a '+' after myScore.
print (myName + ',thank you for taking this quiz. Your score was ' + myScore + 'out of 3. ')
That is the corrected version.
Think deeper, your thought should think what syntax error you just made, not focus on a missing of a '+'

gsub variable regardless of case

I have the following code which will set a highlight for any parts of the phrase where the word is. I would like this to function regardless of case but I am struggling with the syntax. I believe I need to add /i somewhere, but I do not know where.
params.fetch('phrase').gsub(params.fetch('word'),
'<span class="ko-highlight">' + params.fetch('word') + '</span>')
This should do the trick
params.fetch('phrase').gsub(/#{params.fetch('word')}/i, '<span class="ko-highlight">' + params.fetch('word') + '</span>')

Keyboard shortcut to select current line in Xcode

Is there any way to select the text of the current line in Xcode? This would be equivalent to Cmd + l in Sublime or V in vim.
Actually you can just use the normal Mac-Shortcuts.
Beginning of Line
cmd + shift + >
Middle of Line
1. cmd + > (this brings you to the end of the line)
2. cmd + shift + < (selects everything to the left)
End of Line
cmd + shift + <
Hope this helps :)
Update
In Xcode 8, I have found the Select Line keyboard binding which you can set to cmd+l (that's L, not i) for instance to make Xcode select the line you're on right now when hitting that shortcut.
You can actually assign a key command to this. In Xcode under Preferences > Key Bindings > Text search for "Select Line" and assign it to you preferred key command (I also prefer command-l to match Sublime Text)
It's possible to select the line with ctrl + shift + a + e.
(a selects from cursor till the beginning of the line, while b selects from the cursor till the end of the line).
It's a bit long shortcut but can be useful if you end up needing only part of the line or the whole.
You can also split this into 2 steps:
ctrl + a to jump to the beginning of the line then use ctrl + shift + e to select till the end of the line.

How to align ruby string to left or right?

I have few ruby strings, which I want to align left and right appropriately.
I'm now using "Name".center(20, " ") to get "(7 spaces)Name(8 spaces)"
How can I achieve "Name(15 spaces)" or "(15 spaces)Name"
Thanks.
"Name".ljust(19)
"Name".rjust(19)
Ruby has a printf method defined in Kernel, try using that.
It supports many common "f" ("format", like in scanf, printf, ...) options (see e.g. man 3 printf).
Left and right justification can be done like this (extracted from comment):
printf("%10s", "right")
printf("%-10s","left")
Insert n Copies of a Character
There are certainly other ways to do this, but one of them is to use the splat operator to copy a character (e.g. the space character) a certain number of times. For example:
puts (' ' * 15) + 'Name'
puts 'Name' + (' ' * 15)

How do I parse a quoted string inside another string?

I want to extract the quoted substrings from inside a string. This is an example:
string = 'aaaa' + string_var_x + 'bbbb' + string_var_y
The output after parsing should be:
["'aaaa'", "'bbbb'"]
The initial solution was to string.scan /'\w'/ which is almost ok.
Still I can't get it working on more complex string, as it's implied that inside '...' there can be any kind of characters (including numbers, and !##$%^&*() whatever).
Any ideas?
I wonder if there's some way to make /'.*'/ working, but make it less greedy?
Lazy should fix this:
/'.*?'/
Another possibility is to use this:
/'[^']*'/
An alternate way to do it is:
>> %{string = 'aaaa' + string_var_x + 'bbbb' + string_var_y}.scan(/'[^'].+?'/)
#=> ["'aaaa'", "'bbbb'"]
String.scan gets overlooked a lot.

Resources