Why does ocaml ignore one function and does all the rest? - function

So i have this code, which its supposed to give me an yes or no answer. It doesnt give me any errors yet it seems like it doesnt enter my rec func function, which makes it give the wrong answer. Would much apreciate the help
let n = read_int()
let () =
let valor = ref true in
let i = ref 1 in
let a = ref 0 in
let b = ref 0 in
let c = ref 0 in
let e = ref 1 in (* 1 = variavel 0 = conetor*)
let rec func() =
i:=!i+1;
let () = Printf.printf "i" in
let r = read_line() in
if r="(" then a:=!a+1;
if r=")" then b:=!b+1;
if (r=")" && !e=1) then valor:=false;
if (r="(" && !e=0) then valor:=false;
if !b > !a then valor:=false;
if ((r="&" || r="|" || r="->" || r="<->")&&(!c>0 || !e=1)) then valor:=false;
if (r="&" || r="|" || r="->" || r="<->") then e:=1;
if r="!" then c:=!c+1;
if (r<>"!" && r<>"(" && r<>")" && r<>"&" && r<>"|" && r<>"->" && r<>"<->" && !e=0) then valor:=false;
if (r<>"!" && r<>"(" && r<>")" && r<>"&" && r<>"|" && r<>"->" && r<>"<->") then e:=0;
if (r<>"!" && r<>"(" && r<>")" && r<>"&" && r<>"|" && r<>"->" && r<>"<->" && !c>0) then c:=0;
if !i = n-1 then () else func()
in
if !e=1 then valor:=false;
if !c>0 then valor:=false;
if !a <> !b then valor:=false;
let msg = if !valor then "YES" else "NO" in
Printf.printf "%s \n" msg

Just skimming your code I see a definition of a function named func but no calls to this function (other than from inside the function).
I'd say you need to actually call func. That should get you started.

Related

Making Script Quicker/more efficient

