Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -8,46 +8,35 @@ namespace N
{
public static void Main()
{
var headerNames = new [] { "", "X", "Y", "Z" };
var headers = new [] { "", "X", "Y", "Z" };
var headerColumns = headerNames.Select(name =>
new XElement
(
var cols = headers.Select(name =>
new XElement(
"th",
name,
new XAttribute("text-align", "center")
)
);
var rows = Enumerable.Range(0, 4)
.Select
(
rowIndex =>
new XElement
(
"tr",
new XElement("td", rowIndex),
Enumerable.Range(0, 4)
.Select
(
colIndex =>
new XElement
(
"td",
colIndex,
new XAttribute("text-align", "center")
)
)
var rows = Enumerable.Range(0, 4).Select(ri =>
new XElement(
"tr",
new XElement("td", ri),
Enumerable.Range(0, 4).Select(ci =>
new XElement(
"td",
ci,
new XAttribute("text-align", "center")
)
)
);
)
);
var xml = new XElement
(
var xml = new XElement(
"table",
new XElement
(
new XElement(
"thead",
new XElement("tr", headerColumns),
new XElement("tr", cols),
new XElement("tbody", rows)
)
);

View file

@ -0,0 +1,11 @@
(ns rosettacode.html-table
(:use 'hiccup.core))
(defn <tr> [el sq]
[:tr (map vector (cycle [el]) sq)])
(html
[:table
(<tr> :th ["" \X \Y \Z])
(for [n (range 1 4)]
(->> #(rand-int 10000) (repeatedly 3) (cons n) (<tr> :td)))])

View file

@ -1,9 +1,9 @@
import std.stdio, std.random;
void main() {
import std.stdio, std.random;
writeln(`<table style="text-align:center; border: 1px solid">`);
writeln("<th></th><th>X</th><th>Y</th><th>Z</th>");
foreach (i; 0 .. 4)
foreach (immutable i; 0 .. 4)
writefln("<tr><th>%d</th><td>%d</td><td>%d</td><td>%d</td></tr>",
i, uniform(0,1000), uniform(0,1000), uniform(0,1000));
writeln("</table>");

View file

@ -12,10 +12,10 @@ type row struct {
var tmpl = `<table>
<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>
{{range $ix, $row := .}} <tr><td>{{$ix}}</td>` +
`<td>{{$row.X}}</td>` +
`<td>{{$row.Y}}</td>` +
`<td>{{$row.Z}}</td></tr>
{{range $ix, $row := .}} <tr><td>{{$ix}}</td>
<td>{{$row.X}}</td>
<td>{{$row.Y}}</td>
<td>{{$row.Z}}</td></tr>
{{end}}</table>
`

View file

@ -0,0 +1,7 @@
# Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser.
ConvertTo-Html -inputobject (Get-Date)
# Create a PowerShell object using a HashTable
$object = New-Object -TypeName PSObject -Property (@{'A'=(Get-Random -Minimum 0 -Maximum 10);'B'=(Get-Random -Minimum 0 -Maximum 10);'C'=(Get-Random -Minimum 0 -Maximum 10)})
$object | ConvertTo-Html

View file

@ -0,0 +1,25 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>DisplayHint</th><th>DateTime</th><th>Date</th><th>Day</th><th>DayOfWeek</th><th>DayOfYear</th><th>Hour</th><th>Kind</th><th>Milliseco
nd</th><th>Minute</th><th>Month</th><th>Second</th><th>Ticks</th><th>TimeOfDay</th><th>Year</th></tr>
<tr><td>DateTime</td><td>Sunday, October 26, 2014 2:32:31 PM</td><td>10/26/2014 12:00:00 AM</td><td>26</td><td>Sunday</td><td>299</td><td>14<
/td><td>Local</td><td>563</td><td>32</td><td>10</td><td>31</td><td>635499307515634638</td><td>14:32:31.5634638</td><td>2014</td></tr>
</table>
</body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/><col/><col/></colgroup>
<tr><th>C</th><th>B</th><th>A</th></tr>
<tr><td>8</td><td>7</td><td>3</td></tr>
</table>
</body></html>

View file

@ -0,0 +1 @@
$object | ConvertTo-Html | Out-File -FilePath $env:temp\test.html ; invoke-item $env:temp\test.html

View file

@ -0,0 +1,40 @@
Title.s="Create an HTML table"
head.s=""
head.s+"<html><head><title>"+Title.s+"</title></head><body>"+chr(13)+chr(10)
tablehead.s
tablehead.s+"<table border=1 cellpadding=10 cellspacing=0>"+chr(13)+chr(10)
tablehead.s+"<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>"+chr(13)+chr(10)
index=0
tablebody.s=""
for row=1 to 4
index+1
tablebody.s+"<tr><th>"+str(index)+"</th>"
for col=1 to 3
tablebody.s+"<td align="+chr(34)+"right"+chr(34)+">"+str(Random(9999,1))+"</td>"
next
tablebody.s+"</tr>"+chr(13)+chr(10)
next
tablefoot.s=""
tablefoot.s+"</table>"+chr(13)+chr(10)
foot.s=""
foot.s+"</body></html>"+chr(13)+chr(10)
FileName.s="Create_an_HTML_table.html"
If CreateFile(0,FileName.s)
WriteString(0,head.s)
WriteString(0,tablehead.s)
WriteString(0,tablebody.s)
WriteString(0,tablefoot.s)
WriteString(0,foot.s)
CloseFile(0)
Else
Debug "Not WriteString :"+FileName.s
EndIf
; RunProgram(FileName.s)

View file

@ -0,0 +1,9 @@
<html><head><title>Create an HTML table</title></head><body>
<table border=1 cellpadding=10 cellspacing=0>
<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>
<tr><th>1</th><td align="right">6638</td><td align="right">5838</td><td align="right">5360</td></tr>
<tr><th>2</th><td align="right">2995</td><td align="right">3856</td><td align="right">3093</td></tr>
<tr><th>3</th><td align="right">37</td><td align="right">7644</td><td align="right">812</td></tr>
<tr><th>4</th><td align="right">4428</td><td align="right">1100</td><td align="right">3721</td></tr>
</table>
</body></html>

View file

@ -1,32 +1,32 @@
/*REXX program to create an HTML table of five rows and three columns. */
/*REXX program to create an HTML table of five rows and three columns.*/
arg rows .; if rows=='' then rows=5 /*no ROWS specified? Use default*/
cols = 3 /*specify three columns for table*/
maxRand = 9999 /*4-digit numbers, allow negative*/
headerInfo = 'X Y Z' /*column header information. */
oFID = 'a_table.html' /*name of the output file. */
w = 0 /*number of writes to output file*/
arg rows .; if rows=='' then rows=5 /*no ROWS specified? Use default*/
cols=3
maxRand=9999 /*4-digit numbers, allow negative*/
headerInfo='X Y Z' /*column header information. */
oFID='a_table.html'
call wrt "<html>"
call wrt "<head></head>"
call wrt "<body>"
call wrt "<table border=5 cellpadding=20 cellspace=0>"
call lineout oFid,"<html>"
call lineout oFid,"<head></head>"
call lineout oFid,"<body>"
call lineout oFid,"<table border=5 cellpadding=20 cellspace=0>"
do r=0 to rows /* [↓] handle row zero special. */
if r==0 then call wrt "<tr><th></th>"
else call wrt "<tr><th>" r "</th>"
do r=0 to rows
if r==0 then call lineout oFid,"<tr><th></th>"
else call lineout oFid,"<tr><th>" r "</th>"
do c=1 for cols
if r==0 then call lineout oFid,"<th>" word(headerInfo,c) "</th>"
else call lineout oFid,"<td align=right>" rnd() "</td>"
do c=1 for cols /* [↓] for row zero, add hdrInfo*/
if r==0 then call wrt "<th>" word(headerInfo,c) "</th>"
else call wrt "<td align=right>" rnd() "</td>"
end /*c*/
end /*r*/
end /*r*/
call lineout oFid,"</table>"
call lineout oFid,"</body>"
call lineout oFid,"</html>"
exit
/*─────────────────────────────────────RND subroutine───────────────────*/
/*subroutine was subroutinized for better viewfulabilityness.*/
call wrt "</table>"
call wrt "</body>"
call wrt "</html>"
say; say w ' records were written to the output file: ' oFID
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────one-liner subroutines───────────────*/
rnd: return right(random(0,maxRand*2)-maxRand,5) /*REXX doesn't gen negs*/
wrt: call lineout oFID,arg(1); say '' arg(1); w=w+1; return /*write.*/
/* [↑] functions were subroutinized for better viewabilityness.*/

View file

@ -0,0 +1,17 @@
object TableGenerator extends App {
val data = List(List("X", "Y", "Z"), List(11, 12, 13), List(12, 22, 23), List(13, 32, 33))
def generateTable(data: List[List[Any]]) = {
<table>
{data.zipWithIndex.map { case (row, rownum) => (if (rownum == 0) Nil else rownum) +: row}.
map(row => <tr>
{row.map(cell =>
<td>
{cell}
</td>)}
</tr>)}
</table>
}
println(generateTable(data))
}

View file

@ -0,0 +1,38 @@
function emit_table {
nameref d=$1
typeset -i idx=0
echo "<table>"
emit_row th "" "${d[idx++][@]}"
for (( ; idx<${#d[@]}; idx++ )); do
emit_row td $idx "${d[idx][@]}"
done
echo "</table>"
}
function emit_row {
typeset tag=$1; shift
typeset row="<tr>"
for elem; do
row+=$(printf "<%s>%s</%s>" "$tag" "$elem" "${tag## *}")
done
row+="</tr>"
echo "$row"
}
function addrow {
nameref d=$1
typeset n=${#d[@]}
typeset -i i
for ((i=0; i<$2; i++)); do
d[n][i]=$(( $RANDOM % 10000 ))
done
}
n=3
typeset -a data
data[0]=("X" "Y" "Z")
for i in {1..4}; do
addrow data $n
done
emit_table data

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.01" indent="yes"/>
<!-- Most XSLT processors have some way to supply a different value for this parameter -->
<xsl:param name="column-count" select="3"/>
<xsl:template match="/">
<html>
<head>
<title>Rosetta Code: Create an HTML table (XSLT)</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
<xsl:variable name="values" select="/*/*"/>
</xsl:template>
<!--
Rendering HTML from XSLT is so basic as to be trivial. The trickier part of this transform is taking the
single-column list of numbers in the input and folding it into multiple columns. A common strategy is to only
apply templates to every Nth value in the list, but then to have that template pull in the skipped values to
form a row.
-->
<xsl:template match="/numbers">
<table>
<tr>
<th/>
<th>X</th>
<th>Y</th>
<th>Z</th>
</tr>
<!--
Here, we have the template applied to every Nth input element rather than every element. In XSLT,
indices are 1-based, so the start index of every row mod N is 1.
-->
<xsl:apply-templates select="number[position() mod $column-count = 1]"/>
</table>
</xsl:template>
<xsl:template match="number">
<tr>
<th>
<xsl:value-of select="position()"/>
</th>
<!--
Here, we compensate for the skipping by including the skipped values in the processing for this value.
-->
<xsl:for-each select=". | following-sibling::number[position() &lt; $column-count]">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<numbers>
<number>1578</number>
<number>4828</number>
<number>1154</number>
<number>4950</number>
<number>6497</number>
<number>2355</number>
<number>9341</number>
<number>1927</number>
<number>8720</number>
<number>4490</number>
<number>1218</number>
<number>6675</number>
<number>8181</number>
<number>1403</number>
<number>4637</number>
</numbers>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rosetta Code: Create an HTML table (XSLT)</title>
</head>
<body><table>
<tr>
<th></th>
<th>X</th>
<th>Y</th>
<th>Z</th>
</tr>
<tr>
<th>1</th>
<td>1578</td>
<td>4828</td>
<td>1154</td>
</tr>
<tr>
<th>2</th>
<td>4950</td>
<td>6497</td>
<td>2355</td>
</tr>
<tr>
<th>3</th>
<td>9341</td>
<td>1927</td>
<td>8720</td>
</tr>
<tr>
<th>4</th>
<td>4490</td>
<td>1218</td>
<td>6675</td>
</tr>
<tr>
<th>5</th>
<td>8181</td>
<td>1403</td>
<td>4637</td>
</tr>
</table></body>
</html>