ESP32 OTA read local files - html

I have this code in html, which has a form to send files, but I would like to read these files directly from a path on the computer, how do I do that? I'm new to the language
Thanks
`
const char* serverIndex =
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
"<input type='file' name='update'>"
"</form>"
"<div id='prg'>Progresso: 0%</div>"
"<script>"
"$('form').submit(function(e){"
"e.preventDefault();"
"var form = $('#upload_form')[0];"
"var data = new FormData(form);"
" $.ajax({"
"url: '/update',"
"type: 'POST',"
"data: data,"
"contentType: false,"
"processData:false,"
"xhr: function() {"
"var xhr = new window.XMLHttpRequest();"
"xhr.upload.addEventListener('progress', function(evt) {"
"if (evt.lengthComputable) {"
"var per = evt.loaded / evt.total;"
"$('#prg').html('Progresso: ' + Math.round(per*100) + '%');"
"}"
"}, false);"
"return xhr;"
"},"
"success:function(d, s) {"
"console.log('Sucesso!')"
"},"
"error: function (a, b, c) {"
"}"
"});"
"});"
"</script>";
`
Example:
i would like to read this file
file:///C:/Users/Matheus/Desktop/test.bin

Related

Powershell using "at-run" parameters to call functions based on which parameter is called

How to use the "at-run" parameters as parameters within the function.
Right now my code is returning all data/value regardless of what is enter for the "at-run" parameters.
For example, I will like to match the $Server_Name from the "at-run" parameters with the foreach loop, so that only data with the matching $Server_Name is return.
function StartServer{
Param (
[Parameter (Mandatory=$true)] [STRING] $Region,
[Parameter (Mandatory=$true)] [STRING] $Env,
#[STRING] $Env,
[Parameter (Mandatory=$true)] [STRING] $ScriptName, #$ScriptName
[Parameter (Mandatory=$true)] [STRING] $Server_Name
#[STRING] $Server,
#[STRING] $Services
)
#Write-Output ("Region: "+ $Region + " Env: " + $Env + " ScriptName: " + $ScriptName + " Server_Name: " + $Server)
#$startDate = Get-Date;
$Sourcefile = "C:\Users\ Scripts\CLEAN10182019.csv"
$StartProperties = (Import-Csv $Sourcefile)
$Sorted = $StartProperties |select Server_Name,Service_Name, Start_Order, Start_Flag, Start_Wait | Sort-Object -Property Server_Name, {[int]$_.Start_Order}|Format-Table
#$Sorted
foreach($line in $StartProperties)
{
$Server_Name = [string]$line.'Server_Name'
$Service_Name = [string]$line.'Service_Name'
$Start_Order = [string]$line.'Start_Order'
$Start_Wait= [string]$line.'Start_Wait'
$file = #"Matches? " + $Server_Name
"Start " + $Service_Name + " " + " Timeout " + $Start_Wait
Write-Output $file
}
}
StartServer
The quickest and easiest way I can think of might be to only execute the code if the service name is passed in-
foreach($line in $StartProperties) {
if ([string]$line.'Server_Name' -eq $Server_Name) {
$Server_Name = [string]$line.'Server_Name'
$Service_Name = [string]$line.'Service_Name'
$Start_Order = [string]$line.'Start_Order'
$Start_Wait= [string]$line.'Start_Wait'
$file = #"Matches? " + $Server_Name
"Start " + $Service_Name + " " + " Timeout " + $Start_Wait
Write-Output $file
}
}
Does that look like what you're looking for?
If I understand you correctly, you want match only those CSV rows whose Server_Name column matches the $Server_Name parameter value:
Import-Csv $Sourcefile | Where-Object Server_Name -eq $Server_Name | ForEach-Object {
# Synthesize and output a filename.
"Start " + $_.Service_Name + " " + " Timeout " + $_.Start_Wait
}
If you want to output the synthesized string as part of an object, to be presented in tabular form on output, do something like the following:
Import-Csv $Sourcefile | Where-Object Server_Name -eq $Server_Name | ForEach-Object {
# Create a custom object with the properties of interest:
[pscustomobject] #{
# Other properties
Server_Name = $_.Server_Name # ...
FileName = "Start " + $_.Service_Name + " " + " Timeout " + $_.Start_Wait
}
}
If your output objects have 4 or fewer properties, they automatically print as if they had been piped to Format-Table, so you'll get something like the following:
Server_Name FileName
----------- --------
server1 Start service1 Timeout 20
server2 Start service2 Timeout 10
...

How to enter new line to html with Powershell

