I'm trying to create an online python editor and want to use Ace Editor to do so. How does one render or compile python code on the browser using Ace Editor's CDN with HTML/JS (https://ace.c9.io)?
I was successful in compiling a live view of HTML and Javascript using the contentWindow.document function; however, I can't seem to figure out how to do the same, except with Python instead.
ACE Editor is just a code editor, it doesn't include any compiler of any kind. What you are looking for is for a web service that allows you to submit some Python code, then run it on the host server with Python support and return a response.
The best solution would be to implement a Python Sandbox that will run untrusted Python code, ideally through docker or something on a virtual machine where no other code or data of yours could be compromised. Check Pysandbox for a docker solution example.
Related
I am evaluating which framework to create a desktop app. A requirement I have is that the source code "protection" (no one should see the original source code).
For Neautrlinojs I have found this:
https://github.com/neutralinojs/neutralinojs/issues/153#issuecomment-817842757
Now we are using the .asar format (But it is .neu in our scenario). Therefore, I will close this issue. Thanks for reporting the issue/idea.
But, as I know, the sourcecode (js) of an asar file che be obtained.
Is there a way to make impossible to get the "original" code from the build of Neautrlinojs or Electron?
I know that in a build made with nw.js, source code is very difficult to be obtained
For this kind of requirement, which framework is the most suitable?
Thank you!
If you need source code protection you need to use a tool that builds your source code to a native binary. NW.js allows for this by capturing your JS code running in memory in the V8 engine (a "V8 Snapshot"). Which means you need to run it's nwjc tool on each platform to capture it running in memory.
Other tools exist for creating Cross-Platform Desktop Apps (XPDAs):
https://xpda.net
However if you want to use JavaScript as your source code, your only real option is NW.js, or to store it on a remote server and access it via the internet.
https://nwjs.io - Official website
https://nwutils.io - Community website
In RStudio it´s possible to autoformat R Code with CTRL+SHIFT+A (e.g. see this answer). Now my question is, how to autoformat javascript code in RStudio (e.g. if you are working on a shiny app).
The prettifyAddins package I've just made provides two RStudio addins for JavaScript files and more: an addin which only reindents the code and an addin which prettifies the code, e.g. it adds semi-colons when they are missing. I will submit it to CRAN soon.
Update
I updated prettifyAddins. It has now addins using the V8 package, and Shiny is not used for these addins, the prettified code directly replaces the current code.
Another possibility is my (freshly built) package aceEditor. It opens the Ace editor in the viewer pane of RStudio:
This provides a second source editor in RStudio. And many languages are supported.
I want to run java script by using visual studio code.
When I run script, visual studio code returned Code language not supported or define.
I have Code Runner Plugin in visual studio code.
What does Code language not supported or define mean ?
You will probably need to start a web project to run the JavaScript in. I believe there are tools to use JavaScript as a console language, but this would require some extra setup. These scripts are intended to be executed by a browser.
Try this:
Create a new web page project in Visual Studio.
Add tags somewhere in the body of your HTML document.
Paste your JavaScript into the script tags.
When you launch the page, if you hit F12, you should be able to see your console.log output in the "Console" section.
Another option would be to use a site like JSFiddle. https://jsfiddle.net/
It will help you to have a basic understanding of CSS and HTML while learning JavaScript. W3Schools has some excellent beginner guides for HTML, CSS, and JS.
One option is to install Node.js.
Then open a terminal window and type node filename.js and it will execute the JavaScript.
I am practicing online programming contest held by codeforces, and I try to play javascript with it. However, I find it very difficult to setup my environment for offline test, they have readline() for input to stdio and print()/write() for output in stdout. Any help? Thanks.
For practising Javascript, you could use any thing from the chrome development console to online editors like JSFiddle. Nodejs allows you to run Javascript (which is used for client side rendering) on a server. What this means is that using node, you could run javascript on your terminal. As for the input , output functions you mentioned, it is easy to require them as node modules or use appropriate Javascript libraries for the same.
I have a problem. I've tried some libraries that convert html to PDF but they don't import CSS, so my PDF is invalid.
I's tried with "html2pdf" , "pdfmake", "jspdf"..
PDFMake does not help me because it need to generate a JSON with HTML data...
The structure of file that I would like to convert to PDF is:
html: www/templates/phase_one_report.html
css: www/css/phase_one_report.css
Some ideas? I am using nodeJS with sailsJS in backend and javascript with ionic in frontend.
Sorry about my english.
This is a difficult problem. I have also found that existing HTML to PDF libraries usually don't handle the HTML & CSS that I throw at them.
The best solution I have found is not Javascript at all: wkhtmltopdf. This is essentially a program that wraps up the webkit rendering engine so that you can give it any HTML + CSS that webkit can render and it will return a PDF document. It does an outstanding job, since it's actually rendering the document just like a browser would.
You mention that you're using node.js, but it's not clear exactly what your environment is, so I'm going assume that your report is available at a URL like http://my.domain/phase_one_report.html. The simplest way to get this working would be to install the wkhtmltopdf application on your server, then use child_process.exec to execute it.
For example:
import { exec } from 'child_process';
// generate the report
// execute the wkhtmltopdf command
exec(
'wkhtmltopdf http://my.domain/phase_one_report.html output_file.pdf',
(error) => {
// send the PDF file to the client
}
);
There are a lot of different command-line options for wkhtmltopdf - you'll need to look into all the different ways to configure it.
If your report is not accessible at a URL, then this becomes a little more complicated - you'll need to inline the CSS and send everything to wkhtmltopdf at once.
There are a number of options available right now:
Edit 09/2018: Use puppeteer, the JS Headless Chrome driver. Firefox now also has headless mode but I'm not sure which library corresponds to puppeteer.
wkhtmltopdf as mentioned before does the job but is slightly outdated.
You will have to watch the latest chrome releases which will have a --headless option to enable html+css+js to pdf conversion.
Then there is PhantomJS and Slimer.js. Both are possible to use with node and Javascript. Nightmare.js is also an option but sits on top of it.
However, Phantom.js is currently the only solution that is truly headless and javascript based. Slimer.JS works with Firefox but requires you to have a window manager, at least xvfb, a virtual frame buffer.
If you want the latest browser features you will have to go with slimer.js or, another option, go with one of the Electron based solutions that keep popping up. Electron is based on Chrome and is scriptable too. A fine solution that also ships with Docker containers is currently https://github.com/msokk/electron-render-service
This list is possibly incomplete and will change a lot in the near future.