Setting EnableHipHopSyntax to True with HHVM - hhvm

When I run my code, I get the following error:
Syntax only allowed with -v Eval.EnableHipHopSyntax=true in /var/web/site/myfile.php on line 26
myfile.php has a function at that line that has:
public static function set (
string $theme // <str> The theme to set as active.
, string $style = "default" // <str> The style that you want to set.
, string $layout = "default" // <str> The layout that you want to assign.
): string // RETURNS <str>
The bottom line, ): string" is the appropriate syntax for the hack language, but for some reason HHVM decided to brilliantly disable its own syntax by default.
I can't seem to find any documentation with HHVM that indicates how to set that config file. How can one go about this process?
Edit:
It turns out my HHVM conversion tool was not converting <?php to <?hh as I had instructed it to, due to having converted itself. In other words, it was attempting to convert <?hh to <?hh, which did me no good.
I had mistakenly assumed that HHVM was disabling it for <?hh tags, which was not the case.

This syntax is part of Hack, but you have a PHP file. If you change the opening tag from <?php to <?hh, it'll work.
Alternatively, you can add hhvm.enable_hip_hop_syntax = true to /etc/hhvm/php.ini.

Related

LibreOffice: embed script in script URL

In LibreOffice, It is possible to run python scripts like this:
sURL = "vnd.sun.star.script:file.function?language=Python&location=document"
oScript = scriptProv.getScript(sURL)
x = oScript.Invoke(args, Array(), Array())
In that example 'file' is a filename, and 'function' is the name of a function in that file.
Is it possible to embed script in that URL? sURL="vnd.." & scriptblock & "?language.."
(It seems like the kind of thing that might be possible with the correct URL, or might not be possible if just not supported).
We can use Python's eval() function. Here is an example inspired by JohnSUN's explanation in the discussion. Note: xray() uses XrayTool to show output, but you could replace that line with any output method of your choosing, such as writing to a file.
def runArbitraryCode(*args):
url = args[0]
codeString = url.split("&codeToRun=")[1]
x = eval(codeString)
xray(x)
Now enter this formula in Calc and Ctrl+click on it.
=HYPERLINK("vnd.sun.star.script:misc_examples.py$runArbitraryCode?language=Python&location=user&codeToRun=5+1")
Result: 6
Obligatory caveat: Running eval() on an unknown string is about the worst idea imaginable in terms of security. So hopefully you're the one controlling the URL and not some black hat hacker!

F# FSI - Is there a limit to the script length? String Literal appears too long

