My Meteor app is crashing when run on FireFox with this error 4 times, the fourth one must be the one crashing it because this function is called about 30 times through out the html template.;
"Exception in template helper: #http://www.scr9.com:3000 /onepage.js?6b34dec0cc55de19e1c0ff682ac83dd9dce574d6:57:2
bindDataContext/<#http://www.scr9.com:3000/packages /blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:14
Blaze._wrapCatchingExceptions/<#http://www.scr9.com:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:14
Spacebars.call#http://www.scr9.com:3000/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:12
Spacebars.mustacheImpl#http://www.scr9.com:3000/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:108:10
Spacebars.mustache#http://www.scr9.com:3000/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:112:16
Template.writeInvoice</</</<.value#http://www.scr9.com:3000/template.onepage.js?0b87a7326f8eda037de95427f14c078c4ab026ac:1005:18
Blaze._withCurrentView#http://www.scr9.com:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2043:12
.visitAttribute#http://www.scr9.com:3000/packages/blaze.js?efa68f65"[…]
Works fine using Chrome, IE, and Safari. This is the function that it refers to at line 57;
Handlebars.registerHelper("formatMoney", function(str) {
console.log(str); // reports 0 in Chrome, IE, Safari. undefined in FF
if (typeof str == "string")
{
str = Number(str); // line 57
}
str = str.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
if (str == "0.00")
{
return "0.00";
} else {
return "$"+str;
}
});
When it first starts I have no data yet so that function is just receiving str = 0. Any idea of what might be happening in FF?
This can be because of 2 things:
First, regex, especially with a /g can cause bugs, without testing anything, I bet this is the problem.
Second, you've got a lot of coercion going on here, so first, I'd force the str argument to be a number before you pass it into the function. If this is coming from your DB this should be easy because you sanitized the data before it got in, right? right?
Implement both & your new function looks like this:
Template.registerHelper("formatMoney", function(str) {
var formatOpts = {style: "currency", currency: "USD"};
return str ? str.toLocaleString("en-US", formatOpts ) : "0.00";
});
Related
i have this piece of code im trying to run:
float curX;
curX = map(millis(), timeStart, timeEnd, fromX, toX);
// the code itself works fine so variables and stuff aren't really important
and because of the circumstances of the program, sometimes it will give errors like this: map(992, 1000, 1000, 50, 50) called, which returns NaN (not a number)
this doesn't stop the program but i wanted to know if there was a way to detect if this will happen and such, not run this code so it doesn't fill up the console. maybe using a try {} catch() {} statement or something?
if your goal is to not fill the console you can add a if(millis() != timeStart && fromX != toX) before curX = ...
I call readRecords on line 74 and the syntax is simple, but the program hangs at this line. The Students table exists, with 12 students, it was originally created with the createRecord on line
60. I've looked at the syntax for this line for tooooo long. What am I missing?
Also, is there a more elegant way to use this data outside of the readRecords code block? I'm copying it to arrays (no 2-dimensional arrays or structures in applab). I tried to create a global 'records' of some kind, without success. The App Lab project examples I learned from use the data within the readRecords code block, but not outside the block.
The project:
my project: https://studio.code.org/projects/applab/xEEOqp8zpOJ2g-YyCntajlhvh0crb2ysLvP1Pg5LCF8
The specific code:
onEvent("choosePeriodNext", "click", function() {
var chosenPeriod = getText("period2");
readRecords("Students", {}, function(records) {
numStudents = records.length;
if (numStudents>0) {
for (var i =0; i < numStudents; i++) {
console.log (records[i].goesBy);
goesBys[i] = records[i].goesBy;
pronounss[i] = records[i].pronouns;
periods[i] = records[i].period;
firsts[i] = records[i].first;
lasts[i] = records[i].last;
games[i] = records[i].game;
jobs[i] = records[i].job;
goodAts[i] = records[i].goodAt;
toKnows[i] = records[i].toKnow;
photos[i] = records[i].photo;
}
learnNames();
} else setScreen ("home");
});
});
Thank you for your help!
Carol
I answered my own question.
I found that this code worked in a collegue's browser, but not mine.
I cleared cache and cookies, then restarted my browser. Now it works.
Oh my.
EDIT:
I have heavily edited this question after making some significant new discoveries and the question not having any answers yet.
Historically/AFAIK, keeping your Mac awake while in closed-display mode and not meeting Apple's requirements, has only been possible with a kernel extension (kext), or a command run as root. Recently however, I have discovered that there must be another way. I could really use some help figuring out how to get this working for use in a (100% free, no IAP) sandboxed Mac App Store (MAS) compatible app.
I have confirmed that some other MAS apps are able to do this, and it looks like they might be writing YES to a key named clamshellSleepDisabled. Or perhaps there's some other trickery involved that causes the key value to be set to YES? I found the function in IOPMrootDomain.cpp:
void IOPMrootDomain::setDisableClamShellSleep( bool val )
{
if (gIOPMWorkLoop->inGate() == false) {
gIOPMWorkLoop->runAction(
OSMemberFunctionCast(IOWorkLoop::Action, this, &IOPMrootDomain::setDisableClamShellSleep),
(OSObject *)this,
(void *)val);
return;
}
else {
DLOG("setDisableClamShellSleep(%x)\n", (uint32_t) val);
if ( clamshellSleepDisabled != val )
{
clamshellSleepDisabled = val;
// If clamshellSleepDisabled is reset to 0, reevaluate if
// system need to go to sleep due to clamshell state
if ( !clamshellSleepDisabled && clamshellClosed)
handlePowerNotification(kLocalEvalClamshellCommand);
}
}
}
I'd like to give this a try and see if that's all it takes, but I don't really have any idea about how to go about calling this function. It's certainly not a part of the IOPMrootDomain documentation, and I can't seem to find any helpful example code for functions that are in the IOPMrootDomain documentation, such as setAggressiveness or setPMAssertionLevel. Here's some evidence of what's going on behind the scenes according to Console:
I've had a tiny bit of experience working with IOMProotDomain via adapting some of ControlPlane's source for another project, but I'm at a loss for how to get started on this. Any help would be greatly appreciated. Thank you!
EDIT:
With #pmdj's contribution/answer, this has been solved!
Full example project:
https://github.com/x74353/CDMManager
This ended up being surprisingly simple/straightforward:
1. Import header:
#import <IOKit/pwr_mgt/IOPMLib.h>
2. Add this function in your implementation file:
IOReturn RootDomain_SetDisableClamShellSleep (io_connect_t root_domain_connection, bool disable)
{
uint32_t num_outputs = 0;
uint32_t input_count = 1;
uint64_t input[input_count];
input[0] = (uint64_t) { disable ? 1 : 0 };
return IOConnectCallScalarMethod(root_domain_connection, kPMSetClamshellSleepState, input, input_count, NULL, &num_outputs);
}
3. Use the following to call the above function from somewhere else in your implementation:
io_connect_t connection = IO_OBJECT_NULL;
io_service_t pmRootDomain = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPMrootDomain"));
IOServiceOpen (pmRootDomain, current_task(), 0, &connection);
// 'enable' is a bool you should assign a YES or NO value to prior to making this call
RootDomain_SetDisableClamShellSleep(connection, enable);
IOServiceClose(connection);
I have no personal experience with the PM root domain, but I do have extensive experience with IOKit, so here goes:
You want IOPMrootDomain::setDisableClamShellSleep() to be called.
A code search for sites calling setDisableClamShellSleep() quickly reveals a location in RootDomainUserClient::externalMethod(), in the file iokit/Kernel/RootDomainUserClient.cpp. This is certainly promising, as externalMethod() is what gets called in response to user space programs calling the IOConnectCall*() family of functions.
Let's dig in:
IOReturn RootDomainUserClient::externalMethod(
uint32_t selector,
IOExternalMethodArguments * arguments,
IOExternalMethodDispatch * dispatch __unused,
OSObject * target __unused,
void * reference __unused )
{
IOReturn ret = kIOReturnBadArgument;
switch (selector)
{
…
…
…
case kPMSetClamshellSleepState:
fOwner->setDisableClamShellSleep(arguments->scalarInput[0] ? true : false);
ret = kIOReturnSuccess;
break;
…
So, to invoke setDisableClamShellSleep() you'll need to:
Open a user client connection to IOPMrootDomain. This looks straightforward, because:
Upon inspection, IOPMrootDomain has an IOUserClientClass property of RootDomainUserClient, so IOServiceOpen() from user space will by default create an RootDomainUserClient instance.
IOPMrootDomain does not override the newUserClient member function, so there are no access controls there.
RootDomainUserClient::initWithTask() does not appear to place any restrictions (e.g. root user, code signing) on the connecting user space process.
So it should simply be a case of running this code in your program:
io_connect_t connection = IO_OBJECT_NULL;
IOReturn ret = IOServiceOpen(
root_domain_service,
current_task(),
0, // user client type, ignored
&connection);
Call the appropriate external method.
From the code excerpt earlier on, we know that the selector must be kPMSetClamshellSleepState.
arguments->scalarInput[0] being zero will call setDisableClamShellSleep(false), while a nonzero value will call setDisableClamShellSleep(true).
This amounts to:
IOReturn RootDomain_SetDisableClamShellSleep(io_connect_t root_domain_connection, bool disable)
{
uint32_t num_outputs = 0;
uint64_t inputs[] = { disable ? 1 : 0 };
return IOConnectCallScalarMethod(
root_domain_connection, kPMSetClamshellSleepState,
&inputs, 1, // 1 = length of array 'inputs'
NULL, &num_outputs);
}
When you're done with your io_connect_t handle, don't forget to IOServiceClose() it.
This should let you toggle clamshell sleep on or off. Note that there does not appear to be any provision for automatically resetting the value to its original state, so if your program crashes or exits without cleaning up after itself, whatever state was last set will remain. This might not be great from a user experience perspective, so perhaps try to defend against it somehow, for example in a crash handler.
I'm having a problem getting casperjs test to exit after execution, I have to hit CTL-C to exit execution. I'm on OSX 10.7 with casperjs 1.1 devel.
To test this wasn't my code I simply copied this sample from the docs:
var casper = require("casper").create();
function Cow() {
this.mowed = false;
this.moo = function moo() {
this.mowed = true; // mootable state: don't do that at home
return 'moo!';
};
}
casper.test.begin('Cow can moo', 2, function suite(test) {
var cow = new Cow();
test.assertEquals(cow.moo(), 'moo!');
test.assert(cow.mowed);
test.done();
});
And I get the following output
casperjs test cow-test.js
Test file: cow-test.js
# Cow can moo
PASS Subject equals the expected value
PASS Subject is strictly true
I then have to hit CTL-C to stop execution. Am I missing something to stop execution?
Per https://github.com/n1k0/casperjs/issues/593#issuecomment-23062361, the problem was that I had created a casper instance at the top of the file, which the documentation warns you not to do.
The solution was to remove the var casper = require("casper").create(); line.
I encountered a problem in my project. It's about tombstone. I found out that it takes a long time to recover, sometimes it can be as long as 5 minutes with no error occuring!
I have never had a problem like that, can anyone tell me why?
Thanks
finally, I found where the problem is the code blow, if i remove them, the app works well.
DeviceNetworkInformation.ResolveHostNameAsync(
new System.Net.DnsEndPoint("m.baidu.com", 80),
new NameResolutionCallback(handle =>
{
NetworkInterfaceInfo info = handle.NetworkInterface;
if (info != null)
{
networkType = GetNetType(info);
}
else
networkType = NetType.NONE;
}), null);