I'm having an issue getting some code to work that I'm hoping someone out there might be able to help me with.
Basically, we have a nest macro that returns an image ID.
This code works fine when using a static value. However, if I use a variable, it fails.
Works: [#imageIDByPath]Brand/header.jpg[/#imageIDByPath]
Fails: [#imageIDByPath]Brand/${imageName}[/#imageIDByPath]
Is there a way to make this work without updating the macro? sadly I don't have control over the macro to make any changes to it.
I've tried:
[#assign imageName = "Header.jpg"]
[#assign imageIDMacro][#noparse][#imageIDByPath]Brand/[/#noparse]${imagename}[#noparse][/#imageIDByPath][/#noparse][/#assign]
[#assign imageID = imageIDMacro?interpret]
[#imageID /]
but this doesn't appear to work either.
any help would be greatly appreciated.
Thanks.
Related
From MATLAB I am calling a Python function that creates and returns a Python object MyPyObj created by me with some attribute. The object is correctly returned however some attribute is missing and when I try to access them in MATLAB, a No appropriate method, property, or field error is returned. Does someone know why this happens?
Have you already tried this:
commandStr = 'python /Users/myName/pathToScript/sqr.py 2';
[status, commandOut] = system(commandStr);
if status==0
fprintf('squared result is %d\n',str2num(commandOut));
end
I managed to solve the problem following this post. Basically I needed to use
py.getattr(myPyObj, 'name_of_the_hidden_attribute')
However I am still not able to understand why myPyObj.name_of_the_hidden_attribute throws an error. I want to provide also this link in case my solution does not fix the problem for other users.
I'm using this peculiar syntax for assigning an object to an instance variable during a list iteration:
execute: =>
while #canExecute()
for #currentStack in #stacks
#executeNext()
if #currentStack.isEmpty()
#stacks.remove #currentStack
break
The important line here is for #currentStack in #stacks. This assigns this.currentStack during iteration. I like this. It makes me happy.
I'm worried though that it's an issue. I don't see it specifically documented anywhere. This code is running in several different products and I haven't found an issue myself. Anyone have experience with this?
You are using a pure javascript for...in loop, it is perfectly fine you can continue being happy. Link for documentation:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
I was wondering if anyone knew if it is possible to have MATLAB type a string for you, as if the user had typed it on the keyboard. I believe it can be done using a shell script or an applescript, but I was wondering if Matlab had a native implementation.
I have tried searching around for it, but have not had any luck. It is not super necessary, but I am just super lazy and want to write a script that will automatically enter information into an application after MATLAB has calculated stuff.
If you know of another simple way of doing this, let me know as well. Thanks a lot!
EDIT:
Adding some code that I used in response to an answer below, using the Java Robot Class
function robotType(text)
import java.awt.Robot;
import java.awt.event.*;
SimKey=Robot;
for i = 1:length(text)
if strcmp(text(i),upper(text(i))) == 0 || all(ismember(text(i),'0123456789')) == 1
eval(['SimKey.keyPress(KeyEvent.VK_',upper(text(i)),')'])
eval(['SimKey.keyRelease(KeyEvent.VK_',upper(text(i)),')'])
else
SimKey.keyPress(KeyEvent.VK_SHIFT);
eval(['SimKey.keyPress(KeyEvent.VK_',upper(text(i)),')'])
eval(['SimKey.keyRelease(KeyEvent.VK_',upper(text(i)),')'])
SimKey.keyRelease(KeyEvent.VK_SHIFT);
end
end
end
Warning, code may not be the best, but hey it was written in like 5 minutes.
I ended up writing an applescript to do everything that I needed Matlab to do. Unfortunately this will not help the Windows people, but myself and the other people using the script are mac users, so it works for us.
I have however, edited my question above to include code that I used initially in Matlab to auto type things. Simply run command as robotType('SomeString') and it will type that string.
I do not believe it will hand spaces or random characters that well, or at all, but it is good enough for abc123. Sorry for no final solution on this.
I messed up in my code - I create lots of short-lifetime objects and use MEF to resolve dependencies. As anyone with some MEF experience knows, MEF holds onto a reference on these guys. The result is the short lifetime turns into LOOONNNGGG lifetime. So, this is easy enough to fix - use SatisfysImportsOnce on CompositionContainer.
But I'd like to make this x-check part of my unit tests now so that I don't accidently add an incorrect part into the container (or perhaps I missed one in the code search I just did). Sooo... how to do this?
My code, a bit abstracted, looks something like this:
_catalog = new AggregateCatalog();
_container = new CompositionContainer(_catalog);
_batch = new CompositionBatch();
I then add parts to a batch, and call _container.Compose(_batch). I thought perhaps something like the following would work to get a count, but it always returns zero:
int nParts1 = _container.Parts.Count();
int nParts2 = _container.Catalogs.Sum(c => c.Parts.Count());
However, both of those return zero. How can I get this count for tests? It is ok if perf isn't fantastic - this is part of the test, not the running app. Many thanks in advance!
There's not a simple way to do this. You'll need to go digging around in the internal implementation of MEF to find this information. Since the source code is available (mef.codeplex.com) this is quite possible, but still not too simple.
I have a comment template in Eclipse (CDT) that I use for function calls which looks like:
//****************************************************************************
//
// Function: ${enclosing_method}
//
// Purpose:
//
// Parameters:
//
//****************************************************************************
My problem is that the ${enclosing_method} template variable doesn't work MOST of the time, but other times it does and I have yet to figure out why. I've tried using the comment template inside of the function and outside (on top of) the function definition even within the same header file. I prefer it to be on top and have seen it work in that position but again I don't know why.
What prerequisites need to be met in order for the enclosing_method variable to place the name within the comment automagically?
Thanks in advance for any insight you can provide.
You are not the only one experiencing issues with this template.
Even in JDT (Java) there is a problem, since 2004! See bug 76661.
It is however not entirely reproducible.
Looked into this to try and find a reproducible case. I can get it happen consistently if I add a new method to a class and then execute the template inside of the method before saving
So far, no patch in sight.