On transferring a F# file -- Jira.fs to a script file -- Jira.fsx
I am encountering a problem with a constant string that uses triple quotes and within it contains double quotes (example below)
Jira.fs = success
Jira.fsx = fails with error FS0010: Unexpected symbol ':' in expression. Expected '}' or other token.
Warnings include - Warning: line too long, ignoring some characters
Is there a limit to .fsx scripts?
If so is there a recommended way around this? Just read in the string from a file?
Code below: thanks
[<Literal>]
let childIssueSchema = """ {"expand":"renderedFields,names,schema,transitions,operations,editmeta,changelog","id":"18043","self":"https://atlassian.au.MyCompany.net/jira/rest/api/latest/issue/18043","key":"DPMITPRODU-141","fields":{"progress":{"progress":0,"total":0},"summary":"APC - Calculator link on AOL ","customfield_10560":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/customFieldOption/10340","value":"Yes","id":"10340"},"customfield_11067":null,"timetracking":{},"customfield_11066":null,"issuetype":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issuetype/6","id":"6","description":"A user story","iconUrl":"https://atlassian.au.MyCompany.net/jira/images/icons/sales.gif","name":"User Story","subtask":false},"customfield_10562":null,"customfield_11069":null,"customfield_11068":null,"customfield_11160":"4837","customfield_11161":null,"customfield_11660":null,"timespent":null,"reporter":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/user?username=lkaligotla","name":"lkaligotla","emailAddress":"lkaligotla#MyCompany.com.au","avatarUrls":{"16x16":"https://atlassian.au.MyCompany.net/jira/secure/useravatar?size=small&avatarId=10102","48x48":"https://atlassian.au.MyCompany.net/jira/secure/useravatar?avatarId=10102"},"displayName":"Lakshmi Kaligotla","active":true},"created":"2013-12-31T14:39:09.457+1100","updated":"2014-01-02T09:32:57.023+1100","customfield_10041":null,"priority":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/priority/3","iconUrl":"https://atlassian.au.MyCompany.net/jira/images/icons/priority_major.gif","name":"Medium","id":"3"},"description":"The current Age pension Calculator Icon must lead to a landing page with content and Start Calculator Button \r\n\r\nOn Click of start Calculator button calculator Home Page with instructions and start calculator button ","customfield_10002":null,"customfield_10003":null,"customfield_10040":null,"issuelinks":[{"id":"13177","self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issueLink/13177","type":{"id":"10010","name":"CrossProjectLink","inward":"part of","outward":"contains","self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issueLinkType/10010"},"inwardIssue":{"id":"18036","key":"DPMITPROJ-35","self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issue/18036","fields":{"summary":"APC - Calculator","status":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/status/10003","description":"User has placed this item in the queue","iconUrl":"https://atlassian.au.MyCompany.net/jira/images/icons/status_visible.gif","name":"In Queue","id":"10003"},"priority":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/priority/3","iconUrl":"https://atlassian.au.MyCompany.net/jira/images/icons/priority_major.gif","name":"Medium","id":"3"},"issuetype":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issuetype/5","id":"5","description":"A big user story that needs to be broken down.","iconUrl":"https://atlassian.au.MyCompany.net/jira/download/resources/com.pyxis.greenhopper.jira:greenhopper-webactions/images/ico_epic.png","name":"Epic","subtask":false}}}}],"customfield_10000":null,"customfield_10765":null,"subtasks":[],"customfield_10767":null,"status":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/status/10016","description":"","iconUrl":"https://atlassian.au.MyCompany.net/jira/images/icons/status_open.gif","name":"Backlog","id":"10016"},"labels":[],"workratio":-1,"project":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/project/DPMITPRODU","id":"11433","key":"DPMITPRODU","name":"DPMIT-Products","avatarUrls":{"16x16":"https://atlassian.au.MyCompany.net/jira/secure/projectavatar?size=small&pid=11433&avatarId=11680","48x48":"https://atlassian.au.MyCompany.net/jira/secure/projectavatar?pid=11433&avatarId=11680"}},"environment":null,"customfield_10053":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/customFieldOption/10030","value":"Yes","id":"10030"},"aggregateprogress":{"progress":0,"total":0},"customfield_10050":"A link is available and on click leads to Calculor Landing page\r\nhttps://adviseronlineportal.com.au/Agepensioncalculator","components":[],"comment":{"startAt":0,"maxResults":0,"total":0,"comments":[]},"timeoriginalestimate":null,"customfield_10461":null,"customfield_10460":null,"customfield_11963":[{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/customFieldOption/11441","value":"False","id":"11441"}],"customfield_10360":null,"votes":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issue/DPMITPRODU-141/votes","votes":0,"hasVoted":false},"customfield_10261":null,"customfield_10262":null,"customfield_10263":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/customFieldOption/10061","value":"Yes","id":"10061"},"fixVersions":[],"resolution":null,"resolutiondate":null,"aggregatetimeoriginalestimate":null,"customfield_10161":null,"customfield_10160":null,"duedate":null,"customfield_10020":null,"customfield_10060":"4793","watches":{"self":"https://atlassian.au.MyCompany.net/jira/rest/api/2/issue/DPMITPRODU-141/watchers","watchCount":1,"isWatching":false},"customfield_10162":null,"worklog":{"startAt":0,"maxResults":0,"total":0,"worklogs":[]},"assignee":null,"attachment":[],"aggregatetimeestimate":null,"versions":[],"timeestimate":null,"customfield_10030":null,"customfield_10031":null,"aggregatetimespent":null}} """
type ChildJsonSchema = FSharp.Data.JsonProvider< childIssueSchema >
I don't think there is a limit on the size of a script file (not sure what would happen around 2GB, but that does not sound like a realistic scenario), but for some reason (not sure why!) there is a limit on a single line length.
This is a bit unfortunate when you just want to copy & paste sample for a JSON type provider, but if you're using """ quotes, then you can just have a newline character in the string and it will still be treated as a single constant string:
[<Literal>]
let childIssueSchema = """{"foo":1,
"bar":42}"""
type ChildJsonSchema = FSharp.Data.JsonProvider<childIssueSchema>
That said, in case you have long and complex samples, it might be better to save them to files and just point the type provider to a file. Assuming you have childIssue.json in the same folder as the source file, you should be able to write:
type ChildJsonSchema = FSharp.Data.JsonProvider<"childIssue.json">