I am attempting to have a script check sheet1 for first and last names (2 cells), use the first and last name of each person in sheet1, then in sheet2 check each person for a value in 4-5 rows greater than 0.
The issue is that certain names are in different columns and I need to check one column and have those names in that one column checked against a large (180 cells) list of names. This is the part where it times out.
I have the code fully functioning and working, but it uses some parts too heavily and ends up timing out. The getvalue function is used heavily and I am unsure of a better way to use it. I am looking for how to make it more efficient and or run better.
I may just have to input the names in the code to make it faster, but I was hoping for a more user-friendly approach so that names could change in sheet1 and format automatically in the script.
Thank you!
function getvalue(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2').getRange(CellName).getValues();
}
function getAdvisee(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1').getRange(CellName).getValues();
}
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
var columnAmount = 3;
var advisoryStudent = getvalue('a' + columnEnrichment);
var studentEnrichment = getvalue('g'+ columnEnrichment);
var hours = Utilities.formatDate(studentEnrichment, 'EST', 'mm');
var minutes = Utilities.formatDate(studentEnrichment, 'EST', 'ss');
var teacherEmail = getAdvisee('b2');
var student1 = getAdvisee('b3');
var student1F = getAdvisee('b3');
var student2 = getAdvisee('b4');
var student2F = getAdvisee('b4');
var student3 = getAdvisee('b5');
var student3F = getAdvisee('b5');
var student4 = getAdvisee('b6');
var student4F = getAdvisee('b6');
var student5 = getAdvisee('b7');
var student5F = getAdvisee('b7');
var student6 = getAdvisee('b8');
var student6F = getAdvisee('b8');
var student7 = getAdvisee('b9');
var student7F = getAdvisee('c9');
var student8 = getAdvisee('b10');
var student8F = getAdvisee('c10');
var student9 = getAdvisee('b11');
var student9F = getAdvisee('c11');
var student10 = getAdvisee('b12');
var student10F = getAdvisee('c12');
var student11 = getAdvisee('b13');
var student11F = getAdvisee('c13');
for (columns; columns <= LastRow && columns <= 160; columns++) {
var advisoryStudent = getvalue('a' + columns);
var advisoryStudentSp = getvalue('b' + columns);
var reminderCount = getvalue('e' + columns);
var reminderLink = getvalue('m'+columns);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if ( getvalue('e' + columns) > 0 ) {
reminders = reminders + getvalue('b' + columns) + ' ' + getvalue('a' + columns) + ': ' + reminderCount + '<br>Reminder Link: ' + reminderLink + '<br>';
}
}
}
for (columnassignments; columnassignments <= LastRow && columnassignments <= 160; columnassignments++) {
var advisoryStudent = getvalue('a' + columnassignments);
var advisoryStudentSp = getvalue('b'+columnassignments);
var assignmentCount = getvalue ('f' + columnassignments);
var assignmentLink = getvalue('n' + columnassignments);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('f' + columnassignments) > 0) {
assignments = assignments + getvalue('b' + columnassignments) + ' ' + getvalue('a' + columnassignments) + ': ' + assignmentCount + '<br>Assignment Link: ' + assignmentLink + '<br>';
}
}
}
for (columnAmount; columnAmount <= LastRow && columnAmount <= 160; columnAmount++) {
var advisoryStudent = getvalue('a' + columnAmount);
var advisoryStudentSp = getvalue('b' + columnAmount);
var amountowed = getvalue ('i' + columnAmount);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('i' + columnAmount) > 0) {
amount = amount + getvalue('b' + columnAmount) + ' ' + getvalue('a' + columnAmount) + ': ' + '$' + amountowed + '<br>';
}
}
}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Status Calculator');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
for (columnEnrichment; columnEnrichment <= LastRow && columnEnrichment <= 160; columnEnrichment++) {
var advisoryStudent = getvalue('a'+columnEnrichment);
var advisoryStudentSp = getvalue('b' + columnEnrichment);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') > 0 || Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') > 0){
enrichment = enrichment + getvalue('b' + columnEnrichment) + ' ' + getvalue('a' + columnEnrichment) + ': ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') + ' hours ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') + ' minutes <br>'
}
}
}
}
EDIT:
This portion just has a list of names in one column and searches for one word in the entire 200 row column and returns the rows with that word, then returns it again if it is greater than 5.
If I had it just looking for numbers greater than or equal to 5 and using a getvalue function, would that be the most efficient way to return names with values of 5 or more?
function getValues(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).getValues();
}
function setvalue(CellName, value) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).setValue(value);
}
function test(i) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh2 = ss.getSheetByName('Sheet2');
var data = sh2.getRange('A1:C200').getValues();
var amount = sh2.getRange('c1:c200').getValues()
var findthis = sh2.getRange('e1').getValues();
var acol = sh2.getRange(1,sh2.getLastRow(),1,1).getValues();
var bcol = sh2.getRange(1,sh2.getLastRow(), 2, 1).getValues();
var test = acol.join().split(',');
var test2 = bcol.join().split(',');
for (i = 0; i<data.length; i++) { //search all rows
if ('wet' == data[i][0]) { //finds wet in the data column and returns row
Logger.log('testing' + ' row ' + (i+1))
if (amount[i][0] >= 5) { //search if c >= 5
Logger.log('Larger ' + ' row ' + (i+1))
}
}
}
}
I would suggest grouping your data into arrays by its natural grid ranges and then accessing the values by array index.
Something along the lines of:
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh_1 = ss.getSheetByName('sheet1');
var sh_2 = ss.getSheetByName('sheet2');
...
// Get all related values into array & retrieve each row record by index
var student = sh_1.getRange("B3:C13").getValues(); // student[row][col] :ex: student11 => student[12][0]::student11F => student[12][1]
...
// remove the for loop & get all values in a col with one call per col
//(this could be optimized further)
var a_col = sh_2.getRange(1, sh_2.getLastRow(), 1, 1).getValues(); // col a rows 1-lastrow()
var b_col = sh_2.getRange(1, sh_2.getLastRow(), 2, 1).getValues(); // col b rows 1-lastrow()
// Flatten the array to make searching that column easier
var advisoryStudent = a_col.join().split(",")
var advisoryStudentSp = b_col.join().split(",")
// etc ...
// To check if student11 is in advisoryStudentSp: (can loop through students here)
// -1 means not found
// any other number is the index position of `advisoryStudentSp[i]`
// if 5 is returned then student11 matched the value in sheet2 colB row6
Logger.log("student11 is in position: %s", advisoryStudentSp.indexOf(student[12][0]))
}
edit: added the somewhat important .getValues()
Rather than retrieve the cell values one by one using your getValue() / getAdvisee() formulas you need to read the entire sheets or the relevant ranges all at once using Range.getValues(), then work with the data in the arrays.
The key issue here is that each individual call to Range.getValues() consumes a lot of time, whether you read in 100 cells at once or a single cell value. Thus your current approach of reading in one cell at a time is extremely slow (as you are seeing).
Refactoring in this way is too large to undertake as part of my answer, but once completed this script will run in just a couple seconds.

