Add node CATEGORIES to vcard with perl module "vCard::AddressBook" - perl

I do not find a possibility to add nodes like CATEGORIES or ORG to a vcard object when using the perl module vCard::AddressBook (https://metacpan.org/pod/vCard::AddressBook).
The output should look like this:
BEGIN:VCARD
VERSION:4.0
...
N:Doe;John;;;
...
ORG:Organization_01;
CATEGORIES:Cat_01
...
END:VCARD
When I use the following code:
use vCard::AddressBook;
my $address_book = vCard::AddressBook->new();
my $vcard = $address_book->add_vcard;
$vcard->given_names(['John']);
$vcard->family_names(['Doe']);
$vcard->categories(['Cat_01']); ## DOES NOT WORK
my $file = $address_book->as_file('file.vcf');
I get the following error:
Can't locate object method "categories" via package "vCard" at tmp2.pl line 6.
What is the best way to get other nodes like CATEGORIES in my vcard file?
BTW: RFC6350 defines it... https://www.rfc-editor.org/rfc/rfc6350#section-6.7.1

There is https://metacpan.org/pod/Text::vCard::Precisely which seems to be more compliant with RFC6350:
use Text::vCard::Precisely;
my $vcard = Text::vCard::Precisely->new( version => '4.0' );
$vcard->n(['John','Doe']);
$vcard->categories([qw/Cat_01 Cat_02 Cat_03/]);
print $vcard->as_string();
prints:
BEGIN:VCARD
VERSION:4.0
N:John;Doe;;;
CATEGORIES:Cat_01,Cat_02,Cat_03
END:VCARD

Related

object not found when creating targets list programmatically

I'm trying to generate a {targets} list programmatically, via a function in an R package.
get_pipeline <- function(which_countries) {
countries <- NULL # avoid R CMD CHECK warning
print(which_countries) # Shows that which_countries is available
list(
targets::tar_target(
name = countries,
command = which_countries # But here, which_countries is not found
)
)
}
The _targets.R file looks like this:
library(targets)
couns <- c("USA", "GBR")
TargetsQuestions::get_pipeline(couns)
I see the following error:
> tar_make()
[1] "USA" "GBR"
Error in enexpr(expr) : object 'which_countries' not found
Error in `tar_throw_run()`:
! callr subprocess failed: object 'which_countries' not found
Note that the which_countries variable is printable, but not found in the call to tar_target.
How can I get create the countries target successfully so that it contains the vector c("USA", "GBR")?
This code is in a GitHub repository at https://github.com/MatthewHeun/TargetsQuestions. To reproduce:
git clone https://github.com/MatthewHeun/TargetsQuestions
Build the package in RStudio.
targets::tar_make() at the Console.
Thanks in advance for any suggestions!
Thanks to #landau for pointing to https://wlandau.github.io/targetopia/contributing.html#target-factories which in turn points to the metaprogramming section of Advanced R at https://adv-r.hadley.nz/metaprogramming.html.
The solution turned out to be:
get_pipeline <- function(which_countries) {
list(
targets::tar_target_raw(
name = "countries",
# command = which_countries # which_countries must have length 1
# command = !!which_countries # invalid argument type
command = rlang::enexpr(which_countries) # Works
)
)
}
With _targets.R like this:
library(targets)
couns <- c("USA", "GBR")
TargetsQuestions::get_pipeline(couns)
the commands tar_make() and tar_read(countries), give
[1] "USA" "GBR"
as expected!

can't use css file zf2 (Zend\View\HelperPluginManager::get was unable to fetch or create an instance for inlineStyle)

I have a css and js files, i want to use it and call it from controller, for js these lines work perfectly:
$serverUrl = $this->baseUrl();
$headScript = $this->getServiceLocator()->get('viewhelpermanager')->get('inlineScript');
$headScript->appendFile($serverUrl . '/assets/js/file.js');
But for css when i use these lines :
$serverUrl = $this->baseUrl();
$headScript = $this->getServiceLocator()->get('viewhelpermanager')->get('inlineStyle');
$headScript->appendFile($serverUrl . '/assets/js/file.css');
i have this error:
Zend\View\HelperPluginManager::get was unable to fetch or create an instance for inlineStyle
Try to use “headLink” instead of “inlineStyle”.

breathe cannot find C# interface

I'm trying to use doxygen, breathe and sphinx to generate documentation for a C# library. This is under Windows. The basic directory structure is:
docs
index.rst
conf.py
xml
xml output from doxygen
I'm running into the following error when I execute make.bat html:
C:\Programming\J4JLogging\J4JLogging\docs\index.rst:25: WARNING: doxygeninterface: Cannot find class "IJ4JLoggerConfiguration" in doxygen xml output for project "J4JLogger" from directory: ./xml
Here's the contents of conf.py
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
project = 'J4JLogger'
copyright = '2019, Mark Olbert'
author = 'Mark Olbert'
extensions = [ "breathe" ]
breathe_projects = {
"J4JLogger": "./xml"
}
breathe_default_project = "J4JLogger"
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
and here's the contents of index.rst:
.. J4JLogger documentation master file, created by
sphinx-quickstart on Tue Jun 11 16:33:34 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to J4JLogger's documentation!
=====================================
.. toctree::
:maxdepth: 2
:caption: Contents:
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Docs
====
.. doxygeninterface:: IJ4JLoggerConfiguration
:members:
The contents of the xml folder created by doxygen looks like this:

Errors in codeigniter-restserver library

I want to use restful in my ci 3.03 application:
I found this tutplus tutorial
I downloaded codeigniter-restserver-master.zip file and copied Format.php and REST_Controller.php(#version 3.0.0) files into /application/libraries/REST directory
I created control application/controllers/api/Users.php :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
class Users extends REST_Controller
{
//protected $rest_format = 'json';
function users_get()
{
//$users = $this->user_model->get_all();
$filter_username= $this->get('filter_username');
$filter_user_group= $this->get('filter_user_group');
$filter_active= $this->get('filter_active');
$sort= $this->get('sort');
$sort_direction= $this->get('sort_direction');
//, $filter_user_group, $filter_active, $sort, $sort_direction
$users_list = $this->muser->getUsersList(false, ''/*, $filter_username, $filter_user_group, $filter_active, $sort, $sort_direction, ''*/);
echo '<pre>'.count($users_list).'::$users_lists::'.print_r($users_list,true).'</pre>';
if($users_list)
{
$this->response($users, 200);
}
else
{
$this->response(NULL, 404);
}
}
AND RUNNING URL http://local-ci3.com/api/users I got many errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 734
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 734
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 752
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 752
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
Actually I wanted to get some workable library to help me with REST api creation. I think that is preferable way istead of making from zero.
But is this library not workable or does it needs for some fixing? Sorry, what I missed is if this library only for ci 2?
I made search on this forum and found such hint :
I have the same problem when I load both Format.php and
Rest_Controller.php into a controller. After have a quick glance at
Format.php, it appears to be a standalone format conversion helper.
Try to just load Rest_Controller.php and see if your problem goes
away.
I commented line
//require_once("application/libraries/REST/Format.php");
in my controller, but I still get errors like :
Message: Undefined property: Users::$format.
I tried to review code of this library and see that invalid block when data are converted to json format, line 731-757 :
elseif ($data !== NULL)
{
// If the format method exists, call and return the output in that format
if (method_exists($this->format, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a datatype
if ($this->response->format === 'array')
{
$output = $this->format->factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = $this->format->factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}
}
If I tried to commented this block, but get error
Message: Array to string conversion
Looks like data are not converted in this case...
Is is possible to fix these errors?
Or can you, please, to tell me advice some codeigniter 3 REST api workable library with similar interface like library above?
Thanks!
I use that lib, work just fine. My suggestion is follow the more relevant installation instruction on github .
you also wrong place the lib file :
Tutorial say :
require(APPPATH'.libraries/REST_Controller.php');
You try :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
No need to include the format because on line 407 the lib will load it. And also good to know on line 404 it will load the configuration (application/config/rest.php) it will be your default configuration, and also you can change it to suit your need.
Please let me know if you still got error using my answer :)

Reading line containing multiple XML tags

I have a text file containing lines with multiple xml tags in single line.Below is the sample of it (returns and spacing added for clarity).
xmlns="http://www.opentravel.org/OTA/2003/05" EchoToken="1397133927.05244" TimeStamp="2014-04-10T07:45:27.00-05:00" Target="Production" Version="1.002" PrimaryLangID="en-us"><POS><Source><RequestorID Type="18" ID="HILTON"/></Source></POS><AvailStatusMessages ChainCode="ES" BrandCode="ES" HotelCode="41914">
<AvailStatusMessage><StatusApplicationControl Start="2014-04-20" End="2014-04-26" Sun="1" InvCodeApplication="InvCode" InvCode="U1K" RatePlanCodeType="RatePlanCode" RatePlanCode="EXL" RateTier="8" IsRoom="1" Override="1"/><LengthsOfStay ArrivalDateBased="1" FixedPatternLength="2"><LengthOfStay Time="1" TimeUnit="Day" MinMaxMessageType="FullPatternLOS"/></LengthsOfStay></AvailStatusMessage>
<AvailStatusMessage><StatusApplicationControl Start="2014-04-20" End="2014-04-26" Mon="1" Tue="1" Weds="1" Thur="1" Fri="1" Sat="1" InvCodeApplication="InvCode" InvCode="U1K" RatePlanCodeType="RatePlanCode" RatePlanCode="EXL" RateTier="8" IsRoom="1" Override="1"/><LengthsOfStay ArrivalDateBased="1" FixedPatternLength="1"></LengthsOfStay></AvailStatusMessage>
<AvailStatusMessage><StatusApplicationControl Start="2014-04-27" End="2014-05-21" Sun="1" Mon="1" Tue="1" Weds="1" Thur="1" Fri="1" Sat="1" InvCodeApplication="InvCode" InvCode="U1K" RatePlanCodeType="RatePlanCode" RatePlanCode="EXL" RateTier="8" IsRoom="1" Override="1"/><LengthsOfStay ArrivalDateBased="1"
I have tag , which contains field with StatusApplicationControl Start value . I want to get all such AvailStatusMessage tags which have StatusApplicationControl start value as "2014-04-27".
Please assist me of getting this done using perl or shell script.
Thanks in advance.
You could try the following code:
#! /usr/bin/perl
use v5.12;
use File::Slurp;
my $txt=read_file('file');
while ($txt=~m{<AvailStatusMessage>(.*?)</AvailStatusMessage>}gms) {
my $atxt=$1;
if ($atxt=~m{<StatusApplicationControl (.*?)/>}ms) {
my $tmp=$1;
if ($tmp=~m{Start="2014-04-27"}ms) {
say $atxt;
}
}
}