How to rectify "Document was used before it was defined" using Jslint

I get the following error in jsLint:
'document' was used before it was defined.
Line that causes the error:
document.cookie = name + "=" + value + expires + "; path=/";
I get why this happens, but I would like my code to be compliant.
How do I resolve this?
Thanks.
Place
/*jslint browser:true */
in the beginning of the body of your function. Or, alternatively, you may use
/*global document: false */
JSLint is for the checking of any javascript code, and the document global object does not exists everywhere, so you have to manually tell JSLint that your code is aimed to be executed in browser, and thus document global variable is defined. For example, for server-side javascript it is expected for JSLint to report about this error.
From jslint's website, you can read about a /global/ directive that allows you to set variables that are assumed to be declared elsewhere.
Here is an example (put this at the top of the file):
/\*global var1,var2,var3,var4,var5\*/
or, in starjava's case:
/\*global document\*/
I'm not actually sure if the :true or :false is needed, but it looks like it's recommended from what I read on the site. http://www.jslint.com/lint.html
Make sure the initial global statement is on the same line as '/\*', or else it breaks.
If all your JS code is supposed to be run from browser then just the add the --browser flag.
jslint --browser my.js
if you are using node can add the following line
/ * node JSLint: true * /
at the start of the script
http://jslinterrors.com/a-was-used-before-it-was-defined/
In cli mode you can use config file:
jslint.conf
{
"predef": [
"module",
"require",
"window",
"document",
"jQuery",
"Backbone",
"Marionette",
"Modernizr",
"_",
"setTimeout",
"clearTimeout",
"setInterval",
"clearInterval"
],
"evil":false,
"indent":4,
"vars":true,
"passfail":false,
"plusplus":false
}
And use jslint with --config jslint.conf parameter.

How do I make sure that a directory name is quoted in OMake?

