Doxygen anchor inside function - anchor

I have a filter which converts actual code into #code/#endcode blocks but I can't figure out a way to create a #ref link to these sections.
Here's a snippet of what I mean:
/**
* Refer to this example: #ref example1
* #param $arg1
* #param $arg2
*/
public function somefunction($arg1, $arg2)
{
/**
* #anchor example1 #code
if (true)
{
$this = 'bollox';
}
* #endcode
**/
}
The output of this looks pretty much like what I want (although I haven't decided on how best to truly indicate the link point...exmple1 springs to mind).
The problem is that the hyperlink for example1 links to the filename.html#example1.
I've checked the source and there is an anchor class being generated.
I understand I'm not really using anchor as documented.
Any suggestions welcome.
Note: I'm not specifically trying to get anchor to work...just want a hyperlink/bookmark to link a \ref (or similar).

Related

How to check whether url used in IMAGE formula was correct and image is displayed?

I have a list of images I reference using their filenames:
=image("domainname.com/somepath/"&A2&".jpg")
where in A2 is a filename.
Unfortunately some of these images have .png extension.
I try to find a solution to check if file with jpg extension is correct and image is found. If not found I want to use
=image("domainname.com/somepath/"&a2&".png")
For this cell.
IFNA and IFERROR formulas do not work.
I tried also to concatenate formulas:
=image("domainname.com/somepath/"&a2&".png")&image("domainname.com/somepath/"&a2&".jpg")
but I see that you can use & only for strings
There are thousands of images in different folders for reference and I cannot control their format.
Do you have any idea?
One workaround I would suggest is to create and use a custom function to validate the image URL.
Custom Functions
Google Sheets offers hundreds of built-in functions like AVERAGE, SUM, and VLOOKUP. When these aren’t enough for your needs, you can use Google Apps Script to write custom functions — say, to convert meters to miles or fetch live content from the Internet — then use them in Google Sheets just like a built-in function.
Sample Custom Function:
/**
* validate image
*
* #param {input} image url to validate.
*
* #customfunction
*/
function IMAGE_TRY(input) {
try{
var response = UrlFetchApp.fetch(input);
return 1;
} catch(err) {
return 0;
}
}
This custom function will take 1 image URL argument and verify if that URL is valid using the try-catch method. The function will return 1 when the URL is valid and 0 if not a valid URL
Note that the #customfunction tag is important in the function comment so that this custom function will appear as a suggested formula when you are typing in a cell.
Once you have created a custom function, you can use this to validate the URL and use the correct image URL using IF function.
Sample:
=IF(IMAGE_TRY("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.jpg"),image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.jpg"), image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.png"))
Sample Output:
(UPDATE)
OPTIMIZED SOLUTION:
Sample Custom Function:
/**
* get image url with correct file extension.
*
* #param {input} image url string without extension.
*
* #customfunction
*/
function getURL(input) {
try{
var response = UrlFetchApp.fetch(input+".jpg");
return (input.concat(".jpg"));
} catch(err) {
return (input.concat(".png"));
}
}
This solution accepts an image URL without file extension and return an image URL with the valid file extension.
Sheets Formula:
=image(getURL("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp"))

Google Sheets QR code "tab"

I am working with the Google sheets to make QR codes. I have my scanner programmed to do a 'TAB' function after every scan and it works well. I would like to make a single QR code that has 3 different pieces of information in it with a tab between each and an enter on the end. I have tried many ways and just found that most of them work fine in something like Notepad, but nothing is working in a form where there are 3 fields. The form has the following fields: Plant, Department, Part#
I have tried using:
//cell E12 has 106+%09+W6311A+%09+12345678 or 106+char(9)+W6311A+char(9)+12345678
=if(isblank(E12),"",image("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl="&E12))
//A14==106, B14==W06311A, C14==12345678
=CONCATENATE(A14, char(9),B14,char(9),C14,char(10))
//A15==the above concatenate code
=image("https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl="& urlencode(join(char(10),arrayformula(A15))))
//this script is called by the above code:
/**
* Converts a string to a properly encoded URI
*
* #param {string} component The component you want to encode
* #return {string} The encoded URI component.
* #customfunction
*/
function urlencode ( component ) {
if ( component && component.map ) {
return component.map ( urlencode );
Logger.log(component);
}
else {
return encodeURIComponent ( component || "" ) ;
Logger.log("2 "+component);
}
}
As I said, they work fine in word or notepad, but they put all the information into one field of a form. One scan could be quicker then the current 3 individual scans that we do. Is there a coding method that is specific to fill in forms?
Thanks,
Josh