Why exactly the output of this expression return true

I have this expression:
!(1 && !(0 || 1))
The output returns 1 true. And that's ok. When I read the expression I came to the same conclusion before checking the output. But I would really appreciate if someone can explain to me why the returning value is true, that way, I will have a better understanding of boolean logic and how to implement better evaluators in my code.
Key observation here: ! is not, && is the "And" operator, and || is the "Inclusive Or" Operator.
What are you really asking when you say "why it's true?".
0 = false
1 = true
AND && table
0 0 -> 0
0 1 -> 0
1 0 -> 0
1 1 -> 1
OR || table
0 0 -> 0
0 1 -> 1
1 0 -> 1
1 1 -> 1
NOT ! table
0 -> 1
1 -> 0
With parentheses implying "do this first", the statement reduces using the tables above:
!(1 && !(0 || 1))
!(1 && !1)
!(1 && 0)
!0
1
But I don't know "why" it's true. Because that's what an AND operation is, what an OR operation is, and what a NOT operation is, and how reducing a statement works. With those definitions, it can't be another answer, so it's that answer. But you already know that, because you did it yourself and got the same answer ... so what does the question mean?
The innermost expression (0 || 1) is always true.
So !(0 || 1) is always false.
That leaves 1 && 0, which is always false.
So !(false) is always true.
Please forgive my freely intermixing 0/false and 1/true.
The human evaluator (:-).
Working through the expression, following order of operation:
!(1 && !(0 || 1))
= !(1 && !(1))
= !(1 && 0)
= !(0)
= 1
Step by step explanation:
1 = true
0 = false
Starting point: !(1 && !(0 || 1))
Lets start with the inner most expression: !(0 || 1)
Var1 || Var2 =
Var1 or Var2 =
If Var1 or Var2 is 1 or both are 1, the result is 1.
(0 || 1) = 0 or 1 -> the second variable is 1 so the expression is 1.
Insert the result (0 || 1) = 1 into Startingpoint: !(1 && !(1))
! = not (inverts the value of what is behinde)
!1 = 0
!0 = 1
!(0 || 1) = !(1) = 0
Insert the result !(1) = 0 into Startingpoint: !(1 && 0)
So we have !(1 && 0)
Var1 && Var2 = And =
the opossite of or =
If Var1 AND Var2 are both 1, the result is 1. Else it is 0 =
If Var1 or Var2 is 0, the result is zero
1 && 1 = 1
1 && 0 = 0
everything else: 0
So this is left: !(0)
Reminder: ! = not = inverts the expression behind it. So !0 = 1 (and !1 = 0)
This is 1. Or in your case: true
A good book for Beginner C programmers and people who want to learn about programming and logic in an easy, understandable way:
C for Dummies by Dan Godkins
!(1 && !(0 || 1))
Since, you have used parenthesis, evaluation takes place according to them.
First, evaluate innermost parenthesis.
0 || 1 => always true.
!(0 || 1) => !(true) => always false.
1 && !(0 || 1) => 1 && false => always false.
!(1 && !(0 || 1)) => !false => always true.

AS3 one-liner with conditionals

