File header or general comment - language-agnostic

Does anybody have a nice well structured starting comment for a file? I'm looking for something that looks nice, either fancy or very professional.
By general comment I mean the comment at the top of a file showing your name and purpose of the file. Like this one:
/********************************************************
* hello -- program to print out "Hello World". *
* *
* Author: FirstName, LastName *
* *
* Purpose: Demonstration of a simple program. *
* *
* Usage: *
* Runs the program and the message appears. *
********************************************************/

doxygen format?
/*! \file hello.cpp
\brief program to print out "Hello World"
Created: 2009-11-21 by FirstName, LastName \n
Modified: \n
*/

For Java, I prefer the following style (but these points can be applied to other languages too):
If you would like to include some copyright stuff, do in the first one or two lines. Keep it short. If you have something more to say about this, do it in some README file or on your product's web site.
Do not include any metainfo such as filename, last modification date, #author or #version tags. Tools like Subversion can keep track of such things much better, and duplicating this kind of information just adds unnecessary work to keep them in sync.
Start the javadoc of your class with a sentence that summarizes its main function.
No need to use captions like Purpose or Usage, just explain what you have to say in a few paragraphs. Forms and fields are great if a script needs to process them, but not so much if people will read them.
So to sum it up, I use something like this:
/* Copyright 2002-2009 Foo Ltd. All rights reserved. */
package foo.bar;
/**
* This class does this or that.
*
* Now you can go into the details, try to be professional here by writing a
* few clear, articulate paragraphs, not by drawing fancy ascii boxes.
*
* #see foo.bar.OtherClass
*/
public class MyClass {
...
}

For C#, Stylecop enforces a header that looks like this
// <copyright file="filename.cs" company="Company">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Mr blah blah</author>
// <email>blahblah#blahblah.com</email>
// <date>2009-11-21</date>
// <summary>File description.</summary>
You can configure the required company name in the copyright tag.

Related

Meta tags in skin from MediaWiki template

