How to open a temporary file in a browser with Lua? - plugins

I'm currently working on a plugin for NeoVim in which I parse HTML from the current buffer and write it on a temporary file. Now, I want to open the temporary file in the browser, so it would show the result of the parsed HTML, but I can't get it done.
I have tried using os.execute and finding the path of the file, but it doesn't work.
Currently, my function looks like this. buffer_to_string() returns a string which contains all the content of the current buffer and matching_html() returns the matches between the content and a HTML pattern
function M.preview_html()
local content = buffer_to_string()
local matching_html = get_html(content)
local tmp_file = io.tmpfile()
tmp_file:write(matching_html)
end

Related

In VS Code how to search in a project/directory through file content AND file names

I have a VS Code project where I want to search for a string, say "MyDataProvider".
This string appears in the content of some files (as part of URL strings) and in the name of another file (which is the data provider).
How can I search for both in VS Code? The Find in Files command searches only the content.

Read a txt file by URL link in MATLAB

I have a txt file in the following URL path:
https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt
I wana read it into MATLAB. This file contains only an integer value. I used fopen() function, but it gives me error:
The file name contains characters that are not contained in the filesystem encoding. Certain operations may not work as expected.
Then, I used webread() and urlread(), but a big file is generating and not working as expected.
Is there any suggestion to how to read a simple value from an URL link?
It is because the url https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt refers to the dropbox page and not the file. If you add ?dl=1 at the end of the link, then it will refer to the file instead. e.g.
data = urlread('https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt?dl=1')
data =
'100'

How do I prompt the user to choose a file that will be loaded in matlab?

I want the user of a script I'm writing to be able to navigate to a file containing their data and to load the data into the workspace. For example, if a csv file contains two cells with the values 1 and 2 respectively, I want the user to simply choose this file and those two values will be assigned to a variable in the workspace.
I have looked at using:
filename = uigetfile('*.xlsx','*.csv')
But that just returns the name of the file. Perhaps I could construct a full path to where the file they choose is found, and then read it in that way (using xlsread or csvread) but I think I'm probably missing something here. It seems that there should be a more straightforward way of doing it.
I believe that you're looking for the uiopen() function. This function will:
Open dialog box for selecting files to load into workspace.
On default, this function will display in a file explorer dialog box with the filter set to all MATLABĀ® files (with file extensions *.m, *.mlx, *.mat, *.fig, *.mdl, and *.slx).
However, you can import data from data files like CSV files and spreadsheets as well. Simply select the (All Files) option for the Files of Type field.
Once you've selected the data file you're interested in, you will be prompted with another GUI object that previews the data you are about to load into MATLAB's workspace. If you're satisfied with the format of the variables presented in the preview, simply hit the green check-mark at the right-side of the tool-box ribbon in the GUI object and, huzzah, all of the data file's contents have been loaded into separate variables (named according to their respective headers).
Alternatively, though this is undeniably a longer-winded and uglier approach, if you'd like to use the filename returned from uigetfile('*.xlsx', '*.csv'), you could use the importdata() function. This will output a struct that contains each of the variables from your data file as a separate field:
[filename, pathname] = uigetfile( ...
{'*.csv;', 'CSV file (*.csv)';
'*.xlsx', 'Excel Spreadsheet file (*.xlsx)'; ...
'*.*', 'All Files (*.*)'}, 'Pick a File to Import');
full_filename = fullfile(pathname, filename);
[A, delimiterOut] = importdata(full_filename);

Get information about file attachment via perl Mechanize

BACKGROUND
I am experimenting with Mechanize on a web forum. The forum has some file attachments in its threads. The attachment can be of various media types. Each attachment has a link to a server-side program called "attachment.php?" and a unique id which identifies the file. When you visit it in a normal browser, a file is returned and the browser decides what to do with it. If it's an image, the file is displayed in the browser window and the titlebar is set to the filename. If it's another type of file, the browser will ask if you want to download the file (and it automatically sets the filename to the name of the file).
QUESTION
My question is how can I explore the details of such file attachments with Mechanize so that I can determine filetype and filename?
I've already successfully downloaded a file using my program, but I have to tell Mechanize what the filename should be. I would prefer to keep the original filename, but to do that I have to be able to discover it somehow. I know it can be done because my browser is able to determine the filetype and filename.
As a secondary objective I would also like to query the size of the file, if this is possible.
I hope my question makes sense and thank you in advance to anyone who takes the time to answer.
To achieve an inspection of the filetype you have to use $mech->res(). It returns an HTTP::Response object, and this class provides the filename method.
Example:
foreach (#media)
{
print "Fetching " . $_->url() . "\n";
$m->get($_);
my $res = $m->res();
if($res->is_success)
{
my $filename = $res->filename();
print "$filename\n";
}
}

How do I export SAS text string to a Word document using DDE?

I would like to export a string character from SAS to a word document (.docx) using Dynamic Data Exchange (DDE). Is this possible?
The SAS documentation on this is old and suggests I use the following commands:
filename testit dde 'winword|"file_path"!bookmark' notab;
data _null_;
file testit;
put 'insertstuff';
run;
SAS returns an error message:
ERROR: Physical file does not exist
Works for me.
filename testit dde 'winword|"e:\blah.docx"!bookmark' notab;
data null;
file testit;
put 'insertstuff';
run;
Steps:
Create a word document and save it in the specified path.
In word document, create a bookmark by going to Insert->Bookmark, give it a name of 'Bookmark' and press Add
Make sure both word and SAS are open. And that the document is open in word.
Run the SAS code.
Super late to the party, but there are a few issues that could cause that error:
You don't need "" around the filename, should just be:
filename testit dde 'winword|file_path!bookmark' notab;
data _null_;
file testit;
put '[Insert "stuff"]';
run;
The file path may be spelled incorrectly
You may not have permissions to the filepath. This is likely if it is a work machine.
To check:
Navigate to the filepath in the file explorer
Right click on the file
Open properties
Look for your username, click on it, and it will show you what permission you have
You have a missing/incorrect file extension (ie .doc not .docx ect)
Hope you were able to figure this out at the time :P