Trim File Name in Visual Assist Snippet/Macro - visual-assist

I am using Visual Assist X in Visual Studio 2008. I am defining a bunch of forward declaration files, all of which have basically the same format:
namespace ns1 { namespace ns2 {
class SampleClassName;
boost::shared_ptr<SampleClassName> SampleClassNamePtr;
}}
Obviously, I'm also putting in a header guard, a generated file comment, and other things as required by our coding standard (and the namespaces aren't placeholders).
Here's the issue: we name these files SampleClassNameForward.h so using the $FILE_BASE$ placeholder won't exactly work. Is there a way for me to apply a regex and remove the "Forward" from $FILE_BASE$ after it has been expanded, but prior to the snippet being pasted into my file? If I could do that, then I could fully automate generating these forward declarations and save myself (and my colleagues) a ton of time.

No, Visual Assist does not have any tools that would support regex modification of the file name as you are looking to do.
An alternative approach would be to create a VA Snippet that you use to create the block of code in a temporary file.
Create a VA Snippet that has all the boilerplate code.
add $SymbolName$Forward.h to the top of the code.
Invoke the snippet in the empty temporary file.
Cut the generated FooForward.h text at the top of the editor.
Select all (ctrl+a).
Invoke VAssistX | Refactoring | Move Selection to New File
At that point you would be prompted for the name of the new file and can paste the previously cut text (FooForward.h).
Move Selection To New File will create the new file in the same directory as the current file and add it to the same projects it is in.

Related

Current file path in Live Template

Is it possible to get the full path of the current file within a live template in IntelliJ? I've tried using groovyScript("new File('.').absolutePath") function, but that returns /Applications/IntelliJ IDEA.app/Contents/bin/. and not the file path as I was hoping for.
Thanks!
According to the docs (emphasis mine):
You can use groovyScript macro with multiple arguments. The first argument is a script text that is executed or a path to the file that contains a script. The next arguments are bound to _1, _2, _3, ..._n variables that are available inside your script. Also, _editor variable is available inside the script. This variable is bound to the current editor.
The _editor is an instance of EditorImpl which holds a reference to the VirtualFile that represents the currently opened file.
Therefore, the following script gets the full path of currently opened file.
groovyScript("_editor.getVirtualFile().getPath()")
Or if you want to get the path relative to the project's root:
groovyScript("_editor.getVirtualFile().getPath().replace(_editor.getProject().getBaseDir().getPath(), \"\")")
Since IntelliJ IDEA 2019.3 the Live Template macros filePath() and fileRelativePath() are available. A complicated Groovy script macro is no longer required.

How do i set working directory in sql developer in code

I'm using sql developer.
I want to run some scripts.
I don't want to have to include the folder name in the call to each script.
But I also want to use a variable to include the directory to look in (the working directory).
I can do this but i am having trouble with folder names with spaces (this is in windows).
Can anyone help me work out how to do this without having to rename my folder to remove spaces?
define dir="c:\Users\xx\Google Drive\Analytics\Recruitment\NSL\2. Data Understanding\Code"
#&dir\cb_nsl_impairments.sql;
Returns error
SP2-0310: Unable to open file: "c:\Users\xx\Google.sql"
Oops. Solved it.
Just needed double quotes around the script call:
#"&dir\cb_nsl_impairments.sql"

Can I create Variable Names from Constants in Objective-C/Swift?

This question is related to Swift and Objective-C.
I want to create variables from Constant Strings. So, in future, when I change name of a variable though out app, I just need to change it at one place, it must be changed, wherever it is used.
Example:
I have user_id in 14 files, if I want to change user_id into userID I have to change in all 14 files, but I want to change at once place only.
One way to do this would be to use the Xcode build process and add a script (language can be of your choice, but the default is a BASH script)
Create string constant text file where you define all your variables you want to change in some format that expresses the change you want to make, for example:
"variable_one_name" = "new_variable_one_name"
Depending on how 'smart' you wanted your script to be you could also list all your variables and include some way of indicating when a variable is not to be replaced.
"variable_one_name" = "new_variable_one_name"
"variable_two_name" = "DO_NOT_CHANGE"
Run a pre build script on you project that reads in the string constant text file and then iterates through your source files and executes the desired replacement. Be careful to limit the directories you search to you OWN source files!
build project...
This would allow you to manage your constants from one place. However it clearly is only going to help you after you have created a project and written some code :)
BASH string replacement
Adding a run script to the Xcode build process

Execute scripts by relative path in Oracle SQL Developer