how to validate and check if a entered URL is valid or not in Drupal 6

Without using any third party modules, is it possible to validate and check at the same time if any URL entered in a text-box is valid or not in Drupal 6 ? Some sample code will be appreciated.
menu_valid_path() function in menu.inc (which is part of Drupal Core) does just that.
To answer your specific question:
Without using any third party modules, is it possible to validate and check at the same time if any URL entered in a text-box is valid or not in Drupal 6
Yes.
You will, however, need to create a simple custom module.
Let's assume:
Your form id is my_form_1
The field name in question is my_path_field_1
In your MODULENAME.module file:
<?php
/**
* Modifies the existing form element 'my_path_field_1' to add
* 'MODULENAME_path_validate' function to validation array.
*
* (MYMODULE_path_validate is defined below)
*/
function MODULENAME_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'my_form_1' :
$form['my_path_field_1']['#element_validate'] = array('MODULENAME_path_validate');
break;
}
// Note, you could use hook_form_FORM_ID_alter(&$form, &$form_state)
// instead of the above to simplify things if the only thing this module
// does is validite one field for a valid path.
/**
* Validates the my_path_field_1 using Drupal's built-in menu_valid_path()
* function. Returns a form error if the field does not contain a valid path
* or the current user does not have access to the path's permission.
*/
function MODULENAME_path_validate($element, &$form_state) {
if (!menu_valid_path($element)) {
form_error($element, t('The path entered does not exist or you do not have permission to access it.'));
}
}

Is it safe to use the same parameters for input and output in D3DX functions?

Using the D3DX library that is a part of directX, specifically directx9 in this case, I'm wondering if it's safe to use the same matrix (or vector etc) for input and ouput
D3DXMATRIX mat;
D3DXMatrixInverse(&mat, NULL, &mat);
I've been avoiding doing so, assuming that it would result in bad things happening when parts of the array got partly overwritten as results are calculated but I see an awful lot of code around that does exactly this.
A brief test indicates that it seems to work ok, so I'm assuming that the D3DX functions take a copy where necessary of the input data, or some other method to ensure that this works ok, but I can't find it documented anywhere so I'm reluctant to rely on it working.
Is there any official statement on using the functions like this?
Yes, it is. From msdn:
Each of the functions can take the same object as the passed [in] and returned [out] parameters
I'm pretty sure the answer is yes. I can't find anywhere where this is said for sure however ...
Edit: Flicking through D3DX9Math.inl it looks like care HAS been taken to make sure you can. For example if we look at the code for D3DXVec3Cross:
D3DXINLINE D3DXVECTOR3* D3DXVec3Cross
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
{
D3DXVECTOR3 v;
#ifdef D3DX_DEBUG
if(!pOut || !pV1 || !pV2)
return NULL;
#endif
v.x = pV1->y * pV2->z - pV1->z * pV2->y;
v.y = pV1->z * pV2->x - pV1->x * pV2->z;
v.z = pV1->x * pV2->y - pV1->y * pV2->x;
*pOut = v;
return pOut;
}
You can see that it performs the cross product into a temporary and THEN, in the final step, it copies it into the return. It would be nice if this was stated somewhere for sure.

solr sanitizing query

I am using solr with ruby on rails.
It's all working well, I just need to know if there's any existing code to sanitize user input, like a query starting with ? or *
I don't know any code that does this, but theoretically it could be done by looking at the parsing code in Lucene and searching for throw new ParseException (only 16 matches!).
In practice, I think you're better off just catching any solr exceptions in your code and showing an "invalid query" message or something like that.
EDIT: Here are a couple of "sanitizers":
http://pivotallabs.com/users/zach/blog/articles/937-sanitizing-solr-requests
http://github.com/jvoorhis/lucene_query
http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/
If you are using Solarium with PHP then you can use the Solarium_Escape::term() method.
/**
* Escape a term
*
* A term is a single word.
* All characters that have a special meaning in a Solr query are escaped.
*
* If you want to use the input as a phrase please use the {#link phrase()}
* method, because a phrase requires much less escaping.\
*
* #link http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
*
* #param string $input
* #return string
*/
static public function term($input)
{
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
return preg_replace($pattern, '\\\$1', $input);
}

Resources