How can I craft a one-liner return line that also has conditionals? For example, if I want to make a 'return the median' one:
//assuming sorted input array
return ((inputArray.length % 2) && (inputArray[int(inputArray.length/2)] + inputArray[int(inputArray.length/2)+1]) / 2) || inputArray[int(inputArray.length/2)+1];
Is there anyway to make this work?
You should use the ternary operator:
return (inputArray.length % 2 != 0) ? (inputArray[int(inputArray.length/2)] + inputArray[int(inputArray.length/2)+1]) / 2 : inputArray[int(inputArray.length/2)+1];
Which is equivalent to:
if (inputArray.length % 2 != 0) {
return (inputArray[int(inputArray.length/2)] + inputArray[int(inputArray.length/2)+1]) / 2;
} else {
return inputArray[int(inputArray.length/2)+1];
}
If you want to use only && and ||, you can use the following (which is not really a good programming style):
((inputArray.length % 2 != 0) || return inputArray[int(inputArray.length/2)+1]) && return (inputArray[int(inputArray.length/2)] + inputArray[int(inputArray.length/2)+1]);
Which is equivalent to:
(condition || return value2) && return value1;
So, thanks to the short-circuit evaluation of boolean operators:
if condition is true, return value2 is not evaluated and return value1 will be executed.
if condition is false, return value2 will be evaluated.
I would go for a more readable version without repetitions, but with some variables.
var index:int = int(inputArray.length / 2);
var item1:Number = inputArray[index];
var item2:Number = inputArray[index + 1];
var median:Number = (item1 + item2) / 2;
return (inputArray.length % 2 != 0) ? median : item2;
Please try with modified conditions:
return ((inputArray.length % 2) && (((inputArray[int(inputArray.length/2)] + inputArray[int(inputArray.length/2)+1]) / 2) || inputArray[int(inputArray.length/2)+1]));

Iframe does not render properly