Let's say i have a template in my MediaWiki like
<includeonly>
<div id="custom-person">
* <span>Birthday:</span> {{#if: {{{birth date|}}} | <b>{{#ol-time:|{{{birth date}}}}}</b> | — }}
{{#if: {{{full name|}}} | * <span>full name:</span> <b>{{{full name}}}</b>}}
{{#if: {{{birth place|}}} | * <span>birth place:</span> <b>{{{birth place}}}</b>}}
{{#if: {{{age|}}} | * <span> age:</span> <b>{{{age}}}</b>}}
{{#if: {{{nationality|}}} | * <span> nationality:</span> <b>{{{nationality}}}</b>}}
<div class="clear"></div>
</div>
[[Category:Person]]
__NOTOC__
</includeonly>
All these pages are in one Namespace (0).
I need to generate head meta tags with data from this template.
I figured out how to filter such a pages and add title tags in my SkinPerson.php
if ( $out->getTitle()->getNamespace() == 0 ) {
$out->addMeta( "description", $out->getPageTitle());
$out->addHeadItem( 'og:description', '<meta property="og:description" content="' . $out->getPageTitle() . '">');
}
But I'm really stuck on how can I insert in, say, 'og:description' tag something like {{{full name}}} + {{{age}}} ?
That's simply not possible, and I would wonder what your use case here would be, why you want to do that. First some explanation, why this is not possible in the way you want to achieve that:
The template is evaluated by a piece of software we call the Parser. The parser is generating a html representation of your wikitext, including all the templates and so on. The result of that is then saved in the ParserOutput and probably cached in ParserCache (so that not every time it needs to be parsed again).
However, the skin, where you want to add the head item, is using the output of the parser directly, so it does not really know about the wikitext (including template parameters) anymore, and really shouldn't.
One possible solution for what you want to achieve is probably to extend the wikitext markup language by providing a tag extension, parsing that during the parsing of the wikitext, and save the values for the head items in the database. During the output of the page you can then retrieve these values from the database again and add them into the head items like you want. See more information about that in the documentation.
There might be other ways, apart from the database, to get information from the parsing time into the output time, which I'm not aware of.

How to POST via REST a correct markup to a confluence page?

How to post topic in correct wiki syntax when body has "\r\n" which means "carriage return" and "newline"?
When I use data=json.dumps(%topic_body%) it makes all my text with literally "\r\n" in it!
Of course text formatted like this - cannot be used as wiki formatted on confluence!
This is an example of usual markup:
h1. Some Description
[Some link|Link...] is ...
h2. Some
h2. Some Versions
* 9
* 10
* 11
h1. Some Software
||Table 1 ||Block 1||Some||Some 2||
This is how it reproduces via json:
{"storage": {"value": "b'h1. Some Description\\r\\n[Some link|Link...] is ...\\r\\n\\r\\nh2. Some\\r\\n\\r\\nh2. Some Versions\\r\\n* 9\\r\\n* 10\\r\\n* 11\\r\\n\\r\\nh1. Some Software \\r\\n\\r\\n||Table 1 ||Block 1||Some||Some 2||'", "representation": "wiki"}}}
This is important, and I can't send body in markdown because my confluence did not understand this way of macros:
<ac:structured-macro ac:name="attachments">
</ac:structured-macro>
So I need to send my topic body that way, which can include new line method (https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html)
Also I can't use documented:
Explicitly, by entering two consecutive backslashes: \\
Because in this condition wiki markup make all text the same forematted, just like:
h1. Some Description \\ \\ [Some link|Link...] is ...
This whole string will be "h1." size. All all other text from this string will be formatted as h1, ignoring any other tags.
Fixed!
You can ignore the case, when visual(in browser) wiki markdown does not work for you. It will work via REST anyway!

REGEX in mysql table containing html data

I have a table that stores html templates in a mysql database. Now I have to perform some text replacement on them. However my target text is also present in some of the anchor tags and I don't want that to be replaced.
EX :
<body> ... (has huge html crap)... .........(Some more html crap) ... (a bit more of html crap) ... </body>
Task is to replace the occurrences of the "KEYWORD" with "NEW KEYWORD" in the body but not the urls.
It would also be helpful if I can first find such cases where the KEYWORD is a part of a link in a given template.
MySQL is not capable of such advanced string manipulation.
However, if you were to have a one-time-use PHP script do the editing (ie. select from the table, for each row process and update), you can do this:
// foreach row as $row
$newtext = preg_replace("(<a\b.*?>(*SKIP)(*FAIL)|KEYWORD)","NEW KEYWORD",$row['data']);
What this does is look for links (very approximate Regex but should suffice in almost all cases here), then skip over them. Then, it looks for KEYWORD and replaces it with NEW KEYWORD.
You can use this to quickly and easily handle the replacement.
If that "almost all cases" thing above turns out to not be enough, you can use DOMDocument to load the HTML into a parser and process text nodes only from there.
Maybe you could find the cases where the KEYWORD is a part of a link with something like this:
SELECT * FROM tbl WHERE html REGEXP '<a[^>]*KEYWORD';

How can I transform some HTML fragment into XHTML using groovy?

I have an input String containing some HTML fragment like the following example
I would have enever thought that <b>those infamous tags</b>,
born in the <abbr title="Don't like that acronym">SGML</abbr> realm,
would make their way into the web of objects that we now experience.
Obviously, real one is by far more complex (including links, iamges, divs, and so on), and I would like to write a method having the following prototype
String toXHTML(String html) {
// What do I have to write here ?
}
Without a description of the input format, it will probably be some html-like stuff.
Parsing such a mess gets ugly quickly. But it looks like someone else did a good job already:
#!/usr/bin/env groovy
#Grapes(
#Grab(group='jtidy', module='jtidy', version='4aug2000r7-dev')
)
import org.w3c.tidy.*
def tidy = new Tidy()
tidy.parse(System.in, System.out)
Use the force, Riduidel.
Check out this: http://blog.foosion.org/2008/06/09/parse-html-the-groovy-way/
It might be something you are looking for.

Converting digits, generated by weblog service, to Arabic form

sorry if this is irrelevance :-)
I need to write something in my html code to convert digits of form 0123456789 to ۰۱۲۳۴۵۶۷۸۹ (Persian digits uni06F0..uni06F9).
the number of visitors is generated by blog service. and I want to convert its digits to Arabic.
Counter:
تعداد بازدیدکنندگان : <BlogSky:Weblog Counter /> نفر
the Persian part of above code mean 'Number of visitors' and 'Persons' (from left to right). but digits are represented in latin (0123...).
Is it possible to write something like a function in html? i want it to be a global one for using in weblogs.
Note: I don't know anything about web programming languages. I'm not sure about language of above code. (html?)
HTML only describes the structure of the document. You'll have to use JavaScript - a client-side language that allows you to do what you need, ie manipulate DOM tree - in that case.
Here you've got an example of code that replaces 0...9 into ۰...۹ in given String:
myString.replace(/\d/g, function(matches) {
return String.fromCharCode("\u06F0".charCodeAt(0) + (matches[0] * 1));
})
So basically what you need now is to fetch text from document and replace it by itself but modified with above code:
//HTML
<p id="digits">0123456789</p>
//JavaScript:
var text = document.getElementById("digits").firstChild;
text.nodeValue = text.nodeValue.replace(/\d/g, function(matches) {
return String.fromCharCode("\u06F0".charCodeAt(0) + (matches[0] * 1));
});