The simpliest way to store data on pc - html

I'm creating a page for myself that could be accessed without internet connection (local storage only).
I want that page to somehow store data (that I put in the website) on my computer.
I've heard there are ways to edit .txt files with a help of php?
Also maybe Chrome could somehow save that info easier?
Appreciate any help
EDIT: I want a fast and easy access to a website via Chrome only, so I prefer not to be using XAMPP or any other software.

The easiest way would be to use HTML5's localStorage (no server-side languages needed), but it won't be easy to get that data outside of your page (I understood you'll be using that offline page which has stored data).
It's as simple as:
window.localStorage.setItem('myItem', 'Hello World');
And then to get it, you'd just do:
window.localStorage.getItem('myItem');
Array approach works as well (localStorage.myItem, etc.).
Read more about it here and here.
Here is a simple example from above: http://jsfiddle.net/h6nz1Lq6/
Notice how the text remains even after you remove the setter line and rerun the script (or just go to this link: http://jsfiddle.net/h6nz1Lq6/1/).
The downside of this approach is that the data can easily be cleared by accident (by clearing browser/website data, but again this is similar to accidental deleting of a file, so nothing to be afraid of if you know what you're doing) and that it doesn't work across browsers (each browser stores its own localStorage).
If you still decide to use a server-side language, there are millions of tutorials about them. For a beginner, it would probably be the easiest to use a simple PHP script to write a file, but that would require using a server on your machine.

PHP example:
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
Taken from http://www.w3schools.com/php/func_filesystem_fwrite.asp

You can read and write directly to storage with PHP or use a database for i/o. Check in PHP+MySQL for a common solution and use file upload with HTML or textarea field for plain text.

Related

Choice of database for a dictionary which can be edited as plain text

I am creating a dictionary app but I am not sure what kind of database to use !
My Requirements :
Support for Unicode characters.
Reasonably Fast search.
In case of an installed version of the app, the database file can be edited using a text editor (such as notepad).
I want to implement a web version of the app (WHICH USES THE SAME DATABASE FILE USED BY THE INSTALLED VERSION) and viewers can add/modify entries so it requires concurrent access via network.
Easy to parse in any programming language.
Expecting a maximum file size of 100 MB (May not reach anywhere near that but just to make it future proof.)
So with my limited knowledge I ended up with 3 options : CSV, XML or JSON. I prefer CSV for easy editing.
I understand that they are not as good as RDBMS but for the specific scenario is it possible to use any of these or how good can they perform?
Any alternate ideas are also welcome !
Thanks in advance.
I think that using a single file as a "database" is not such a great choice if you think/plan to extend your application further.
My recommendation is SQLite (https://www.sqlite.org/about.html). As it is currently promoted on their website it's suitable on almost all of your requirements except that of being edited with a text editor. But I think that are easy enough solutions for content management as well, like SqliteBrowser http://sqlitebrowser.org/

Is there a way to define a variable in HTML?

I have some text that is pretty repetitive on a web page. It can change from time to time. If I write it in 10 different places then need to change it, I have to go through the html and change it in every single place.
As an example of what I'm looking for, instead of writing "Stack Overflow is the best website ever" over and over again, is there a way that I could write something like variable:stackoverflow="Stack Overflow is the best website ever" in one place then write "stackoverflow" in the 10 different places I need the text. That way if/when I need to change it I can just change it in the one place, not the 10 different places on the page.
No.
Typically this problem is solved by generating HTML using a programming language, often in combination with a template language.
This can be done either at:
build time, generating static files and uploading them to a server), e.g. using a tool such as assemble
server side (on demand when the page is requested), e.g. using FastCGI and the programming language of your choice
client side (using JavaScript running in the browser … although this isn't considered best practise).
You can't declare such variables in HTML. I guess, it's the best way, to use PHP. PHP is executed by the server and a HTML-Document will be send to the client. JavaScript is executed by the client and some users denie the JavaScript-execution.
In my opinion it's he best way is to use PHP.
For display texts in PHP, you should check out the website PHP.net

Objective-C - Parsing a .csv, extracting and inserting information, then displaying the .csv as an interface for editing

This question has been troubling me for the past week. Below, I will list my issue, and the research I have put into it.
The scenario: I was given a .csv file with 5000 rows and three columns. The three columns are defined as:
Site ID|Site Name|Site URL
My task: To create an HTML interface for the designers of the company to rate each site on a scale of 1-5.
My plan of action: I am a new hire. I am getting accustomed to the language I was hired for, which was Objective-C.
My algorithm for the project was to:
Parse the .csv
Remove the "Site Name" variable
Create a new .csv that contains the below variables: Site ID|Site URL|Rating|Image
Display the new .csv (with all aforementioned items) as an HTML page where there are toggles for "Ratings", which when pressed, will log the rating into the .csv which it was imported (or loaded) from.
The "Image" section I will be using a piece of software by the name of Paparazzi (on the Mac OS X operating system) which takes a fully formatted screenshot of the main page and saves it as a PNG file. I plan on using the file extension URL (which is stored locally) and load it into the "Image" column, thus when the designer clicks on the image, he is able to load the image that is stored locally.
My issue: As Objective-C is not entirely a scripting language, I am confused with some of the libraries I may need and/or methods I can implement this. I have the algorithm, but I am wholy unsure with the implementation.
My questions: If you have done a project similar to this before with Objective-C, what tips can you provide for me? How does one load the .csv as a HTML interface where upon edit, it will save this edit into the .csv? Will I need any servers for this, or is everything executable from just a machine? How do you grab an image (stored locally), extract its file extension, and load it onto the .csv?
The most important question: Is this achievable through Objective-C? My reasoning behind it is, I want to advance my knowledge of OC through a task like this. Yes, using Python is easier, but is it possible to do this with Objective-C?
Thank you.
It certainly is achievable, but I doubt you'd really want to go this way. If I understand it correctly, you want to serve the HTML page to others via web browser - that would mean either writing a (simple) http daemon, that would run on the server or writing a CGI script that would communicate with a standard http daemon. Python/PHP/Ruby do this for you readily, so there is much less room for possible errors.
As for
As Objective-C is not entirely a scripting language
I would perhaps rephrase it as
As Objective-C is entirely not a scripting language

HTML5: accessing large structured local data

Summary:
Are there good HTML5/javascript options for selectively reading chunks of data (let's say to be eventually converted to JSON) from a large local file?
Problem I am trying to solve:
Some existing program locally and outputs a ton of data. I want to provide a browser-based interactive viewer that will allow folks to browse through these results. I have control over how the data is written out. I can write it all out in one big file, but since it's quite large, I can't just read the whole thing in memory. Hence, I am looking for some kind of indexed or db-like access to this from my webapp.
Thoughts on solutions:
1. Brute-force: HTML5 FileReader API has a nice slice() method for random access. So I could write out some kind of an index in the beginning of the file, use it to look up positions of other stored objects, and read them whenever they're needed. I figured I'd ask if there are already javascript libraries that do something like this (or better) before trying to implement this ugly thing.
2. HTML5 local database. Essentially, I am looking for an analog of HTML5 openDatabase() call that would open (a read-only) connection to a database based on a user-specified local file. From what I understand, there's no way to specify a file with a pre-loaded database. Furthermore, even if there was such a hack, it's not clear whether the local file format would be the same across browsers. I've seen the phonegap solution that populates the browser local database from SQL statements. I can do that too, but the data I am talking about is quite large (5-10GB): it will take a while to load, and such duplication seems rather pointless.
HTML5 does not sound like the appropriate answer for your needs. HTML5's focus is on the client side, and based on your description you're asking a lot out of the browsers, most likely more than they can handle.
I would instead recommend you look at a server-based solution to deliver the desired goal/results to the client view, something like Splunk would be a good product to consider.

How can I extract HTML content efficiently with Perl?

I am writing a crawler in Perl, which has to extract contents of web pages that reside on the same server. I am currently using the HTML::Extract module to do the job, but I found the module a bit slow, so I looked into its source code and found out it does not use any connection cache for LWP::UserAgent.
My last resort is to grab HTML::Extract's source code and modify it to use a cache, but I really want to avoid that if I can. Does anyone know any other module that can perform the same job better? I basically just need to grab all the text in the <body> element with the HTML tags removed.
I use pQuery for my web scraping. But I've also heard good things about Web::Scraper.
Both of these along with other modules have appeared in answers on SO for similar questions to yours:
how can i screen scrape with perl
how can i extract xml of a website and save in a file using perls lwp
how do i extract an html title with perl
can you provide an example of parsing html with your favorite parser
how do I extract content from html file using perl
HTML::Extract's features look very basic and uninteresting. If the modules that draegfun mentioned don't interest you, you could do everything that HTML::Extract does using LWP::UserAgent and HTML::TreeBuilder yourself, without requiring very much code at all, and then you would be free to work in caching on your own terms.
I've been using Web::Scraper for my scraping needs. It's very nice indeed for extracting data, and because you can call ->scrape($html, $originating_uri) then it's very easy to cache the result you need as well.
Do you need to do this in real-time? How does the inefficiency affect you? Are you doing the task serially so that you have to extract one page before you move onto the next one? Why do you want to avoid a cache?
Can your crawler download the pages and pass them off to something else? Perhaps your crawler can even run in parallel, or in some distributed manner.