i try write some code to view the score on Spark AR
but it not show up on spark editor, and there`s no error on code
whats wrong?
can you help me?
const Scene = require('Scene');
const P = require('Patches');
const R = require('Reactive');
var SKAWNum = Scene.root.findFirst('test');
var scoreNum = P.outputs.getScalar('score');
SKAWNum.text = scoreNum.toString();
From what I can see you are accessing/getting the patch scalar value incorrectly and the findFirst is used incorrectly.
Your code:
const Scene = require('Scene');
const P = require('Patches');
const R = require('Reactive');
var SKAWNum = Scene.root.findFirst('test');
var scoreNum = P.outputs.getScalar('score');
SKAWNum.text = scoreNum.toString();
Here's how you should do it:
const Scene = require('Scene');
const P = require('Patches');
const R = require('Reactive');
var SKAWNum = Scene.root.find('test');
var scoreNum = P.getScalarValue('score');
SKAWNum.text = scoreNum.toString();
if the Scene.root.find doesn't work then visit this page which has an example of how you use the findFirst which the find from the code above could also be replaced with.
Related
I've been trying to solve this but am new to programming. I want to get all file names from a temporary folder and filter them against file names that have previously been logged to a sheet together with other file properties (size, date modified, id, url).
After keeping only the file names in the array that aren't already listed, I'd like to retrieve the files that have these names from my tempfolder and get their file properties in order to append a new row to the sheet with the name, size, date modified, id, url).
This is what I have so far:
const invoiceLog = SpreadsheetApp.openById('SPREADSHEETID').getSheetByName('invoicedata');
const invoiceDispatcherLog = SpreadsheetApp.openById('SPREADSHEETID').getSheetByName('invoicedispatcherlog');
const tempInvoiceFolder = DriveApp.getFolderById('TEMPFOLDERID');
const invoiceFolder2021 = DriveApp.getFolderById('INVOICEFOLDERID');
function invoiceLogger () {
// get new Invoices from tempFolder and make an array of their names
let newInvoiceFileNames = [];
let newInvoices = tempInvoiceFolder.getFiles();
while (newInvoices.hasNext()){
file =newInvoices.next();
let row = []
row.push(file.getName())
newInvoiceFileNames.push(row);
Logger.log(row)
}
// filter the array of new invoices by existing invoice names in the invoice log
let newInvoiceFileNamesFlat = newInvoiceFileNames.map(function(row) {return row [0];});
let existingInvoices = invoiceLog.getRange('A2:A').getValues();
let existingInvoicesFlat = existingInvoices.map(function(row) {return row [0];});
var cleanInvoiceNames = newInvoiceFileNamesFlat.filter(item => !existingInvoicesFlat.includes(item))
//let markedFiles = DriveApp.getFilesByName(cleanInvoiceNames);
cleanInvoiceNames.forEach(SearchFiles)
I'm sure I have some redundancies in here and am not at a point where I can fully appreciate all aspects of how functions and methods interlock but would be enormously grateful for some guidance. Please let me know if any of this was unclear and if I can provide further info.
Update Invoice Data
function updateInvoiceData() {
const ss = SpreadsheetApp.openById('ssid');
const ish = ss.getSheetByName('invoicedata');
const lnames = ish.getRange(2, 1, ish.getLastRow() - 1).getValues().filter(r => r[0]).flat();//listed names
const ifldr = DriveApp.getFolderById('TEMPFOLDERID');
let info = [];//new names
let ifiles = ifldr.getFiles();
while (ifiles.hasNext()) {
let ifile = ifiles.next();
let n = ifile.getName();
//if not already listed
if(!~lnames.indexOf(n)) {
info.push([n, ifile.getSize(),ifile.getDateCreated(),ifile.getId(),ifile.getUrl()]);
}
}
ish.getRange(ish.getLastRow() + 1,1,info.length,info[0].length).setValues(info);
}
bitwise not (~)
This gets the modified date:
function updateInvoiceData() {
const ss = SpreadsheetApp.openById(gobj.globals.ssid);
const ish = ss.getSheetByName('Sheet0');
const sr = 2;//data start row
const lr = ish.getLastRow();//data last row
let lnames;
if(lr > 1) {
lnames = ish.getRange(2, 1, ish.getLastRow() - 1).getValues().filter(r => r[0]).flat();//listed names
} else {
lnames = [];
}
const ifldr = DriveApp.getFolderById(gobj.globals.testfolderid);
let info = [];//new names
let ifiles = ifldr.getFiles();
while (ifiles.hasNext()) {
let ifile = ifiles.next();
let n = ifile.getName();
//if not already listed
if(!~lnames.indexOf(n)) {
let d = JSON.parse(Drive.Files.get(ifile.getId())).modifiedDate;
info.push([n, ifile.getSize(),d,ifile.getId(),ifile.getUrl()]);
}
}
ish.getRange(lr + 1,1,info.length,info[0].length).setValues(info);
}
You have to enable Drive API version 2
Let's say that this is my URL/Link that i have written in an input
https://www.instagram.com/p/CBt-W4jHZjH/
How can I get the "CBt-W4jHZjH" part?
var link = ?????
var a = link.val().trim();
var regex = new RegExp(/^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,29}$/);
var validation = regex.test(a);
https://developer.mozilla.org/en-US/docs/Web/API/URL
const getLastPath = (url) => {
url = new URL(url);
const pathname = url.pathname;
const paths = pathname.split("/");
return paths.pop() || paths.pop();
}
console.log(getLastPath("https://www.instagram.com/p/CBt-W4jHZjH/")); // "CBt-W4jHZjH"
console.log(getLastPath("https://www.instagram.com/p/CBt-W4jHZjH")); // "CBt-W4jHZjH"
Many ways to do it. One way is to look for / any character but / ending with / end of line.
var url = 'https://www.instagram.com/p/CBt-W4jHZjH/'
var x = new URL(url);
console.log(x.pathname.match(/\/([^\/]+)\/?$/)[1])
Could be done with split. The filter removes the empty string caused by the trailing /.
var url = 'https://www.instagram.com/p/CBt-W4jHZjH/'
var x = new URL(url);
console.log(x.pathname.split('/').filter(x=>x).pop());
I'm using several CANVAS in a HTML file and I want to declare them in an Array. This is the (not array) declaration:
var canvas0 = document.getElementById('canvas0');
var ctxPaint0 = canvas0.getContext('2d');
var canvas1 = document.getElementById('canvas1');
var ctxPaint1 = canvas1.getContext('2d');
var canvas2 = document.getElementById('canvas2');
var ctxPaint2 = canvas2.getContext('2d');
var canvas3 = document.getElementById('canvas3');
var ctxPaint3 = canvas3.getContext('2d');
To optimize this, I'm trying to use For loops, but it doesn't work:
var canvasArray = ["canvas0","canvas1","canvas2","canvas3"];
for (var i = 0; i < canvasArray.length; i++) {
window["canvas"+i] = document.getElementById(canvasArray[i]);
window["ctxPaint"+i] = canvasArray[i].getContext('2d');
}
It outputs this error:
Uncaught TypeError: canvasArray[i].getContext is not a function
EDIT:
Thanks to RSchneyer, changing the Array of strings to an Array of Canvas works fine now:
let canvasArray = Array.from(document.getElementsByTagName("canvas"));
for (var i = 0; i < canvasArray.length; i++) {
window["canvas"+i] = document.getElementById(canvasArray[i]);
window["ctxPaint"+i] = canvasArray[i].getContext('2d');
}
You could do like
const ctxArray = [...document.querySelectorAll('[id^="canvas"]')].map(cvs => cvs.getContext('2d'));
which will result to an array holding all the canvases context - which is all you need, since to get the original canvas out of its context all you need is i.e.:
let i = 0; // or any desired index
const canvas = ctxArray[i].canvas;
canvasArray is an array of strings, which don't have a getContext() function. Try replacing the canvasArray[i] in window["ctxPaint"+i] = canvasArray[i].getContext('2d'); with window["canvas"+i], or create another array to hold your actual canvas variables
how can i make this work:
var storedValues = $('<table class="table_groessentabelle_custom"></table>');
// contains excel paste content from Libreoffice
$('textarea[name=excel_data]').bind("paste", function(e){
var pastedData = e.originalEvent.clipboardData.getData('text/html');
storedValues.append(pastedData);
});
//localisation - tables (just a subset)
var de = ["Größe","Höhe","Weite","Damen","Herren","Kinder",];
var fr = ["Pointure","Hauteur","Largeur","Femme","Homme","Enfants"];
var de_storedvalues = JSON.parse(JSON.stringify( storedValues.html() ));
var fr_storedvalues = JSON.parse(JSON.stringify( storedValues.html() ));
for (var i = 0; i < de.length; i++) {
// doesnt work, no fields are translated
fr_storedvalues = fr_storedvalues.replace(/de[i]/gi,fr[i]);
}
it works without the /gi flag but only transates the first entry of a given variable. if there is more than one entry, the rest stays in german.
Thanks in advance,
Michael
var find = de[i];
var regex = new RegExp(find, "g");
fr_storedvalues = fr_storedvalues.replace(regex,fr[i]);
I'm using a node.js script to create a signature for azure documentDB - the simplified version is (result at the bottom):-
var crypto = require("crypto");
var masterKey = "ABCDE"
var key = new Buffer(masterKey, "base64");
var signature = crypto.createHmac("sha256", key).update("FGHIJ").digest("base64");
console.log("\n\n"+signature)
// RNkID54/1h1H9p3NWPeRA0mOW2L0c0HUJGTTY2GPbDo=
This works, and does what I need it to. I'm trying to do the same thing in Swift with CommonCrypto
let keyString = "ABCDE"
let body = "FGHIJ"
let utf8data = keyString.dataUsingEncoding(NSUTF8StringEncoding)
let key = utf8data!.base64EncodedDataWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
let str = body.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen = body.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)
let digestLen = Int(CC_SHA256_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA256), key.bytes, key.length, str!, strLen, result);
var hmacData = NSData(bytes: result, length: digestLen)
var hmacBase64 = hmacData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
result.dealloc(digestLen)
let signature = String(hmacBase64)
let test = "RNkID54/1h1H9p3NWPeRA0mOW2L0c0HUJGTTY2GPbDo="
XCTAssert(test == signature, "Pass")
But it returns a completely different result. If I pass the masterKey directly into the javascript hmac, and pass it in as a string into the CCHmac method in Swift, it all works; so it seems to be something to do with finding the equivalent to this:-
var key = new Buffer(masterKey, "base64");
Thoughts?
More information - this:-
let keyString = "ABCDE"
let body = "FGHIJ"
let keyData = keyString.dataUsingEncoding(NSUTF8StringEncoding)! // .base64EncodedDataWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
let bodyData = body.dataUsingEncoding(NSUTF8StringEncoding)!
let digestLen = Int(CC_SHA256_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA256), keyData.bytes, keyData.length, bodyData.bytes, bodyData.length, result);
var hmacData = NSData(bytes: result, length: digestLen)
var hmacBase64 = hmacData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
result.dealloc(digestLen)
let signature = String(hmacBase64)
let test = "FA372zbobgpTLI5cQWh5YFiFwkNhMI8womX4Cvw68YE=" // "RNkID54/1h1H9p3NWPeRA0mOW2L0c0HUJGTTY2GPbDo="
XCTAssert(test == signature, "Pass")
Produces the same result as this:-
var crypto = require("crypto");
var masterKey = "ABCDE"
var signature = crypto.createHmac("sha256", masterKey).update("FGHIJ").digest("base64");
console.log("\n\n"+signature)
// FA372zbobgpTLI5cQWh5YFiFwkNhMI8womX4Cvw68YE=