So I'm attempting to run a webpage that shows security camera feeds for a client. However it does not render properly at all and only shows the background. I have a feeling it has to do with a limitation of the iframe tag, since using other iframe testing gadgets online I get the same results. Other clients are using camera feeds with a different interface and my solution works fine for them. Are there any alternatives to iframe?
edit: The page actually renders perfectly fine when being visited directly, and not through an iframe.
edit2: By popular request here is the source for the security feed site. I did not post my iframe code, since no matter what I use for iframe it will not display.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="expires" content="-1">
<title>:::</title>
<script language="JavaScript" src="/js/lgSource.js"></script>
<script language="JavaScript" src="/js/data_init.js"></script>
<script language="javascript" src="/js/AVUtility.js"></script>
<script language="JavaScript">
var d = document ;
d.write( "<frameset frameSpacing=0 rows='37,*' frameBorder='no' >" ) ;
d.write( " <frame name='ban' src='' scrolling='no'>" ) ;
d.write( " <frameset frameSpacing=0 frameBorder='no' cols='*,195'>" ) ;
d.write( " <frame name='main' src='home.htm' scrolling='auto'>" ) ;
d.write( " <frame name='left' src='' noResize scrolling='no'>" ) ;
d.write( " </frameset>" ) ;
d.write( "</frameset>" ) ;
d.write( "<noframes><body><p>no frame</p></body></noframes>" ) ;
var httpObj,httpObj2,httpObj3;
//alert("Code in NFS. H264 \n\n charset=utf-8");
//top.dt.user.SupportLG = "ENGLISH&CHINESE&"
loadSupportLanguage();
//loadUserPwd();
function loadSupportLanguage()
{
httpObj3 = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/nobody/Machine.cgi?action=get_capability";
httpObj3.onreadystatechange = updSL;
requestCgiParam(httpObj3, requestData);
}
function updSL()
{
if (httpObj3.readyState == 4 && httpObj3.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj3.responseText;
if (GetCgiParam(objStr,"Language.Support=") == 1)
if (objStr.strGet != "")
top.dt.user.SupportLG = objStr.strGet;
loadUserPwd();
}
}
function loadUserPwd()
{
httpObj = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/guest/UserInfo.cgi?action=query";
httpObj.onreadystatechange = updUserPwd;
requestCgiParam(httpObj, requestData);
}
function updUserPwd()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
if (GetCgiParam(objStr, "Username=") == 1)
top.dt.user.username = objStr.strGet;
if (GetCgiParam(objStr, "Password=") == 1)
top.dt.user.password = objStr.strGet;
loadLogin();
}
}
function loadLogin()
{
httpObj2 = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/guest/Login.cgi?rnd="+Math.random();
httpObj2.onreadystatechange = updLogin;
httpObj2.open("get", requestData, true);
httpObj2.send(null);
}
function updLogin()
{
if (httpObj2.readyState == 4 && httpObj2.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj2.responseText;
if (GetCgiParam(objStr,"Server-Language=") == 1)
{
if(objStr.strGet.toUpperCase() == "CHINESE")
top.dt.user.language = 2;
else if(objStr.strGet.toUpperCase() == "GREEK")
top.dt.user.language = 3;
else
top.dt.user.language = 1;
}
if (GetCgiParam(objStr, "Video-System=") == 1)
top.dt.user.VideoSystem = objStr.strGet;
if (GetCgiParam(objStr, "User-Level=") == 1)
top.dt.user.ulevel = objStr.strGet;
if (GetCgiParam(objStr, "Product-ShortName=") == 1)
{
if(objStr.strGet == "V_Indep")
top.dt.user.IndepFlag = true;
}
//top.dt.user.NatSupport = true;
//top.dt.user.PosSupport = true;
if (GetCgiParam(objStr, "Capability=") == 1)
{
tmpStr = objStr.strGet.split(",");
if(tmpStr.length==4){
if(parseInt(tmpStr[3],16)&0x01)
top.dt.user.isDvrPtz = true;
if(parseInt(tmpStr[2],16)&0x01)
top.dt.user.DvrHaSupport = true; // HA
if(parseInt(tmpStr[2],16)&0x02)
top.dt.account.NotifySys = true; //3G Notify
if(parseInt(tmpStr[2],16)&0x04)
top.dt.user.NatSupport = true; //NAT
if(parseInt(tmpStr[2],16)&0x08)
top.dt.user.RfidSupport = true; //RFID
if(parseInt(tmpStr[1],16)&0x01)
top.dt.user.PosSupport = true; //POS
}
}
if (GetCgiParam(objStr, "Product-ID-Minor=") == 1)
{
top.dt.user.ProductID = objStr.strGet;
var pid = objStr.strGet;
// Video Channel (default: 4 ch)
if(pid == "787" || pid == "718" || pid == "616" || pid == "757" || pid == "677" || pid == "678" || pid == "DG1648" || pid == "798"){
top.dt.user.dvrCh = 16;
}
else if (pid == "785" || pid == "608" || pid == "716" || pid == "755" || pid == "675" || pid == "676" || pid == "DG0824" || pid == "796"){
top.dt.user.dvrCh = 8;
}
else if (pid == "783" || pid == "604" || pid == "604F" || pid == "714" || pid == "724" || pid == "DG0412" || pid == "763" || pid == "764" || pid == "760A" || pid == "761A" || pid == "041"){
top.dt.user.dvrCh = 4;
}
else{
top.dt.user.dvrCh = 4; /* default 4 ch */
}
// Audio Channel
if(pid == "DG0824" || pid == "608" || pid == "DG1648" || pid == "616" || pid == "718" || pid == "757" || pid == "755" || pid == "675" || pid == "676" || pid == "677" || pid == "678" || pid == "724" || pid == "764" || pid == "673" || pid == "674" || pid == "683" || pid == "796" || pid == "798"){
top.dt.user.soundCh = 4;
}
else if (pid == "732E" || pid == "DG0412" || pid == "714"){
top.dt.user.soundCh = 2;
}
else if (pid == "733" || pid == "944" || pid == "945" || pid == "946" || pid == "311" || pid == "321" || pid == "202" || pid == "212" || pid == "604F" || pid == "203" || pid == "671" || pid == "672" || pid == "681"){
top.dt.user.soundCh = 1;
}
else{
top.dt.user.soundCh = 0;
}
//Top-Page
if(top.dt.user.ulevel != "SUPERVISOR" || pid == "203" || pid == "763")
top.dt.user.topSrc = "/top2.htm";
else
top.dt.user.topSrc = "/top.htm";
//show Left-Page
if(pid == "311" || pid == "321"){
top.dt.user.leftSrc = "/left_ipcam.htm";
top.dt.user.confSrc = "/left_ipcam_config.htm";
top.dt.user.ProductType = "IP CAMERA";
top.dt.user.isAutomoveSupport = true;
}
else if(pid == "203"){
top.dt.user.leftSrc = "/left_ipcam_h264.htm";
top.dt.user.ProductType = "IP CAMERA";
}
else{
if(pid == "763"){
top.dt.user.leftSrc = "/left_home763.htm";
}else if(pid == "798" || pid == "796"){
top.dt.user.leftSrc = "/left_home16ch.htm";
}
else{
top.dt.user.leftSrc = "/left_home.htm";
}
top.dt.user.confSrc = "/left_config.htm";
top.dt.user.ProductType = "DVR";
}
//show Title
if(pid == "764" || pid == "671" || pid == "672" || pid == "673" || pid == "674" || pid == "681" || pid == "683" || pid == "203" || pid == "796" || pid == "798" || pid == "041"){
top.dt.user.MediaType = "H264";
document.title = "H264 "+ top.dt.user.ProductType;
}
else
document.title = "MPEG4 "+ top.dt.user.ProductType;
if(top.dt.user.ulevel == "SUPERVISOR")
if(top.dt.user.ProductType == "DVR")
loadRecImageSize();
else
chkNatFirstUse();
else
loadMainPage();
}
}
}
function loadRecImageSize()
{
httpObj = createHttpRequestObj();
var requestData = "http://"+getURL()+"/cgi-bin/user/Config.cgi?action=get&category=DVR.Record.*";
httpObj.onreadystatechange = updRecImageSize;
requestCgiParam(httpObj, requestData);
}
function updRecImageSize()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
if (GetCgiParam(objStr,"ImageSize=") == 1){
top.dt.user.DVR_Record_ImageSize = objStr.strGet;
chkNatFirstUse();
}
}
}
function chkNatFirstUse()
{
httpObj = createHttpRequestObj();
var requestData = "http://"+getURL()+"/cgi-bin/user/Config.cgi?action=get&category=Network.NAT.*";
httpObj.onreadystatechange = updNatFirstUse;
requestCgiParam(httpObj, requestData);
}
function updNatFirstUse()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
var FirstUseNatFlag = false;
if (GetCgiParam(objStr,"FirstUse=") == 1)
if(objStr.strGet == "YES")
FirstUseNatFlag = true;
if (GetCgiParam(objStr,"Hostname=") == 1)
top.dt.user.NatName = objStr.strGet;
if(FirstUseNatFlag)
showNatFirstUseWeb();
else
loadMainPage();
}
}
function showNatFirstUseWeb()
{
top.ban.location.replace("/top2.htm");
top.left.location.replace("/left_empty.htm");
top.main.location.replace("/combo/nat_firstuse.htm");
}
function loadMainPage()
{
top.dt.user.mainSrc = "/home.htm";
top.ban.location.replace(top.dt.user.topSrc);
top.left.location.replace(top.dt.user.leftSrc);
}
</script>
</html>
The page actually renders perfectly
fine when being visited directly, and
not through an iframe.
The only thing I can think of that the page has a frame busting technique.
You can read a little about it here.
I can't help you much more without the code!

