Parse .md file with php or javascript - javascript

Is there a way to parse an .md file with php or javascript for code snippets.
My scenario is the following:
I have been migrating an old system (php4) to a Laravel Framework(php7) which needed Schema updates. All of this updates I made it manually( I know I could used migrations but the table structure is quite extensive and I want to persevere the old datas in my new system) and I made a history of changes over mysql updates in a Changelog.md.
Now I try to make an automised migration on schema check if matches some negative rules on table columns with a middleware. For example if Table X does not contain columns Y,Z .. than my system is obsoleted and needs an update of schema and I redirect to dedicated Controller.
no I want to read the changelog with changes let it run this mysql updates.

You can do it using http://parsedown.org/
$Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello<em>Parsedown</em>!</p>
You can install it for Laravel easily : https://github.com/parsedown/laravel

Related

Prisma migration cause data lose

I'm new to prisma I'm working on a project with nodejs & prisma , my database isn't empty and I did some changes in prisma schema and I want to migrate it without data lose is there any solution please ?
Answered based on the problem you mentioned in the comment: "I want to add some columns but I don't want existing data be lost"
if you want to add new columns to an existing database without causing data loss you need to make sure the new columns/field are optional. This can be done in Prisma by marking the type of the field with a ?.
If you need the field to be mandatory, you could do it in three steps:
Create the new field as optional first in your prisma schema and run a migration
Run a script to update all records with that field to have certain data (what that data should depend on your context). This will have to be done for the production database data as well.
Mark the field is as mandatory in your Prisma schema and run a migration. It will not cause data loss now because the field is non-null for all records in the database.

Full CRUD app without a database possible?

If I use a json file stored in one of my GitHub repos as a mock backend, I know how to fetch and read all the data. Is it also possible to edit or post new data to this json file? Would an alternative mock backend like Mocky.io be a better solution (to achieve full CRUD)?
I think you could store the information inside csv files or somehting like that, you would be recreating a database engine as MongoDB & create your own reader to find the info, or you could store the users info using local Storage,
However this would make your app very limited.
Here's the link for the documentation of local storage
https://developer.mozilla.org/es/docs/Web/API/Window/localStorage
Well if you want to try out CRUD operations you can use free JSON APIs like http://jsonplaceholder.typicode.com/ or
https://mockfirst.com/
where you can create, read, update and delete data using various api end points. It is better to go this way first then you could move on to updating a JSON file.
(UPDATE)
You can use https://jsonbin.io/
Here you can place your own data and use it as an API.

Replace Appcelerator Application database on iOS

Hy, I have an iOS application (only for iOS) developed in Titanium Appcelerator using JavaScript.
I'm trying to use SQLite data bases in my app.
I was able to copy my SQLite database to my project with this:
Ti.Database.install('/baseDados/aquarismo', 'AquaInfo');
This "/baseDados/aquarismo" is the database directory inside my project, and "AquaInfo" is the name of the database after copying it.
Then I can open and close my database to get my data from it.
My problem is when I update my SQLite database I need to update it inside my project. So I replace my database inside my project folder with the new database.
But then I need to delete the old database when my app starts and replace it whit the new one.
I have tried this:
var f = Ti.Filesystem.getFile(
Ti.Filesystem.applicationSupportDirectory, 'database','AquaInfo.sql');
//If it's there, delete it
if(f.exists() == true){
f.deleteFile();
}
// Install fresh database
Ti.Database.install('/baseDados/aquarismo','AquaInfo');
However the database doesn't get replaced by the new one.
How can I update my SQLite database when my iOS app starts?
Whenever you update database whether update your table column or create new table and save your changes, new "AquaInfo.sqlite" file generated.
So we have to replace it because we are updating database from external source.
Solution:
If you want database changes at application starting point. You have to write code manually like create table, add column in manual created table and change data type of certain column.
So you can achieve this via manually write code for creating table and related stuff.

SpagoBI data set: use javascript to access to MongoDB data base

Since data set in SpagoBI could be created using scripts, I need to connect, query my MongoDB data base using javascript (or Groovy).
I need to use scripts to be able to execute aggregation on the mongoDB data, I can't use aggregation directly on my MongoDB because my data type is String
I dont know how to access my Database using scripts
Any ideas?
You should create a Mongo dataset. The steps to create are:
Step1: Create a Mongo datasource in the administrator console. Notes: the type must be JDBC and the value for Class input field must be "mongo"
JDBC: {unit_host}:{port}/${db}
CLASS: mongo
Step2: now you can create a dataset. The procedure is the same of the query datasets. The difference here is the language.. JS instead of SQL.
Take a look at the SpagoBI wiki in particolar here: http://wiki.spagobi.org/xwiki/bin/view/spagobi_server/data_set#HQueryDataSet28Mongo29
When connecting to mongoDB, you pass auth stuff in the url. Since the scripts lies on the client side, it would be hard to make the connection secure (unless you are talking about backend JavaScript). Anybody would be able to see how to connect to your DB and for instance delete all content.
I would suggest a simple api to interface the database. Then u control the access to what a user can do towards the database.
Or have I misunderstood the scenario?

Ruby on Rails - Storing and accessing large data sets

I am having a hard time managing the storage and access of a large dataset within a Ruby on Rails application. Here is my application in a nutshell: I am performing Dijkstra's algorithm as it pertains to a road network, and then displaying the nodes that it visits using the google maps API. I am using an open dataset of the US road network to construct the graph by iterating over two txt files given in the link, but I am having trouble storing this data in my app.
I am under the impression that a large dataset like this not an ActiveRecord object - I don't need to modify the contents of this data, rather be able to access it and cache it locally in a hash to perform ruby methods on it. I have tried a few things but I am running into trouble.
I figured that it would make most sense to parse the txt files and store the graph in yml format. I would then be able to load the graph into a DB as seed data, and grab the graph using Node.all, or something along those lines. Unfortunately, the yml file becomes too large for rails to handle. Running a Rake causes the system to run at 100% for infinity...
Next I figured, well since I don't need to modify the data, I can just create the graph every time the application loads as start of its "initialization." But I don't exactly know where to put this code, I need to run some methods, or at least a block of data. And then store it in some sort of global/session variable that I can access in all controllers/methods. I don't want to be passing this large dataset around, just have access to it from anywhere.
This is the way I am currently doing it, but it is just not acceptable. I am parsing the text files that creates the graph on a controller action, and hoping that it gets computing before the server times out.
Ideally, I would store the graph in a database that I could grab the entire contents to use locally. Or at least only require the parsing of the data once as the application loads and then I would be able to access it from different page views, etc.. I feel like this would be the most efficient, but I am running into hurdles at the moment.
Any ideas?
You're on the right path. There are a couple of ways to do this. One is, in your model class, outside of any method, set up constants like these examples:
MY_MAP = Hash[ActiveRecord::Base.connection.select_all('SELECT thingone, thingtwo from table').map{|one| [one['thingone'], one['thingtwo']]}]
RAW_DATA = `cat the_file` # However you read and parse your file
CA = State.find_by_name 'California'
NY = State.find_by_name 'New York'
These will get executed once in a production app: when the model's class is loaded. Another option: do this initialization in an initializer or other config file. See the config/initializers directory.

Categories

Resources