How to use net/xhr.getRequestCount() - firefox-addon-sdk

The documentation for the net/xhr module includes a method called getRequestCount() supposed to
Return[s] the number of XMLHttpRequest objects that are alive (i.e., currently active or about to be).
Both calling
const xhr = require("sdk/net/xhr");
var x = new xhr.XMLHttpRequest();
x.getRequestCount();
and
xhr.getRequestCount();
failed with a TypeError. In the debugger, you see that neither XMLHttpRequest nor its prototype have such function. (jpm version 1.0.5)
How are you supposed to use it?

Apparently this function was removed quite a while back(https://hg.mozilla.org/mozilla-central/rev/b57750ca97bf from 2013) and nobody remembered to update the documentation.
So in short: you're not supposed to use it.

Related

How to get result from QQuickWebEngineView::runJavaScript

I'm trying to execute javascript on QQuickWebEngineView object in c++ and get returned value. In QML it's easy
view.runJavaScript("document.documentElement.outerHTML", function(result){//do smth})
in c++ method signature for executing js is this:
void runJavaScript(const QString&, const QJSValue & = QJSValue());
and I believe I could use QJSValue to get returned data, but I'm not finding anything on how to use it... maybe someone has an example of how to use QJSValue here. Thanks.

How to replace deprecated SOBE Code in TYPO3 10.4

I inherited an old TYPO3 Extension using SOBE. As far as I unterstand it's deprecated, but it seems there is no documentation on how to replace it.
The Extension is using Backend Forms and the following line is throwing an error:
if (is_array($GLOBALS['SOBE']->editconf['tt_content']) && reset($GLOBALS['SOBE']->editconf['tt_content']) === 'new') {
The error is:
Cannot access protected property TYPO3\CMS\Backend\Controller\EditDocumentController::$editconf
The Var $GLOBALS['SOBE'] is still there, and there is also editconf, but it's not working.
How can I replace this code or rewrite it?
The SOBE object is part by part removed since years. As there are multiple ways for using it - see https://docs.typo3.org/c/typo3/cms-core/main/en-us/search.html?q=sobe&check_keywords=yes&area=default - you may need to take a closer look what is the exact part of replacing this code.
I would guess you can see more at https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.2/Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.html?highlight=editconf.

Mongoose 5.3.1 ofFail() helper issues

After reading this blog post (below), I wanted to use the .orFail() helper function in one of my projects.
http://thecodebarbarian.com/whats-new-in-mongoose-53-orfail-and-global-toobject.html
When the function findById() fails, it throws the exception indicated in the .orFail() function. However, when it doesn't fail, it returns "undefined" instead of the actual model object.
let tenants = await Tenant.findById(req.params.tenantId).orFail(new Error(`ID "${req.params.tenantId}" not found`))
Any ideas?
This issue was confirmed as a bug. It's now fixed on 5.3.2
https://github.com/Automattic/mongoose/issues/7099

How to use delta trigger in flink?

I want to use the deltatrigger in apache flink (flink 1.3) but I have some trouble with this code :
.trigger(DeltaTrigger.of(100, new DeltaFunction[uniqStruct] {
override def getDelta(oldFp: uniqStruct, newFp: uniqStruct): Double = newFp.time - oldFp.time
}, TypeInformation[uniqStruct]))
And I have this error:
error: object org.apache.flink.api.common.typeinfo.TypeInformation is not a value [ERROR] }, TypeInformation[uniqStruct]))
I don't understand why DeltaTrigger need TypeSerializer[T]
and I don't know what to do to remove this error.
Thanks a lot everyone.
I would read into this a bit https://ci.apache.org/projects/flink/flink-docs-release-1.2/dev/types_serialization.html sounds like you can create a serializer using typeInfo.createSerializer(config) on your type info. Note what you're passing in currently is a type itself and NOT the type info which is why you're getting the error you are.
You would need to do something more like
val uniqStructTypeInfo: TypeInformation[uniqStruct] = createTypeInformation[uniqStruct]
val uniqStrictTypeSerializer = typeInfo.createSerializer(config)
To quote the page above regarding the config param you need to pass to create serializer
The config parameter is of type ExecutionConfig and holds the
information about the program’s registered custom serializers. Where
ever possibly, try to pass the programs proper ExecutionConfig. You
can usually obtain it from DataStream or DataSet via calling
getExecutionConfig(). Inside functions (like MapFunction), you can get
it by making the function a Rich Function and calling
getRuntimeContext().getExecutionConfig().
DeltaTrigger needs a TypeSerializer because it uses Flink's managed state mechanism to store each element for later comparison with the next one (it just keeps one element, the last one, which is updated as new elements arrive).
You will find an example (in Java) here.
But if all you need is a window that triggers every 100msec, then it'll be easier to just use a TimeWindow, such as
input
.keyBy(<key selector>)
.timeWindow(Time.milliseconds(100)))
.apply(<window function>)
Updated:
To have hour-long windows that trigger every 100msec, you could use sliding windows. However, you would have 10 * 60 * 60 windows, and every event would be placed into each of these 36000 windows. So that's not a great idea.
If you use a GlobalWindow with a DeltaTrigger, then the window will be triggered only when events are more than 100msec apart, which isn't what you've said you want.
I suggest you look at ProcessFunction. It should be straightforward to get what you want that way.

