1084: Syntax error: expecting in before colon - actionscript-3

Error message:
Scene 1, Layer 'Script', Frame 1, Line 11, Column 13 1084: Syntax error: expecting in before colon.
var tab:Array = new Array();
tab[0] = {alder:45, navn: "N Linjesæter"};
tab[1] = {alder:34, navn: "P Kurverud"};
tab[2] = {alder:18, navn: "O Sirkelstad"};
tab[3] = {alder:12, navn: "J Rektangelsen"};
tab[4] = {alder:27, navn: "M Ellipsen"};
var utskrift:String = "";
for(var teller:int = 0;teller < 3; teller ++)
{
for(varNavn:String in tab[teller])
{
utskrift = utskrift + varNavn + ": " +
tab[teller] [varNavn] + "\n";
}
utskrift = utskrift + "\n";
}
txtFelt.text = utskrift;
What have i done wrong here? I simply can't find it.

I think you have a typo.
This:
for(varNavn:String in tab[teller])
Needs to be changed to this:
for(var Navn:String in tab[teller])
Or if you really needed a variable named varNavn then use:
for(var varNavn:String in tab[teller])

Related

Private key does not satisfy the curve requirements (ie. it is invalid);

Can Anyone help me, please? It gives me the error "throw new Error('Private key does not satisfy the curve requirements (i.e., it is invalid)');" it's been 5 days of debugging the code but still no luck; please correct the code and resend it.
const Wallet = require("ethereumjs-wallet");
var possible = "abcdef1234567890";
var basePrivateKey =
"0x09e8568e418bcb88662b7d0094db85b24177ad68ae715dc871d07a5ef4c2a1";
var charsMissing = 66 - basePrivateKey.length;
var targetPublicAddress = " 0x3fFacFff9858168c4E0c34C6f88Eb9e6F8576c6B";
var missingPart = "";
for (var i = 0; i < charsMissing; i++) {
missingPart = missingPart.concat(i);
}
var maxVal = parseInt(missingPart, 16);
console.log(
` \n searching for address : ${targetPublicAddress} \n base private key : ${basePrivateKey} \n missing chars : ${charsMissing} \n it will be quiet now. if you don't see anything below me, it's working on finding your key. \n If you see something below that doesn't say 'FOUND KEY!', you have an error \n `
);
function makeHexString(numb) {
var hex = numb.toString(16);
for (var i = 0; i < charsMissing - hex.length; i++) hex = "0" + hex;
return hex;
}
for (var i = 0; i <= maxVal; i++) {
for (var j = 0; j <= basePrivateKey.length; j++) {
// console.log(" i : " + i + " : j : " + j + "\n");
var endPrivateKey = makeHexString(i);
var privateKeyGuess = [
basePrivateKey.substring(0, j) +
endPrivateKey +
basePrivateKey.substring(j, basePrivateKey.length),
];
var wallet = Wallet.fromPrivateKey(Buffer.from(privateKeyGuess, "hex"));
var publicAddress = util.bufferToHex(wallet.getAddress());
if (publicAddress.toLowerCase() == targetPublicAddress.toLowerCase()) {
console.log(
`Found Private Key: ${privateKeyGuess}\n matching address \n \n \n \n`
);
process.exit();
}
}
if (i % 100000 === 0) {
console.log("checked", i, "keys");
}
}
Length of the basePrivateKey that you shared is 62 hex characters (prepended by 0x) which is 248 bits.
However the expected length is 64 hex characters (prepended by 0x), or 256 bits. In other words, your key is invalid because it's too short.

Execute Code as Fast as Possible