I have a PowerShell script that opens an IE browser and fill a form.
I also have an csv file with phone numbers. how can I insert each phone number to new line on the value tag?
tried already:
$phoneBox = $IE.Document.getElementById($phonesID)
$phones = Get-Content -Path "c:\phones.csv"
foreach($p in $phones)
{
$phoneBox.value += "<br>" + $p + "<\br>"
}
and also:
$phoneBox = $IE.Document.getElementById($phoneID)
$phones = Get-Content -Path "c:\phones.csv"
foreach($p in $phones)
{
$phoneBox.value += $p + "\n"
}
and also:
$phoneBox = $IE.Document.getElementById($phoneID)
$phones = Get-Content -Path "c:\phones.csv"
foreach($p in $phones)
{
$phoneBox.value += $p + "
" + "
"
}
EDIT:
The Html element I AM REFERING TO IS:
<textarea name="ctl00$MainContent$reciSel$TabsContacts$tabFromFile$txtFromFile" tabIndex="0" id="ctl00_MainContent_reciSel_TabsContacts_tabFromFile_txtFromFile" style="width: 98%; height: 386px; overflow-x: hidden;" onkeyup="PhoneNumbersTxt_onChange(this.value);" onkeypress="AddNewLine(this,event);" rows="2" cols="20" wrap="off" autocomplete="off">Here I need to enter each number to new line</textarea>
Literal whitespace is not parsed as formatting information in HTML (all consecutive whitespace is collapsed to a single space in the output).
Either put each phone number in a separate paragraph
$phoneBox.value += '<p>' + $p + '</p>'
or (if you want it in a single block element with a linebreak after each entry) put a single <br> (or <br/> if you want valid XHTML) after the number:
$phoneBox.value += $p + '<br>'
That does not apply to the content of textareas, though. For those you add linebreaks like this (LF only):
$phoneBox.value += $p + "`n"
or like this (CR-LF):
$phoneBox.value += $p + "`r`n"
PowerShell escape sequences start with a backtick, not a backslash.

How do you create an HTML table in Ruby?

I want to create a 2x2 table in Ruby in order to output a side-by-side comparison of some XML files. The first row would just be headers, the next row would be the files.
From what I understand, a very simple script like that could do the job, but I might have missed something from your question:
# Assuming your xml files are xml1.xml and xml2.xml, this will create an HTML file called result.html containing the HTML table
html = ""
html += "<html>"
html += "<table>"
html += "<tr><td>First XML File</td><td>Second XML file</td></tr>"
html += "<tr>"
html += "<td>"
html += File.read("xml1.xml", :encoding => "UTF-8").encode(:xml => :text)
html += "</td>"
html += "<td>"
html += File.read("xml2.xml", :encoding => "UTF-8").encode(:xml => :text)
html += "</td>"
html += "</tr>"
html += "</table>"
html += "</html>"
%x(echo '#{html}' >> "result.html")
If you want to have pretty-indentation on top of that, you can use ruby core REXML::Document which has it built-in. You also have to nest your pretty-indented XML in a pre tag for it to display well:
require "rexml/document"
doc1 = REXML::Document.new File.read("xml1.xml", :encoding => "UTF-8")
out1 = ""
doc1.write(out1, 2)
doc2 = REXML::Document.new File.read("xml2.xml", :encoding => "UTF-8")
out2 = ""
doc2.write(out2, 2)
html=""
html += "<html>"
html += "<table>"
html += "<tr><td>First XML File</td><td>Second XML file</td></tr>"
html += "<tr>"
html += "<td><pre>"
html += out1.encode(:xml => :text)
html += "</pre></td>"
html += "<td><pre>"
html += out2.encode(:xml => :text)
html += "</pre></td>"
html += "</tr>"
html += "</table>"
html += "</html>"
%x(echo '#{html}' >> "result.html")

Enterprise Architect code generation templates: import hierarchical package structure as a string

Problem
In Enterprise Architect 7.1.834 in the code generation templates it is possible to print all the parent packages that a class belongs to in the scope of the File template?
The reason this is needed is to generate multi-include guards compliant with my companies coding standard
What doesn't work
I have tried both:
%list="Namespace__Notes" #separator="-"%
and
%packageName%
The output of both only prints the top-level parent package (Package1) but I would like to see:
Package1-Package2-Package3
Has anyone found a way to do this?
Namepace__Notes
Namepace__Notes is a custom template with Namepace type, the contents are ar follows
%PI=""%
%packageName%
[Edit] Dirty Solution
My current (dirty) solution is to mangle the file-path. Am I missing something?
The code:
$l_backslash = %REPLACE("\z","z","")%
$filepath = %filePath%
$upper_filepath = %TO_UPPER($filepath)%
$upper_package_as_path = $l_backslash + %TO_UPPER(packageName)% + $l_backslash
$upper_package_base_len = %LENGTH(packageName)%
$package_path_pos = %FIND($upper_filepath,$upper_package_as_path)%
%if $package_path_pos != "-1" and $package_path_pos != "0"%
$upper_filepath = %MID($upper_filepath,$package_path_pos)%
%endIf%
$file_define = "_" + $upper_filepath + "__"
$file_define = %REPLACE($file_define,".","_")%
$file_define = %REPLACE($file_define,$l_backslash,"_")%
$file_define = %REPLACE($file_define,"/","_")%
$body += "/**************************************************************************//**"
$body += "\n * \file " + %fileName%
$body += "\n *"
$body += "\n * \brief " + %elemType% + " " + %className% + " header file"
$body += "\n *"
$body += "\n * \author " + %classAuthor ? value : "<unknown>"%
$body += "\n *"
$body += "\n *****************************************************************************/"
$body += "\n"
$body += "\n#ifndef " + $file_define
$body += "\n#define " + $file_define
$body += "\n"
%packagePath% gives you the dot-separated package hierarchy, while %classQualName% yields the ::-separated class hierarchy (for inner classes).
This is for the current version, I don't know whether these macros were present as far back as 7.1. You should seriously consider upgrading, as the current version is 9.3 and EA is backwards-compatible wrt project contents.
In EA 10 %packagePath% also gives only top level package in File template
[Edit] Another dirty and partial solution.
I'v made a new custom templates, Namespace__fullName:
$prevName = %list="Namespace__fullName"%
%if $prevName != ""%
%packageName%::$prevName
%else%
%packageName%
%endIf%
;
and Class__fullQualName:
%list="Namespace__fullName"%::%classQualName%
This will work in simple cases when the source file contains only 1 class (possibly with nested items) and, therefore, only 1 namespaces hierarchy.

