Apologies if this has been asked before but i could not find a straightforward answer.
I have the following code, the application is a third party so the incoming $supernet is provided as a string. So what i am wanting to do it take a IP address and then manipulate it to create a list of subnets based on a template.
#set ($Supernet = "10.10.10.10")
#set ($octs = $Supernet.split("\."))
#set ($netmgmt[2] = "$octs[0].$octs[1].$octs[2].$octs[2]+1")
$netmgmt
But this as I expect gives the result "10.10.10.10+1"
I figured out I can do this in a longhand way
convert the $oct[2] to an integer and store in a variable
create a temporary variable and store the result of the converted $oct[2] + 1
Then use this to create the string
like
$Integer = $convert.toInteger($oct[2])
#set ($newoct = $Integer + 1)
#set ($netmgmt[2] = "$octs[0].$octs[1].$octs[2].$newoct")
but i have a lot of these to create and this will get long winded and confusing.
So i am trying to work out if I can write #set ($octs = $Supernet.split(".")) to store as integers. To be honest just trying to directly convert each array value to int does not seem to work as based on what i have found on line. I expected the below would result in "$oct1 = 10" but it does not?
#set ($Supernet = "10.10.10.10")
#set ($octs = $Supernet.split("\."))
#set ($oct1 = $convert.toInteger($oct[0])
New to Velocity any help appreciated.
You should check which version of Velocity-Tools you are using, and which tools are available in the provided context.
Since Velocity-Tools 3.1, for instance, $convert.toInteger() has been deprecated in favor of $math.toInteger(). You can check if those tools are present in the context just by displaying $convert and $math.
The following code works for me with Velocity 1.7 + Tools 2.0, as long as with Velocity 2.X + Tools 3.x:
#set ($Supernet = "10.10.10.10")
#set ($octs = $Supernet.split('\.'))
#set ($last = $math.toInteger($octs[2]) - 1)
#set ($ip = "${octs[0]}.${octs[1]}.${octs[2]}.$last")
$ip
Related
Hi I have a little problem with this plugin, this is the code that makes an error
Sheet::macro('setPageMargins', function (Sheet $sheet, float $top = 1, float $right = 0.75, float $bottom = 1, float $left = 0.75) {
$sheet->getDelegate()->getPageMargins()->setTop($top);
$sheet->getDelegate()->getPageMargins()->setRight($right);
$sheet->getDelegate()->getPageMargins()->setLeft($left);
$sheet->getDelegate()->getPageMargins()->setBottom($bottom);
});
Here is the error
Argument 1 passed to
PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::setPageMargins() must be
an instance of PhpOffice\PhpSpreadsheet\Worksheet\PageMargins, float
given
and I just following this documentation https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#page-margins with using maatwebsite\Excel, by the way i'm using Laravel 5.7.
The question is how to set the margin? because I think the documentation is wrong, please help
I believe you should be doing:
// Create a page margins object.
$pageMargins = new \PhpOffice\PhpSpreadsheet\Worksheet\PageMargins();
$pageMargins->setTop(1);
$pageMargins->setRight(0.75);
$pageMargins->setBottom(1);
$pageMargins->setLeft(0.75);
Sheet::macro('setPageMargins', function($sheet, $pageMargins));
According to the code, it says public function setPageMargins(PageMargins $pValue).
(https://github.com/PHPOffice/PhpSpreadsheet/blob/0e8fde9be6d3918ffe030bed0ba0297bfe330c4d/src/PhpSpreadsheet/Worksheet/Worksheet.php#L966)
Your ::macro calls the setPageMargins function, although this pattern confuses me (it appears to be some Maatwebsite\Excel thing).
I'm using Mapnik v2.2.0 from Python 2.7 in an Ubuntu 16.04 environment. The application generates maps with a set of MarkerSymbolizers at various coordinates. In one map, when the MarkerSymbolizers are set to 25x25 pixels, one of the markers does not appear. If the marker size is set to 15x15, all of the markers appear.
The markers are loaded from a csv file:
layer = mapnik.Layer('GPS_tracking_points')
layer.datasource = mapnik.CSV(file=leak_file_name, layer_by_index=0)
The styling is below:
point_style = mapnik.Style()
point_rule = mapnik.Rule()
point_filter = mapnik.Filter ("[val] > 10")
point_rule.filter = point_filter
point_point_symbolizer = mapnik.MarkersSymbolizer()
point_point_symbolizer.width = mapnik.Expression ('25')
point_point_symbolizer.height = mapnik.Expression ('25')
point_point_symbolizer.fill = mapnik.Color ('#ff0000')
point_point_symbolizer.allow_overlap = True
point_point_symbolizer.opacity = 0.5 # semi-transparent
point_rule.symbols.append(point_point_symbolizer)
point_style.rules.append(point_rule)
map_canvas.append_style('high', point_style)
Screenshots are below.
Any help is appreciated.
Thanks.
The problem appears to be related to the way Mapnik 2.2 handles styling in code vs xml. I moved the styling specification to an xml file and everything works as expected.
The answer was found here: https://github.com/mapnik/python-mapnik/issues/117
I want to set Windows Width/ Windows Center value when use vtkImageActor/vtkActor. But I could not find the way to solve it.
(If I use vtkActor2d, it's okay, but I don't want to use it)
Attach a vtkWindowLevelLookupTable to your mapper.
Basic Example:
vtkSmartPointer<vtkWindowLevelLookupTable> myLookupTable =
vtkSmartPointer<vtkWindowLevelLookupTable>::New();
double WindowWidth = myImageReader->GetOutput()->GetScalarRange()[1] -
myImageReader->GetOutput()->GetScalarRange()[0];
double WindowLevel = (myImageReader->GetOutput()->GetScalarRange()[1] +
myImageReader->GetOutput()->GetScalarRange()[0]) / 2.0;
myLookupTable->SetWindow(WindowWidth);
myLookupTable->SetLevel(WindowLevel);
myMapper->SetLookupTable(myLookupTable);
I've been playing around of this issue for awhile now and can't get my head wrapped around of it. I'm using Liferay 6.1 CE GA2.
Goal:
User editable content, for example footer in each page. I've created the web content which id is 12701.
Method:
#set ($local_temp_content = $journalContentUtil.getContent($scope_group_id, "12701", null, "$locale", $theme_display))
$local_temp_content<br />
Issue:
It won't return anything sensible. It's just printing "$local_temp_content" as the result.
Any pointers how to debug this issue?
This is a velocity macro to retrieve a web content by ID from local scope first and then by global scope:
#macro(glarticle $temp_article_id)
#set ($temp_content = "")
#set ($scope_group_id = $theme_display.scopeGroupId)
#set ($global_group_id = $theme_display.companyGroupId)
#set ($temp_content = $journalContentUtil.getContent($scope_group_id, $temp_article_id, null, "$locale", $theme_display))
#set ($temp_content = "$!{temp_content}")
#if ($temp_content.length() == 0)
#set ($temp_content = $journalContentUtil.getContent($global_group_id, $temp_article_id, null, "$locale", $theme_display))
#end
$!{temp_content}
#end
How to use it:
#glarticle('1234')
For debugging velocity try outputting every part of your call.
scope_group_id = $scope_group_id<br>
theme_display = $theme_display<br>
journalContentUtil = $journalContentUtil<br>
If you get exactly what you wrote than that variable is not available.
If all are resolved then possibilitis are:
wrong article id
there was exception during article rendering (you should check log)
I am using liferay 6.1.20.
Structure variable demo_image : type Document and Media
here is my template code. It is not fetching uuid or groupId from url !
#set ($dlLocalService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLAppLocalService"))
#set ($url = $getterUtil.getString($demo_image.getData()))
#set ($uuid = $getterUtil.getString($httpUtil.getParameter($url, "uuid", false)))
#set ($groupId = $getterUtil.getLong($httpUtil.getParameter($url, "groupId", false)))
#set ($imageObj = $dlLocalService.getFileEntryByUuidAndGroupId($uuid,$groupId))
#set ($imageSmallid = $imageObj.getSmallImageId())
#set ($imageLargeid = $imageObj.getLargeImageId())
#set ($imageTitle = $imageObj.getTitle())
#set ($imageDescription = $imageObj.getDescription())
#set ($urlLargeImage = "/documents/imageLargeid")
#set ($urlSmallImage = "/documents/imageSmallid")
$imageTitle
<img src="$urlSmallImage" rel="$imageTitle" alt="$imageTitle" />
Check value of $url for your image, does this URL contain uuid & groupId if yes you should get the values. else if url contains imageId try using different method from service util.
Also try using DLFileEntryLocalService instead of DLAppLocalService
Hope this helps you find your solution !