How to redirect category page to first child in Umbraco without a ThreadAbortException

(I'm about to answer this question as well, because I've found the solution, but Google didn't really help, so hopefully this will gain some PageRank for the search terms I was using.)
We have a big Umbraco site with several sections, but most locales don't have section homepages. So if the structure looks like:
- Homepage
- Section1
- Page1-1
- Page1-2
- Section2
- Page2-1
- Page2-2
and so on, then going to ~/section1/ would redirect you to ~/section1/page1-1/ (and, likewise ~/section2/ redirects you to ~/section2/page2-1/).
At the moment, we use a macro that checks a property in the locale homepage and then redirects:
var node = Model.AncestorOrSelf("SiteHome");
var useCSSV2 = node.GetProperty("useCSSV2").Value;
if (useCSSV2 == "1")
{
Response.Redirect(Model.Children.First().Url);
}
We're seeing a bunch of occasions where macros don't load properly, with errors like
Error loading MacroEngine script (file: PrimaryNavigationSwitcher.cshtml)
displaying instead. Looking at the UmbracoTraceLog, I can see things like:
2014-11-25 00:11:28,226 [5] WARN umbraco.macro - [Thread 39] Error loading MacroEngine script (file: PrimaryNavigationSwitcher.cshtml, Type: ''. Exception: System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.AbortCurrentThread()
at System.Web.HttpResponseWrapper.Redirect(String url)
at ASP._Page_macroScripts_SecondLevelPageRedirection_cshtml.Execute() in d:\webroot\www.mysite.com\macroScripts\SecondLevelPageRedirection.cshtml:line 8
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
(where line 8 of SecondLevelPageRedirection.cshtml is the Response.Redirect).
That problem and the ThreadAbortException itself are strongly suggesting to me that Response.Redirect is the problem here and I should be using some other means of performing this redirect. (And even if this weren't a problem I'd prefer to avoid the performance impact of a bunch of exceptions being thrown.)
How should we be performing this redirect to have the same effect (so anyone going to ~/section1/ will be redirected to ~/section1/page1-1/ and so on), without having to add an umbracoRedirect or umbracoInternalRedirectId to each node and without having these damn ThreadAbortExceptions thrown all the time?
As detailed in a handful of places (notably Why Response.Redirect causes System.Threading.ThreadAbortException? here on Stack Overflow and PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer on the MSKB), Response.Redirect(string) is only present in ASP.Net for backwards compatibility.
To quote from Joel Fillmore in his answer to the Stack Overflow question linked above:
The correct pattern is to call the Redirect overload with endResponse=false and make a call to tell the IIS pipeline that it should advance directly to the EndRequest stage once you return control:
Response.Redirect(url, false);
Context.ApplicationInstance.CompleteRequest();
This blog post from Thomas Marquardt provides additional details, including how to handle the special case of redirecting inside an Application_Error handler.
Note that code after the Context.ApplicationInstance.CompleteRequest call will execute, so may need handling separately.
Incidentally, as the problem stems from Response.End, which includes the code
InternalSecurityPermissions.ControlThread.Assert();
Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false));
then Server.Transfer will have precisely the same problem. There is more information at Is Response.End() considered harmful?