Date Range Overlap with Nullable Dates

I'm looking for an extended answer to the question asked here:
Determine Whether Two Date Ranges Overlap
where any of the dates in either date range can be null. I've come up with the following solution, but I'm not sure if it can be simplified further.
(StartA == NULL || StartA <= EndB) &&
(EndA == NULL || EndA >= StartB) &&
(StartB == NULL || StartB <= EndA) &&
(EndB == NULL || EndB >= StartA)
Assuming:
DateTime ranges of StartA to EndA and StartB to EndB
EDIT: Sorry I quickly threw the above logic together, which seems to fail when either range's start and end dates are NULL. See David's solution below for a better & well-explained approach.
This case can be handled by a slight generalization of Charles Bretana's excellent answer to that question.
Let CondA Mean DateRange A Completely After DateRange B (True if StartA > EndB)
Let CondB Mean DateRange A Completely Before DateRange B (True if EndA < StartB)
In this case, assuming you want a null date to represent "no starting/ending bound," the conditions are modified. For CondA, for instance, in order for DateRange A to be completely after DateRange B, DateRange A must have a defined starting time, DateRange B must have a defined ending time, and the starting time of A must be after the ending time of B:
CondA := (StartA != null) && (EndB != null) && (StartA > EndB)
CondB is the same with A and B switched:
CondB := (StartB != null) && (EndA != null) && (StartB > EndA)
Continuing,
Then Overlap exists if Neither A Nor B is true
Overlap := !(CondA || CondB)
and
Now deMorgan's law, I think it is, says that
Not (A Or B) <=> Not A And Not B
Overlap == !CondA && !CondB
== ![(StartA != null) && (EndB != null) && (StartA > EndB)] &&
![(StartB != null) && (EndA != null) && (StartB > EndA)]
== [(StartA == null) || (EndB == null) || (StartA <= EndB)] &&
[(StartB == null) || (EndA == null) || (StartB <= EndA)]
I think this is actually a bit more robust than the solution you developed, because if EndB == NULL but StartA is not null, your first condition will wind up comparing StartA <= NULL. In most languages I'm familiar with, that's an error condition.
Without considering nulls, answer is
(StartA <= EndB) and (EndA >= StartB)
(see this for detailed explanation)
considering nulls for start and end dates,
Using C Ternary operator syntax:
(StartA != null? StartA: EndB <= EndB != null? EndB: StartA) &&
(EndA != null? EndA: StartB >= StartB != null? StartB: EndA)
Or C# 4.x style null operators:
(StartA??EndB <= EndB??StartA) && (EndA??StartB >= StartB??EndA)
or in SQL:
(Coalesce(StartA, EndB) <= Coalesce(EndB, StartA))
And (Coalesce(EndA, StartB ) <= Coalesce(StartB , EndA))
Explanation:
consider the non-null answer:
(StartA <= EndB) and (EndA >= StartB)
Now, consider that StartA is null, indicating that date range A has existed since beginning of time (BOT). In that case, DateRangeB can never be before DateRangeA. So first condition, (StartA(BOT) <= EndB) will ALWAYS be true, no matter what EndB is. So change this expression so that instead of comparing null with EndB, when StartA is null, compare EndB with itself
No matter what EndB is, the expression EndB <= EndB will be true.
(We could create variables to represent BOT and EOT, but this is easier).
Do the same for other three input variables.
That is probably as 'simple' as you can get it, although I haven't actually proven it.
It probably isn't worth it to simplify further, since that block ends up being about 8 operations in the worst case (4 on average thanks to short-circuit evaluation).
All answers are based if the condition is true. I'would like to add some note here.
1- The DateTime variable type is a struct and you can not set it to null unless that you are using nullable type like "DateTime?"
2- To find the overlap range follow the following steps
DateTime? StartOverLap = null,EndOverLap = null;
if (StartA != null && StartB != null)
{
StartOverLap = StartA > StartB ? StartA : StartB;
}
else if (StartA == null && StartB != null)
{
StartOverLap = StartB;
}
else if (StartA != null && StartB == null)
{
StartOverLap = StartA;
}
if (EndA != null && EndB != null)
{
EndOverLap = EndA < EndB ? EndA : EndB;
}
else if (EndA == null && EndB != null)
{
EndOverLap = EndB;
}
else if (EndA != null && EndB == null)
{
EndOverLap = EndA;
}
if (StartOverLap != null && EndOverLap == null)
{
if (EndOverLap < StartOverLap)
{
StartOverLap = null;
EndOverLap = null;
}
}