Safely store code snippets in JavaScript and MySQL - code-snippets

I'm working on an online python learning project which shows an online compiler inside an iframe to make user able to run and test codes simultaneously with courses . I have an idea of saving users code input into a database so the next time that they load the compiler , be able to have their last inputed code . While the user's input can be retrieved with js , how can I safely store it in my database ? Note that the code snippet will be send to a PHP API and from that will be saved into the database . What i want to ensure is the security of either sending or receiving code snippet through this route ( JavaScript , PHP , MySQL )

Related

i'm using angular13 with electron , i'm stack with one problem , i have to store data in local system and get that data and perform curd on that data

I am building a desktop application using Angular 13. to build the desktop application I am using electron JS along with Angular 13. here I've requirement to store a data in the local system.
So I need your help like which process I need to follow to store the data in the local system. also I want to display a data inside application in a list format.
Right now i'm doing but facing an issue, please review below details I have 1 JSON files on the client-side which are basically an array of JSON objects, from where I read and use in my component. I want to add (or edit) an object in those JSON files using angular only(without sending it to backend) and then make sure component is able to use it. Is it possible through angular? Or will I have to use a typescript file and store all information there?
I need to store the data inside the operating system as the data will be in large amount
Please if there is any other way that we can store this data in local system and show it in the application then please help me.
I have this form add form
and store this form data in local(os), get that data in listing page list form data,
and able to do curd on listing page ,
Thanks an advance
can't use backend apis

Whats the best practice for creating and sending an email attachment using Rails API

I need to know if I'm implementing the correct procedure when sending an email with an attached .xls document.
The attached .xls document would simple have the information provided in an object. ...ie: person.first_name person.last_name. The xls file will render the full names of the list.
I have a front-end React.js with a back-end Rails API.
I actually have it working in it’s most simple way but I’m not sure if this would be the best way.
Please let me know if there is amore efficient way of doing this.
Currently I have this setup: In my React Action Creator I have a fetch calling to a custom “list” method on my controller backend. In this controller I’m creating and writing the file like this:
File.open(“new_file”, 'w+') do | f |
c = #list.names do | name, data |
f.puts ( "#{name.first_name} #{name.last_name}")
f.close
end
end
The above code will create a file in the root of my application which I’m not sure if it’s best practice.
After this code runs the mailer sends out the email with the proper xls file attached .
My question is: What do I do with this newly created file on the root of my rails application. Is this normal to have and every time this runs the file is overwritten which is okay in my opinion. What if two different people on different devices run the code at the same time. Will there be a chance of the list being mixed up and one user getting the wrong list? I just feel like this is not right to create a file to my back-end Rails api whenever my user needs a list emailed to them. Even if I delete it right after it’s sent in the mailer.
Thank you for your help.
How about creating temporally files with the ruby API
Or if there is not a need to reuse the file use send_data
If you have thousand of files that need caching is worth thinking something like the official Rails cache api(you can cache any kind of file no just HTML )

Best way to check for data updates on webserver

I have an application which uses the data from web server. When you first launch the app, it downloads the data and then work with it. But what if the data on web site was changed. How can I know from the application that the data was changed, and if so, what data should I download?
My first idea was each time when you run the application to check the number of entries in the local database on your phone and the number of entries on web server, and if they are not equal, delete all data in local database and then download all data again. But I think that it will take more time than if the application just loads 5-10 needed records instead of all data.
The second idea was when the information on the site changes, website somehow has to inform the application to load some records. But I don’t know if it is possible to do(
Another idea was to compare the id of the last entry in the application database with last id on website. And if they are not equal download the information from the next id.
Are there any suggestions how can I accomplish this?
I am not sure that you have any database or web services but my suggestion is parsing data from the web with JSON or XML.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/
this class reference is will be clear for you.
Also in my opinion, if you are new in swift and want to choose easy way for this operation search for iOS package managers.
If you want to use a package manager for your project, e.g Pod
https://cocoapods.org/pods/Alamofire
would be a good startig point.
Alamofire is an HTTP networking library written in Swift.
Hope to helped you

How does BreezeJS will help in saving data to client browser without actually saving it to database

In SPA , how can we use BreezeJS to save data on client cache before saving back to database. I am working on this HotTowel Template and trying an application which is a simple calculator and I want to calculate the results using cache and save it to only cache (client browser), and I should be able to query on the results. ( I am already done with this type of application but problem is that it will do the saveChanges into database directly and the view is updated accordingly)
It's not clear that you have a specific issue we can address.
For a general understanding of how to manage changes offline, you might watch John Papa's Pluralsight course, "Building Apps with Angular and Breeze - Part 2", particularly the "Saving State with Local Storage" module.

How to store the submitted form information in MySQL?

I have configured Orbeon to use MySQL as explained in the general documentation. It works with some limitations. Now I have published a form and I can fill it up.
When submitted the information is stored somewhere, but I don't know where (probably in eXistdb). How can also configure Orbeon to also store submissions in MySQL? I want to access to this information from external applications.
The submit process as of 4.2 runs the following actions:
require-uploads then require-valid then save
then success-message("save-success") then result-dialog
recover error-message("database-error")
So it does save the data. However, you're saying that you don't see the data saved in MySQL. To simplify things, you can start by trying to check of the data gets saved when you hit just the Save button on the same form. And if it doesn't get saved, see if there are any errors in the orbeon.log. If you see an error, but not enough information about it, you can increase the log level by using the development configuration.

Resources