I am using node.js with my WebStorm IDE to parse a large JSON file (~500 megabytes). Here is my code:
fs = require("fs");
fs.readFile('C:/Users/.../Documents/AAPL.json', 'utf8', function (err,data) {
for (i = 0; i < 1000; i++) {
var hex = JSON.parse(data)[i]._source.layers.data["data.data"];
var askPrice = parseInt(hex.substring(215, 239).split(":").reverse().join(""),16);
var bidPrice = parseInt(hex.substring(192, 215).split(":").reverse().join(""),16);
var symbol = hex.substring(156, 179);
var timestamp = hex.substring(132, 155);
var askSize = hex.substring(240, 251);
var bidSize = hex.substring(180, 191);
var price = String((+bidPrice+askPrice)/2);
var realprice = price.slice(0, price.length - 4) + "." + price.slice(price.length - 4);
function hex2a(hexx) {
var hex = hexx.toString();
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
if(JSON.parse(data)[i]._source.layers.data["data.len"] == 84 && realprice.length == 8 && +realprice <154 && +realprice >145) {
console.log(i + " " + hex2a(symbol.replace(/:/g, "")) + " sold for " + realprice + " at " + parseInt(timestamp.split(":").reverse().join(""), 16));
}
}
});
The problem I am running into however is that my IDE is parsing this file at an extremely slow speed, roughly 1 iteration a second. I do not think this is because I have a slow computer, for I have a high end rig with a core i7 7700k and a gtx 1070. I tried executing the code in the console with the same result. I tried trimming down the code and again I achieved the same speed:
fs = require("fs");
fs.readFile('C:/Users/Brandt Winkler Prins/Documents/AAPL.json', 'utf8', function (err,data) {
for (i = 0; i < 12000; i++) {
var hex = JSON.parse(data)[i]._source.layers.data["data.data"];
var askPrice = parseInt(hex.substring(215, 239).split(":").reverse().join(""),16);
var bidPrice = parseInt(hex.substring(192, 215).split(":").reverse().join(""),16);
var price = String((+bidPrice+askPrice)/2);
var realprice = price.slice(0, price.length - 4) + "." + price.slice(price.length - 4);
if(+realprice <154 && +realprice >145) {
console.log(realprice);
}
}
});
How should I execute my code to get my data as fast as possible?
You're running JSON.parse(data) every iteration, that might take quite some time for a 500MB json file.
The solution would be to move it out of the loop and reuse the parsed object:
var obj = JSON.parse(data);
for (...

Getting values from class tag with HtmlAgilityPack

I'm having this code (see bellow) and I want to get the values 'Day.1' and 'Day.2' from it.
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml("<div class=\"large-10 columns\"><div class=\"box\"><div class=\"table-header\">Day.1</div></div></div>" +
"<div class=\"large-10 columns\"><div class=\"box\"><div class=\"table-header\">Day.2</div></div></div>");
var classes = doc.DocumentNode.SelectNodes("//div[#class=\"large-10 columns\"]");
foreach (var item in classes)
{
var str = item.SelectSingleNode("//div[#class=\"box\"]//div[#class=\"table-header\"]");
Output += "Test: " + str.InnerText.Split('.')[1] + "\n";
}
With this code the Output is:
Test: 1
Test: 1
Why the variable 'str' is getting the value from first 'table-header' class both times?
try:
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml("<div class=\"large-10 columns\"><div class=\"box\"><div class=\"table-header\">Day.1</div></div></div>" +
"<div class=\"large-10 columns\"><div class=\"box\"><div class=\"table-header\">Day.2</div></div></div>");
var classes = doc.DocumentNode.SelectNodes("//div[#class=\"large-10 columns\"]/div[#class=\"box\"]/div[#class=\"table-header\"]");
foreach (var item in classes)
{
var str = item.InnerText;
Output += "Test: " + str.Split('.')[1] + "\n";
}

getRange(),setFormulas doesn't want to work

I have the following code and when I run it I get the right number of items in sheetFormulas (4), and the array values look correctly formed.
However, I get an error right after the sheetFormulas Browser.msgBox pops up, indicating the getRange().setFormulas line has an issue, but I can't see what it is.
function test(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var testingTarget = ss.getSheetByName("Testing");
var sheetFormulas = new Array();
for (l=0;l<10;l++) {
sheetRowCount = l + 2;
var monthlyTotalCompanyCosts = '=F' + sheetRowCount + '/$F$29*$I$14';
var monthlyTotalCompanyCostsPerEa = '=IFERROR(H' + sheetRowCount + '/C' + sheetRowCount + ')';
var monthlyMargin = '=D' + sheetRowCount + '-F' + sheetRowCount;
var monthlyMarginPctg = '=IFERROR(J' + sheetRowCount + '/D' + sheetRowCount + ')';
sheetFormulas.push(monthlyTotalCompanyCosts,monthlyTotalCompanyCostsPerEa,monthlyMargin,monthlyMarginPctg);
Browser.msgBox("sheetFormulas.length is: " + sheetFormulas.length);
Browser.msgBox("sheetFormulas is: " + sheetFormulas);
testingTarget.getRange(sheetRowCount,8,1,4).setFormulas(sheetFormulas);
sheetFormulas = [];
}
}
Any help is appreciated,
Phil
First, sheetFormulas has to be a 2D array. So try doing
/* Notice the [] around sheetFormulas */
testingTarget.getRange(sheetRowCount,8,1,4).setFormulas([sheetFormulas]);
If you still see other problems, then put your code inside a try{}catch{} block and print out the exception in the catch block.
I also suggest that you print out the formula using Logger.log() before setting it on the spreadsheet.

ActionScript - Formatting Zero With NumberFormatter?

i've assigned properties to a NumberFormatter object so that formatted values contain a leading zero, trailing zeros and a 2 decimal places.
the formatting works unless the number being formatted is 0. how can i format a 0 with the set properties so that 0 becomes 0.00?
var numFormat:NumberFormatter = new NumberFormatter(LocaleID.DEFAULT);
numFormat.leadingZero = true;
numFormat.trailingZeros = true;
numFormat.fractionalDigits = 2;
trace(numFormat.formatNumber(46)); //46.00
trace(numFormat.formatNumber(0.556849)); //0.56
trace(numFormat.formatNumber(0)); //0
[EDIT]
i've remedied this problem by manually appending the locale decimal separator with the desired number of fractionalDigits if the formatted number is 0:
if (myFormattedNumber.text == "0" && numFormat.fractionalDigits)
{
myFormattedNumber.appendText(numFormat.decimalSeparator);
for (var i:uint = 0; i < numFormat.fractionalDigits; i++)
myFormattedNumber.appendText("0");
}
i'm still very interested in knowing if this is a bug or a feature, but it seems like a oversight to me.
It's not sexy, but this was similar to what I used when I ran into a similar issue:
function numberFormat(number:*, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String
{
var i:int = 0, inc:Number = Math.pow(10, maxDecimals), str:String = String(Math.round(inc * Number(number))/inc);
var hasSep:Boolean = str.indexOf(".") == -1, sep:int = hasSep ? str.length : str.indexOf(".");
var ret:String = (hasSep && !forceDecimals ? "" : (siStyle ? "," : ".")) + str.substr(sep+1);
if (forceDecimals) for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "." : ",") + str.substr(sep - (i += 3), 3) + ret;
return str.substr(0, sep - i) + ret;
}
trace("zero: " + numberFormat(0, 2, true, false))
Full article here
How about Number(value).toFixed(2) ?