How do you get the Scope in PDFlib - pdflib

I'm just starting out in PDFlib, and the manual (for PDFlib 8) says to get the scope ...
You can query the current scope with the scope parameter.
But I have no idea how to get at that parameter, and internet searches are getting me nowhere because "get scope" is everywhere.

I currently use the following construct in PHP:
PDF_get_string($p, PDF_get_option($p, 'scope', ''), '')
Explanation: PDF_get_option gets the current scope as an integer, and then PDF_get_string resolves that integer to a nice string. This return something like "template" or "page".
If you use PDFLib object oriented, the code is probably something like this:
$p.get_string($p.get_option('scope', ''), '');
And it should be easy enough to adapt it to Java.

There may be a better way, but I found that this seems to work...
myPDF.get_parameter('scope', 0)

Related

Maquette cannot read property "class" of undefined

Chrome debug console snapshot
I basically am unsure as to what is causing this error ^^.
I've done a little digginng, and it seemse the previousProperties is passed in as previous.properties by updateDom(). previous, in turn, is passed in by update where it is labeled as just vnode. This VNOde is a valid VNode, but just lacks the properties.
I'm pretty sure I've made everything distinguishable (by setting unique key properties) that would need to be distinguishable, so I don't think that's the problem, although I could be mistaken.
So I had this question, wrote it, did more looking and found my answer before even posting it. I'm still posting this question, and answering it myself in hopes that it might help save someone else some heartache in the future.
In this case, this error is being caused by a projector rendering and receiving an invalid value in return from the renderMaquette function. In my component based framework, I've been using ternary operators to work like if-else statements inside renderMaquetteFunction return blocks. I.E.
function renderMaquette(){
return h('div',
showTitle ?
h('h1', 'My Title')
: []
)
}
Leaving an empty array is perfectly acceptable parameter inside of a hyperscript function, as it will return nothing. However, returning an empty array is not. I.E.
function renderMaquette(){
return showTitle ?
h('h1', 'My Title')
: []
}
This generates an error.

Extract a html tag that contains a string in openrefine?

There is not much to add to the title. It's what i'm trying to do. Any suggestions?
I reviewed the docs at github and googled extensively.
The best i got is:
value.parseHtml().select('p[contains('xyz')]')
It results in a syntax error.
The 'select' syntax is based on the select syntax in Beautiful Soup (http://jsoup.org/cookbook/extracting-data/selector-syntax)
In this case I believe the syntax you need is:
value.parseHtml().select("p:contains(xyz)")
Owen
Perhaps you missed my writeup (and WARNING) on the wiki :) here ?
https://github.com/OpenRefine/OpenRefine/wiki/StrippingHTML#extract-html-attributes-text-links-with-integrated-grel-jsoup-commands
WARNING: Make sure to use .toString() suffixes when needed to output strings into Refine cells while working with the built-in HTML GREL commands (the default output is org.jsoup.nodes objects). Otherwise you'll get a preview just fine in the Expression Editor, BUT no data shown in the Refine cells when you apply it!
BTW, How could we make the docs better and where, so that someone doesn't miss this in the future ?
I even gave folks a nice example in our docs that shows using .toString() :
https://github.com/OpenRefine/OpenRefine/wiki/GREL-Other-Functions#selectelement-e-string-s

jQuery tmpl: handling null/undefined elements

I have a data structure returned by a web service. It's a few levels deep, and could have null instead of the expected object. Which results in some ugly code to check.
<td>{{if FulfilledBy}}${FulfilledBy.Name}{{/if}}</td>
I can't change the output of the service, but I'd rather not need to check if FulfilledBy exists prior to access the .Name property.
Is there a better way to write this? I would have preferred something like
<td>${(FulfilledBy || {}).Name}</td>
but it doesn't work either.
According to docs, you can use expressions within ${}. Have you tried ${FulfilledBy? FulfilledBy.Name: 'no name'}?

Group functions of similar functionality

Sometimes I come across this problem where you have a set of functions that obviously belong to the same group. Those functions are needed at several places, and often together.
To give a specific example: consider the filemtime, fileatime and filectime functions. They all provide a similar functionality. If you are building something like a filemanager, you'll probably need to call them one after another to get the info you need. This is the moment that you get thinking about a wrapper. PHP already provides stat, but suppose we don't have that function.
I looked at the php sourcecode to find out how they solved this particular problem, but I can't really find out what's going on.
Obviously, if you have a naive implementation of such a grouping function, say filetimes, would like this:
function filetimes($file) {
return array(
'filectime' => filectime($file)
,'fileatime' => fileatime($file)
,'filemtime' => filemtime($file)
);
}
This would work, but incurs overhead since you would have to open a file pointer for each function call. (I don't know if it's necessary to open a file pointer, but let's assume that for the sake of the example).
Another approach would be to duplicate the code of the fileXtime functions and let them share a file pointer, but this obviously introduces code duplication, which is probably worse than the overhead introduced in the first example.
The third, and probably best, solution I came up with is to add an optional second parameter to the fileXtime functions to supply a filepointer.
The filetimes functions would then look like this:
function filetimes($file) {
$fp = fopen($file, 'r');
return array(
'filectime' => filectime($file, $fp)
,'fileatime' => fileatime($file, $fp)
,'filemtime' => filemtime($file, $fp)
);
}
Somehow this still feels 'wrong'. There's this extra parameter that is only used in some very specific conditions.
So basically the question is: what is best practice in situations like these?
Edit:
I'm aware that this is a typical situation where OOP comes into play. But first off: not everything needs to be a class. I always use an object oriented approach, but I also always have some functions in the global space.
Let's say we're talking about a legacy system here (with these 'non-oop' parts) and there are lots of dependencies on the fileXtime functions.
tdammer's answer is good for the specific example I gave, but does it extend to the broader problem set? Can a solution be defined such that it is applicable to most other problems in this domain?
Use classes, Luke.
I'd rewrite the fileXtime functions to accept either a filename or a file handle as their only parameter. Languages that can overload functions (like C++, C# etc) can use this feature; in PHP, you'd have to check for the type of the argument at run time.
Passing both a filename and a file handle would be redundant, and ambiguous calls could be made:
$fp = fopen('foo', 'r');
$times = file_times('bar', $fp);
Of course, if you want to go OOP, you'd just wrap them all in a FileInfo class, and store a (lazy-loaded?) private file handle there.

How to execute a literal in VBA?

Is there a way to execute a literal such as,
UseValueKey = ExecuteMethod("Date()")
I want to have the variable UseValueKey return the actual date.
I am using VBA.
Any ideas?
I haven't done any VBA coding for several years, but I recall that Access VBA had an Eval() method that could be used to evaluate code represented as a string.
This article gives an example of its usage.
You can try the Eval function.
If, as indicated in the question comments, the function name is known and can be delivered as a method on a class, try looking at
CallByName object, routine, callType
where callType indicates whether the called routine is a property Get/Let/Set or a Method.
It feels a lot less kludgey (and somewhat better controlled) than fooling with code evaluation, where you may be leaving yourself open to, er, unexpected consequences...
Perhaps I'm not exactly following you, but you should be able to use
Date
for example
UseValueKey = date