I don't know how to get a javascript file to work for web-browser functionalit, when it's coded as node.js.
The code in question is from a github graphenejs-lib. I want to convert this node.js code into js:
import {Apis} from "graphenejs-ws";
var {ChainStore} = require("graphenejs-lib");
Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
console.log("connected to:", res[0].network);
ChainStore.init().then(() => {
ChainStore.subscribe(updateState);
});
});
let dynamicGlobal = null;
function updateState(object) {
dynamicGlobal = ChainStore.getObject("2.1.0");
console.log("ChainStore object update\n", dynamicGlobal ? dynamicGlobal.toJS() : dynamicGlobal);
}
There is another github from the same developer, steemjs-lib, that shows both the node.js use, and the browser use in the README default page.
I don't know how to make graphenejs-lib into browser javascript, like the steemjs-lib has been made into a regular javascript working version. I contact the dev, but have yet to receive a response.
I figured other people actually know how to do what the dev did for steemjs-lib, and get the graphenejs-lib to work in a browser.
Can you help me out? Thank you.
You can use Browserify to help you with that:
Note that not all of the Node's APIs will be available in the browser.
Use browserify. https://wzrd.in/ will package it for you if you just want to use that one library. https://wzrd.in/standalone/graphenejs-lib#latest
<script src="https://wzrd.in/standalone/graphenejs-lib#latest"></script>
<script>
const {ChainStore} = graphenejsLib;
...
</script>
Related
I am stopped at one point for 2 days and not able to fix.
Can anyone please help me through this?
Question: How can I convert .obj file o .glb?
I used obj2gltf package of npm and search to implement it with Laravel but nothing helped. so now I am confused that does I am doing anything wrong?
Also I tried this article to use the node with PHP/Laravel and another solution from stack overflow.
Can anyone please help me through this?
Thank you in the advance guys.
Unfortunately, there is no solution in pure PHP. But you may create a JS script that converts your files using obj2gltf lib and then execute the script from the PHP in some kind of like that:
//php
$converter = '/path/to/your/script.js';
$objFilePath = '/path/to/your/3d.obj';
$glbFilePath = trim(shell_exec("node $converter $objFilePath"));
And let's say, your JS is converting your 3D object and then returning a path to the converted file:
// script.js
const obj2gltf = require("obj2gltf");
const fs = require("fs");
obj2gltf(process.argv[2])
.then(function (gltf) {
const data = Buffer.from(JSON.stringify(gltf));
fs.writeFileSync("result.gltf", data);
console.log(process.cwd() + "/result.gltf");
});
let dairy = [];
function records(events,experience) { dairy.push({events,experience});
};
How do I save my functions , so I don’t have to write my codes after a shutdown?
Please see the getting started guide which directs you to write code in a text file with a .js file extension and then run it with node yourfilename.js and not to just type everything in the REPL.
I have a problem with my small demo for live query as in attached image.
To be honest, I have no idea why does it go wrong. Try to find some solutions around but not yet successfully. Please give me some ideas or solutions if you know this issue. Thanks so much.
Parse server example: 1.4.0
Parse JS SDK: 1.10.2
NodeJS: 8.9.1
npm: 5.5.1
P/S: I have added classes for supporting by Live Query already.
Here is the source which run successfully without using Live Query
Link to src with removed parse link:
var Parse = require('parse/node');
Parse.initialize("shetei5aeJ9Aequi6deejojiv7foh6Hieg2eesh9keingohw");
Parse.serverURL = 'serURLhere';
var Node = Parse.Object.extend('Node');
var q = new Parse.Query('Node');
var subscription = q.subscribe();
var procEventOpen = () => {
console.log('subscription opened...');
};
subscription.on('open', procEventOpen);
This happened to me when I had a typo in server url.
Try to explicit specify liveQueryServerURL parameter:
Parse.liveQueryServerURL = 'ws://yourserverurl/parse';
Note the ws instead of http(s)
Good morning!
I have been working on a client side browser based app using JavaScript that (all of a sudden) needs the capability to save and load files locally.
The saved files are plain text (.txt) files.
I have managed to get JavaScript to read existing text files. However, I am unable to find reliable information on how to create and edit the contents of these files.
Based on what I see online, I am under the impression that you can't do this with JavaScript alone.
I found out from another source that the best way to do this is outsource the file writing/editing to a Java file and let Java do the work.
I found a code snippet and tweaked it around a bit, but it is not working and I seem to be at a loss:
JAVASCRIPT
<!Doctype html>
<html>
<OBJECT ID="Test" height=0 width=0
CLASSID="CLSID:18F79884-E141-49E4-AB97-99FF47F71C9E" CODEBASE="JavaApplication2/src/TestJava.java" VIEWASTEXT>
</OBJECT>
<script language="Javascript">
var Installed;
Installed = false;
try
{
if (Test==null)
Installed = false;
else
Installed = true;
}
catch (e)
{
Installed = false;
}
alert ("Installed :- " + Installed);
TestStr = Test.SendStr("Basil");
alert (TestStr);
</script>
</html>
JAVA
import javax.swing.*;
public class TestJava {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
public String SendStr(String lStr)
{
return lStr + "!!!";
}
}
If someone could point me in the right direction or even just explain why this isn't working, I would appreciate it.
I believe the sandbox issue prevents all browsers from performing any and all local file writing, without an enormous amount of working around the access restrictions. It is easier to write files remotely on the server than to write them locally to the client. This is true across all browsers.
So while it may be possible to perform the load function, you cannot perform the 'save' function on the local machine.
So similar to ALt-Shift-F in Netbeans, is there a to do this right in the ide in TestComplete? Not sure if this is possible or if anyone can think of a workaround to autoFormat without leaving the TestComplete window.
I'm trying to get the below solution to work with http://jsbeautifier.org/ for javascript / Jscript code in TestComplete.
Thanks
Great question!
There is no built-in function for that. So, we should not expect any solution to be 100% convenient - it is just not a simple task to modify the current script editor contents (if at all possible). So, whatever you do, it will still be some kind of compromise.
In general, the task is three-fold:
Get the current unit code.
Format the code.
Put the code back to the unit.
According to my understanding, items 1 and 3 can be accomplished only by creating a TestComplete plug-in - accessing editors for project nodes is not an easy thing.
UPDATE: silly me! There is a way to access the script editor code - I've updated the below part.
What will help us avoid switching to a different app, are the Script Extensions:
We create a custom Checkpoint in the form of a Script Extension, and install it to TestComplete. As a result, we get a button on the toolbar that we can click to invoke our code.
In the design time action, we call some code that reads the editor contents, then uses external code formatting functionality, and replaces the editor contents with the formatted code.
It would extremely interesting to see the implementations other TestComplete users can suggest! As a start, I am posting a solution that includes using an external web site to format VBScript code (http://www.vbindent.com/). I know that the starter of the post is probably using JScript, but I have not found a JScript formatter yet.
My solution is a simple Script Extension. I can't post a file here, so I will post the code of the two Script Extension files:
Description file:
<!-- Description.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<ScriptExtensionGroup>
<Category Name="Checkpoints">
<ScriptExtension Name="VBScript Code Indent" Author="SmartBear Software" Version="0.1" HomePage="smartbear.com">
<Script Name="VBIndent.js">
<DesignTimeAction Name="Indent Current VBScript Unit" Routine="DesignTimeExecute"/>
</Script>
<Description>
Indents VBScript code in the currently active unit.
</Description>
</ScriptExtension>
</Category>
</ScriptExtensionGroup>
Code file:
// VBIndent.js
function DesignTimeExecute()
{
if (CodeEditor.IsEditorActive)
{
var newCode = IndentVBSCode_Through_VBIndent(CodeEditor.Text);
if (null == newCode)
return;
CodeEditor.Text = newCode;
}
}
function IndentVBSCode_Through_VBIndent(codeToIndent)
{
var URL_VBIndent = "http://www.vbindent.com/?indent";
var httpObj = Sys.OleObject("MSXML2.XMLHTTP");
httpObj.open("POST", URL_VBIndent, false);
httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpObj.send("thecode=" + escape(codeToIndent));
var responseText = httpObj.responseText;
// Extract the indented code from the response
var rx = /<textarea name=\"thecode\".*?>((.*\n)*?)<\/textarea>/;
matches = rx.exec(responseText);
if (null == matches)
{
return null;
}
codeIndented = matches[1];
return codeIndented;
}
After you create these files, and put them to something like "\Bin\Extensions\ScriptExtensions\VBIndent", and click "File | Install Script Extensions | Reload", you will see a new "Indent Current VBScript Unit" item in the custom checkpoints drop-down button on the Tools toolbar. Clicking the element will format the VBScript code in the currently active editor.
So, this is to give a clear idea of what a solution can look like. Better suggestions are welcome! Share your thoughts!
FYI
I've done. Based on your posts.
JSFormat.tcx
https://drive.google.com/uc?export=download&id=0B1x_73bHRc2Jcm8wbTJ2dUpZQTQ
To install the extension copy attached file JSFormat.tcx to C:\Program Files (x86)\SmartBear\TestComplete 10\Bin\Extensions\ScriptExtensions
To use view next image:
https://drive.google.com/uc?export=download&id=0B1x_73bHRc2Jc3RuLXFpTnlCSnc
Regards