I have a relatively complicated suite of OMake files designed for cross-compiling on a specific platform. My source is in C++.
I'm building from Windows and I need to pass to the compiler include directories which have spaces in their names. The way that the includes string which is inserted in the command line to compile files is created is by the line:
public.PREFIXED_INCLUDES = $`(addprefix $(INCLUDES_OPT), $(set $(absname $(INCLUDES))))
At some other point in the OMake files I have a line like:
INCLUDES += $(dir "$(LIBRARY_LOCATION)/Path with spaces/include")
In the middle of the command line this expands to:
-IC:\Library location with spaces\Path with spaces\include
I want it to expand to:
-I"C:\Library location with spaces\Path with spaces\include"
I don't want to change anything but the "INCLUDES += ..." line if possible, although modifying something else in that file is also fine. I don't want to have to do something like change the definition of PREFIXED_INCLUDES, as that's in a suite of OMake files which are part of an SDK which may change beneath me. Is this possible? If so, how can I do it? If not, in what ways can I make sure that includes with spaces in them are quoted by modifying little makefile code (hopefully one line)?
The standard library function quote adds escaped quotes around its argument, so it should do the job:
INCLUDES += $(quote $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))
If needed, see quote in Omake manual.
In case someone else is having the same problem, I thought I'd share the solution I eventually went with, having never figured out how to surround with quotes. Instead of putting quotes around a name with spaces in it I ended up converting the path to the short (8.3) version. I did this via a a simple JScript file called shorten.js and a one line OMake function.
The script:
// Get Access to the file system.
var FileSystemObject = WScript.CreateObject("Scripting.FileSystemObject");
// Get the short path.
var shortPath = FileSystemObject.GetFolder(WScript.Arguments(0)).ShortPath;
// Output short path.
WScript.StdOut.Write(shortPath);
The function:
ShortDirectoryPath(longPath) =
return $(dir $(shell cscript /Nologo $(dir ./tools/shorten.js) "$(absname $(longPath))"))
So now I just use a line like the following for includes:
INCLUDES += $(ShortDirectoryPath $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))

xcode info.plist build variable ${PRODUCT_NAME:rfc1034identifier} seems completely undocumented?

I'm trying to find documentation that describe the syntax and possibilities suggested by the construction ${PRODUCT_NAME:rfc1034identifier}. Obviously this turns into some version of the product name, but where is the documentation that describes how? I just grepped the entire /Developer directory, and got nothing useful.
I'm not looking for the narrow definition of what happens to this particular variable, I want to know about all such modifiers like rfc1034identifier.
By using strings I also dug out the following things that look like they're related to :rfc1034identifier:
:quote - adds backslashes before whitespaces (and more), for use in shell scripts
:identifier - replaces whitespace, slashes (and more) with underscores
:rfc1034identifier - replaces whitespace, slashes (and more) with dashes
:dir - don't know, observed replace with ./ in some cases
:abs - don't know
Exact command:
strings /Developer/Library/PrivateFrameworks/DevToolsCore.framework/Versions/A/DevToolsCore|grep '^:'
There are more things that look like interesting modifiers (for example, :char-range=%#), but I couldn't get these to work. There's only one example of :char-range on the net, and it's from a crash log for Xcode.
Someone asked how do we know it's a modifier specification. Well, we know because it works on multiple variables in build settings. Plist preprocessor probably uses the same mechanisms to resolve build variables as does the build system.
Hack Saw, if you get a response via that bug report, don't forget to keep us informed :-)
Looks like you can stack these as well. The useful case floating around out there is
com.yourcompany.${PRODUCT_NAME:rfc1034identifier:lower}
such that a product name of "Your App" becomes com.yourcompany.your-app.
At long last, Apple produced some documentation on this. This is in the "Text Macros" section of the Xcode manual, as of this date.
Text macro format reference
A text macro can contain any valid unicode text. It can also contain other text macros.
Including other text macros
To include another text macro, add three underscore (_) characters before and after the macro name:
___<MacroName>___
Modifying text macro expansion
You can modify the final expansion of the text macro by adding one or more modifiers. Add a modifier to a text macro by placing a colon (:) at the end of the macro followed by the modifier. Add multiple modifiers by separating each one with a comma (,).
<MACRO>:<modifier>[,<modifier>]…
For example, the following macro will remove the path extension from the FILENAME macro:
FILENAME:deletingPathExtension
To turn the modified macro above into a valid C identifier, add the identifier macro:
FILENAME:deletingPathExtension,identifier
Modifiers
bundleIdentifier: Replaces any non-bundle identifier characters with a hyphen (-).
deletingLastPathComponent: Removes the last path component from the expansion string.
deletingPathExtension: Removes any path extension from the expansion string.
deletingTrailingDot: Removes any trailing dots (.).
identifier: Replaces any non-C identifier characters with an underscore (_).
lastPathComponent: Returns just the last path component of the expansion string.
pathExtension: Returns the path extension of the expansion string.
rfc1034Identifier: Replaces any non-rfc1034 identifier characters with a hyphen (-).
xml: Replaces special xml characters with the corresponding escape string. For example, less-than (<) is replaced with <
TEXT MACROS
Text macros reference
COPYRIGHT
A copyright string that uses the company name of the team for the project. If there is no company name, the string is blank.
The example shows a copyright string when the company is set to “Apple”.
Copyright © 2018 Apple. All rights reserved.
DATE
The current date.
DEFAULTTOOLCHAINSWIFTVERSION
The version of Swift used for the default toolchain.
FILEBASENAME
The name of the current file without any extension.
FILEBASENAMEASIDENTIFIER
The name of the current file encoded as a C identifier.
FILEHEADER
The text placed at the top of every new text file.
FILENAME
The full name of the current file.
FULLUSERNAME
The full name of the current macOS user.
NSHUMANREADABLECOPYRIGHTPLIST
The entry for the human readable copyright string in the Info.plist file of a macOS app target. The value of the macro must include the XML delimiters for the plist. For example, a valid value is:
'''
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 Apple, Inc. All rights reserved.</string>
'''
Notice that the value includes a newline.
ORGANIZATIONNAME
The name for your organization that appears in boilerplate text throughout your project folder. The organization name in your project isn’t the same as the organization name that you enter in App Store Connect.
PACKAGENAME
The name of the package built by the current scheme.
PACKAGENAMEASIDENTIFIER
A C-identifier encoded version of the package name built by the current scheme.
PRODUCTNAME
The app name of the product built by the current scheme.
PROJECTNAME
The name of the current project.
RUNNINGMACOSVERSION
The version of macOS that is running Xcode.
TARGETNAME
The name of the current target.
TIME
The current time.
USERNAME
The login name for the current macOS user.
UUID
Returns a unique ID. The first time this macro is used, it generates the ID before returning it. You can use this macro to create multiple unique IDs by using a modifier. Each modifier returns an ID that is unique for that modifier. For example, the first time the UUID:firstPurpose modifier is used, the macro generates and returns a unique ID for that macro and modifier combination. Subsequent uses of the UUID:firstPurpose modifier return the same ID. Adding the UUID:secondPurpose modifier generates and returns a different ID that will be unique to UUID:secondPurpose, and different from the ID for UUID:firstPurpose.
WORKSPACENAME
The name of the current workspace. If there is only one project open, then the name of the current project.
YEAR
The current year as a four-digit number.
$ strings /Developer/Library/PrivateFrameworks/DevToolsCore.framework/Versions/A/DevToolsCore
PRODUCTNAME
PRODUCTNAMEASIDENTIFIER
PRODUCTNAMEASRFC1034IDENTIFIER
PRODUCTNAMEASXML
It seems that there are :identifier, :rfc1034identifier and :xml modifiers. But I have no clue except this.
After stumbling over this question and its existing answers, I have to say: Apples documentation did not improve on this topic over the recent years. We are currently at Xcode 13 and there is still no complete list of all modifiers available.
Therefore I did some spelunking and found the supported modifiers in DVTFoundation.framework which I will list below.
I've tested them all in Xcode 13.3 build settings and used the following two macros to illustrate their impact:
MY_MACRO = Some "text" with umlauts äöüçñ and special characters are ',/|\-_:;%&<>.!
MY_SOURCE = /Applications/Xcode.app/Contents/Frameworks/../SharedFrameworks/DVTFoundation.framework
Retrieval operators/modifiers
Retrieval modifiers are used to extract and/or transform all or parts of a macro/variable/setting.
They are applied using the following syntax: $(<VARIABLE>:<MODIFIER>)
quote: Escapes all characters which have a special meaning in shell scripts/commands like space, colon, semicolon and backslash.
RESULT_quote = $(MY_MACRO:quote)
Some\ \"text\"\ with\ umlauts\ äöüçñ\ and\ special\ characters\ are\ \',/|\\-_:;%&<>.!
upper: Transforms all characters to their uppercase equivalents.
RESULT_upper = $(MY_MACRO:upper)
SOME "TEXT" WITH UMLAUTS ÄÖÜÇÑ AND SPECIAL CHARACTERS ARE ',/|\-_:;%&<>.!
lower: Transforms all characters to their lowercase equivalents.
RESULT_lower = $(MY_MACRO:lower)
some "text" with umlauts äöüçñ and special characters are ',/|\-_:;%&<>.!
identifier: Replaces any non-C identifier characters with an underscore (_).
RESULT_identifier = $(MY_MACRO:identifier)
Some__text__with_umlauts_______and_special_characters_are________________
rfc1034identifier: Replaces any non-rfc1034 identifier characters with a hyphen (-)
RESULT_rfc1034identifier = $(MY_MACRO:rfc1034identifier)
Some--text--with-umlauts-------and-special-characters-are----------------------------
c99extidentifier: Replaces any non-C99 identifier characters with an underscore (_). Umlauts are allowed as C99 uses Unicode!
RESULT_c99extidentifier = $(MY_MACRO:c99extidentifier)
Some__text__with_umlauts_äöüçñ_and_special_characters_are___________________________
xml: According to Apple documentation it should replace special xml characters with the corresponding escape string. For example, less-than (<) is replaced with <. But in my examples this didn't work.
RESULT_xml = $(MY_MACRO:xml)
Some "text" with umlauts äöüçñ and special characters are ',/|\-_:;%&<>.!
dir: Extracts the directory part of a path
RESULT_dir = $(MY_SOURCE:dir)
/Applications/Xcode.app/Contents/Frameworks/../SharedFrameworks/
file: Extracts the filename part of a path
RESULT_file = $(MY_SOURCE:file)
DVTFoundation.framework
base: Extracts the filename base part of a path (=filename without suffix/extension)
RESULT_base = $(MY_SOURCE:base)
DVTFoundation
suffix: Extracts the filename extension/suffix a path or filename
RESULT_suffix = $(MY_SOURCE:suffix)
.framework
standardizepath: Standardizes the path (e.g. ../ and tilde (~) are resolved)
RESULT_standardizepath = $(MY_SOURCE:standardizepath)
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework
Replacement operators/modifiers
Beside above extracting/transforming operators, there is support built into the build settings system to replace specific parts of a directory which are matched using a modifier.
They are applied using the following syntax: $(<VARIABLE>:<MODIFIER>=<VALUE>)
dir=<VALUE>: Replaces the directory part of a path with <VALUE> and returns the new path
RESULT2_dir = $(MY_SOURCE:dir=/Developer/SharedFrameworks)
/Developer/SharedFrameworks/DVTFoundation.framework
file=<VALUE>: Replaces the filename part of a path and returns the new path
RESULT2_file = $(MY_SOURCE:file=my_file.txt)
/Applications/Xcode.app/Contents/Frameworks/../SharedFrameworks/my_file.txt
base=<VALUE>: Replaces the filename base part of a path (=filename without suffix/extension) and returns the new path
RESULT2_base = $(MY_SOURCE:base=Dummy)
/Applications/Xcode.app/Contents/Frameworks/../SharedFrameworks/Dummy.framework
suffix=<VALUE>: Replaces the filename extension/suffix a path and returns the new path
RESULT2_suffix = $(MY_SOURCE:suffix=.txt)
/Applications/Xcode.app/Contents/Frameworks/../SharedFrameworks/DVTFoundation.txt
I hope this list will help more people looking at Xcodes build settings and wondering how they can be transformed.

Resources