Importing XPM graphics into an HTML5 canvas

Is this possible?
I am trying to port an old professor's demo-game into a web-playable format for fun, and he had setup all the graphics in the XPM format.
Is there some way to load XPM files directly into an HTML5 canvas? I could probably get by with loading them into an image editor and converting...but I'd rather stay as true to the original source as possible.
You could probably write some sort of parser for XPM in JavaScript and render canvas pixels using a similar approach to this question, however I think it'd be more efficient just to use something like ImageMagick and do a one off conversion:
mogrify -format png *.xpm
I made a little plugin to do this, there's a lot to improve but maybe it can help you... you can see the demo here: http://cortezcristian.com.ar/xpm2canvas/
You can also play with the demo in this fiddle: http://jsfiddle.net/crisboot/aXt3G/
<script src="./js/libs/jquery-1.7.1.min.js"></script>
<script src="./js/jquery.xpm2canvas.js"></script>
<script>
var pseudoXMP = [
/* <Values> */
/* <width/cols> <height/rows> <colors> <char on pixel>*/
"40 40 6 1",
/* <Colors> */
" c none",
". c #ffffff",
"X c #dadab6",
"o c #6c91b6",
"O c #476c6c",
"+ c #000000",
/* <Pixels> */
" ",
" ",
" ",
" . .X..XX.XX X ",
" .. .....X.XXXXXX XX ",
" ... ....X..XX.XXXXX XXX ",
" .. ..........X.XXXXXXXXXXX XX ",
" .... ........X..XX.XXXXXXXXX XXXX ",
" .... ..........X.XXXXXXXXXXX XXXX ",
" ooOOO..ooooooOooOOoOOOOOOOXX+++OO++ ",
" ooOOO..ooooooooOoOOOOOOOOOXX+++OO++ ",
" ....O..ooooooOooOOoOOOOOOOXX+XXXX++ ",
" ....O..ooooooooOoOOOOOOOOOXX+XXXX++ ",
" ..OOO..ooooooOooOOoOOOOOOOXX+++XX++ ",
" ++++..ooooooooOoOOOOOOOOOXX+++ +++ ",
" +++..ooooooOooOOoOOOOOOOXX+++ + ",
" ++..ooooooooOoOOOOOOOOOXX+++ ",
" ..ooooooOooOOoOOOOOOOXX+++ ",
" ..ooooooooOoOOOOOOOOOXX+++ ",
" ..ooooooOooOOoOOOOOOOXX+++ ",
" ..ooooooooOoOOOOOOOOOXX+++ ",
" ..oooooOooOOoOOOOOOXX+++ ",
" ..oooooooOoOOOOOOOOXX+++ ",
" ..ooooOooOOoOOOOOXX+++ ",
" ..ooooooOoOOOOOOOXX++++ ",
" ..o..oooOooOOoOOOOXX+XX+++ ",
" ...o..oooooOoOOOOOXX++XXX++ ",
" ....OO..ooOooOOoOOXX+++XXXX++ ",
" ...oo..+..oooOoOOOXX++XXooXXX++ ",
" ...ooo..++..OooOOoXX+++XXooOXXX+ ",
" ..oooOOXX+++....XXXX++++XXOOoOOXX+ ",
" ..oooOOXX+++ ...XXX+++++XXOOooOXX++ ",
" ..oooOXXX+++ ..XX+++ +XXOOooOXX++ ",
" .....XXX++++ XXXXXXX++ ",
" ....XX++++ XXXXXXX+ ",
" ...XX+++ XXXXX++ ",
" ",
" ",
" ",
" "];
$(document).ready(function(){
$('#xmp2canvas').xpm2canvas({xpm:pseudoXMP});
});
</script>
IIRC, the rendering context for a canvas element in such a context relies on manipulating the src attribute of an embedded img tag. As such, presumably XPM files only stand a chance of working if the browser in question supports them.
The best way to check this would be to test it. The accepted answer for this question contains some code that should help:
importing image on canvas html5