First, this question relates to Oracle SQL Developer 3.2, not SQL*Plus or iSQL, etc. I've done a bunch of searching but haven't found a straight answer.
I have several collections of scripts that I'm trying to automate (and btw, my SQL experience is pretty basic and mostly MS-based). The trouble I'm having is executing them by a relative path. for example, assume this setup:
scripts/A/runAll.sql
| /A1.sql
| /A2.sql
|
/B/runAll.sql
/B1.sql
/B2.sql
I would like to have a file scripts/runEverything.sql something like this:
##/A/runAll.sql
##/B/runAll.sql
scripts/A/runAll.sql:
##/A1.sql
##/A2.sql
where "##", I gather, means relative path in SQL*Plus.
I've fooled around with making variables but without much luck. I have been able to do something similar using '&1' and passing in the root directory. I.e.:
scripts/runEverything.sql:
#'&1/A/runAll.sql' '&1/A'
#'&1/B/runAll.sql' '&1/B'
and call it by executing this:
#'c:/.../scripts/runEverything.sql' 'c:/.../scripts'
But the problem here has been that B/runAll.sql gets called with the path: c:/.../scripts/A/B.
So, is it possible with SQL Developer to make nested calls, and how?
This approach has two components:
-Set-up the active SQL Developer worksheet's folder as the default directory.
-Open a driver script, e.g. runAll.sql, (which then changes the default directory to the active working directory), and use relative paths within the runAll.sql script to call sibling scripts.
Set-up your scripts default folder. On the SQL Developer toolbar, Use this navigation:
Tools > Preferences
In the preference dialog box, navigate to Database > Worksheet > Select default path to look for scripts.
Enter the default path to look for scripts as the active working directory:
"${file.dir}"
Create a script file and place all scripts associated in it:
runAll.sql
A1.sql
A2.sql
The content of runAll.sql would include:
#A1.sql;
#A2.sql;
To test this approach, in SQL Developer, click on File and navigate and open the script\runAll.sql file.
Next, select all (on the worksheet), and execute.
Through the act of navigating and opening the runAll.sql worksheet, the default file folder becomes "script".
I don't have access to SQL Developer right now so i can't experiment with the relative paths, but with the substitution variables I believe the problem you're seeing is that the positional variables (i.e. &1) are redefined by each start or #. So after your first #runAll, the parent script sees the same &1 that the last child saw, which now includes the /A.
You can avoid that by defining your own variable in the master script:
define path=&1
#'&path/A/runAll.sql' '&path/A'
#'&path/B/runAll.sql' '&path/B'
As long as runAll.sql, and anything that runs, does not also (re-define) path this should work, and you just need to choose a unique name if there is the risk of a clash.
Again I can't verify this but I'm sure I've done exactly this in the past...
you need to provide the path of the file as String , give the patch in double quote it will work
**
For Example
#"C:\Users\Arpan Saini\Zions R2\Reports Statements and Notices\Patch\08312017_Patch_16.2.3.17\DB Scripts\snsp.sql";
**
Execution of Sql
#yourPath\yourFileName.sql
How to pass parameters in file
#A1.sql; (Parameter)
#A2.sql; (Parameter)
This is not absolute or relative path issue. It's the SQL interpreter issue, where by default it will look for files which are having .sql extention.
Please make sure to modify the file name to file_name.sql
Ex: if workspace is having file name called "A", then move the file from A to "A.sql"

Automatically locating a file

By default AutoCAD installs a text based file called acad2010.lsp at the set location below
Dim FILE_NAME As String = "C:\Program Files\AutoCAD 2010\Support\acad2010.lsp"
However it my be that the user/ administrator/ or third party has changed the location of this file. Is it possible to then locate it using the following
Dim FILE_NAME As String = "C:\*\acad2010.lsp"
In other words search the entire c:\ drive for file acad2010.lsp?
If this doesn't work can you please let me know what would?
You could search for it with an FSO. It's not going to be fast however you do it but this is the fastest way I can think of.
http://www.microbion.co.uk/developers/fso.htm should give you a rough idea of how it's done.
Your solution will not work. Is not possible to locate it using *. (BTW is possible in ms-builds scripts). The only way of doing it is:
1- Create a FindFile function (check for example
http://xlvba.3.forumer.com/index.php?showtopic=125)
2- Use it to locate the exact path of the file. (It could be really time
consuming)
3- From this point your code is the same...
Unfortunately, you can't use wildcards in a filepath. You have two options:
Prompt the user for the file location using the "Open File" dialog. The code to do this varies based on which Office product you are using. In Excel, you would use the Application.FindFile method (more info here).
Write your own function to search the filesystem for the file. Microsoft provides an example here.
If that file is used by internal functions of the application, the installer will have recorded a registry key for the file's location.
Open regedit.exe and search for the file name and path.
You can read a registry entry using this VBA one-liner:
CreateObject("WScript.Shell").RegRead(strRegPath)
You may need a terminating backslash on the key address, but that's a safe and simple registry access method. More details on the MSDN site:
https://msdn.microsoft.com/en-us/library/x05fawxd%28v=vs.84%29.aspx