Json single line is too long - json

I have a super long value for a key in a json file. Is there any way to format this single line into multiple lines for easier reading? Thank you so much!
"transforms.route.topic.expression":"if (value.source.table == 'test_item') {'rec.test_item'} else if (value.after != null && value.after.item_channel == 0){'rec.test_item.order_item.item_channel0'} else if (value.after != null && value.after.item_channel == 1) {'rec.test_item.order_item.item_channel1'} else if (value.after != null && value.after.item_channel == 2) {'rec.test_item.order_item.item_channel2'} else if (value.after != null && value.after.item_channel == 3) {'rec.test_item.order_item.item_channel3'} else if (value.after != null && value.after.item_channel == 4) {'rec.test_item.order_item.item_channel4'} else null"
"transforms.route.topic.expression":"if (value.source.table == 'test_item') {'rec.test_item'} else if (value.after != null && value.after.item_channel == 0){'rec.test_item.order_item.item_channel0'} else if (value.after != null && value.after.item_channel == 1) {'rec.test_item.order_item.item_channel1'} else if (value.after != null && value.after.item_channel == 2) {'rec.test_item.order_item.item_channel2'} else if (value.after != null && value.after.item_channel == 3) {'rec.test_item.order_item.item_channel3'} else if (value.after != null && value.after.item_channel == 4) {'rec.test_item.order_item.item_channel4'} else null"

It could be split into lines in an array, which can be joined together again later, e.g.:
"transforms.route.topic.expression": [
"if (value.source.table == 'test_item') {'",
"rec.test_item'",
"} else if (value.after != null && value.after.item_channel == 0){",
"'rec.test_item.order_item.item_channel0'",
"} else if (value.after != null && value.after.item_channel == 1) {",
"'rec.test_item.order_item.item_channel1'",
"} else if (value.after != null && value.after.item_channel == 2) {",
"'rec.test_item.order_item.item_channel2'",
"} else if (value.after != null && value.after.item_channel == 3) {",
"'rec.test_item.order_item.item_channel3'",
"} else if (value.after != null && value.after.item_channel == 4) {",
"'rec.test_item.order_item.item_channel4'",
"} else null"
]
If using e.g. JavaScript, then join like this:
json["transforms.route.topic.expression"] = json["transforms.route.topic.expression"].join("");

Related

Php How To Echo Null from MySql

I have the following script that I use for part of my count in payment_status from Mysql. I have seen some examples of this online, but I can't seem to figure out how to make this work WITH a Null instance. Any insight would be appreciated.
Note: The way I have it now doesn't work when Null is in the database. I'm guessing because that isn't an inserted word?
Objective: To add $row['payment_status'] == "Null" to this with the rest of the script.
if($row['payment_status'] == "Completed" || $row['payment_status'] == "Free" || $row['payment_status'] == "Cancelled" || $row['payment_status'] == "Null")
if payment_status column has default value NULL, Then try below change
if($row['payment_status'] == "Completed" || $row['payment_status'] == "Free" || $row['payment_status'] == "Cancelled" || $row['payment_status'] == null)

Data call using apend in controller

Hy. I'm learning about Laravel
im using append to enter data in select option
here is my append code
if($('.type').val()=="MAG") {
$('.tools').empty();
$('.tools').append('<?php echo $MAGRES ?>');
$(".tools").prop('disabled', false);
$('.level').empty();
$('.level').append('<?php echo $mlevel ?>');
$(".level").prop('disabled', false);
}
if($('.type').val()=="WAG") {
$('.tools').empty();
$('.tools').append('<?php echo $WAGRES ?>');
$(".tools").prop('disabled', false);
$('.level').empty();
$('.level').append('<?php echo $flevel ?>');
$(".level").prop('disabled', false);
}
Here is my controller
$openM =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','MAG')->first();
$openF =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','WAG')->first();
$mlevel='<option value="">-- Choose Levels --</option>';
$flevel='<option value="">-- Choose Levels --</option>';
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){$mlevel=$mlevel.'<option value="Level 1">Level {{$event->onename}} </option>';}
if($openM->TwoO == 1 || $openM->TwoA == 1 || $openM->TwoB == 1 || $openM->TwoC == 1 || $openM->TwoD == 1){$mlevel=$mlevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
if($openM->ThreeO == 1 || $openM->ThreeA == 1 || $openM->ThreeB == 1 || $openM->ThreeC == 1 || $openM->ThreeD == 1){$mlevel=$mlevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
if($openM->FourO == 1 || $openM->FourA == 1 || $openM->FourB == 1 || $openM->FourC == 1 || $openM->FourD == 1){$mlevel=$mlevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
if($openM->FiveO == 1 || $openM->FiveA == 1 || $openM->FiveB == 1 || $openM->FiveC == 1 || $openM->FiveD == 1){$mlevel=$mlevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
if($openM->FigO == 1 || $openM->Fig1 == 1 ||$openM->Fig2 == 1){$mlevel=$mlevel.'<option value="FIG">FIG</option>';}
if($openF->OneO == 1 || $openF->OneA == 1 || $openF->OneB == 1 || $openF->OneC == 1 || $openF->OneD == 1){$flevel=$flevel.'<option value="Level 1">Level {{$event->onename}}</option>';}
if($openF->TwoO == 1 || $openF->TwoA == 1 || $openF->TwoB == 1 || $openF->TwoC == 1 || $openF->TwoD == 1){$flevel=$flevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
if($openF->ThreeO == 1 || $openF->ThreeA == 1 || $openF->ThreeB == 1 || $openF->ThreeC == 1 || $openF->ThreeD == 1){$flevel=$flevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
if($openF->FourO == 1 || $openF->FourA == 1 || $openF->FourB == 1 || $openF->FourC == 1 || $openF->FourD == 1){$flevel=$flevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
if($openF->FiveO == 1 || $openF->FiveA == 1 || $openF->FiveB == 1 || $openF->FiveC == 1 || $openF->FiveD == 1){$flevel=$flevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
if($openF->FigO == 1 || $openF->Fig1 == 1 ||$openF->Fig2 == 1){$flevel=$flevel.'<option value="FIG">FIG</option>';}
there is no problem to display the options
but its print text :
'{{$event->onename}}' not data from $event->onename
i want it shows $event->onename data from database.
can anyone help me? thank you
Because you are using Blade syntax in your controller file, that is why it is displaying {{$event->onename}} instead of its actual value.
You can do like
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
$mlevel= $mlevel."<option value=\"Level 1\">Level {$event->onename} </option>";
}
Or
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
$mlevel = $mlevel.'<option value="Level 1">Level '.$event->onename.'</option>';
}

Shorten if Statement Actionscript 3

I just started learning actionscript and I'm wondering how could I shorten this if statement
if (txtInputTemp.charAt(track - 1) == "a" || txtInputTemp.charAt(track - 1) == "b" || txtInputTemp.charAt(track - 1) == "c" || txtInputTemp.charAt(track - 1) == "d" || txtInputTemp.charAt(track - 1) == "e" || txtInputTemp.charAt(track - 1) == "f" || txtInputTemp.charAt(track - 1) == "g" || txtInputTemp.charAt(track - 1) == "h" || txtInputTemp.charAt(track - 1) == "i" || txtInputTemp.charAt(track - 1) == "j" || txtInputTemp.charAt(track - 1) == "k" || txtInputTemp.charAt(track - 1) == "l" || txtInputTemp.charAt(track - 1) == "m" || txtInputTemp.charAt(track - 1) == "n" || txtInputTemp.charAt(track - 1) == "o" || txtInputTemp.charAt(track - 1) == "p" || txtInputTemp.charAt(track - 1) == "q" || txtInputTemp.charAt(track - 1) == "r" || txtInputTemp.charAt(track - 1) == "s" || txtInputTemp.charAt(track - 1) == "t" || txtInputTemp.charAt(track - 1) == "u" || txtInputTemp.charAt(track - 1) == "v" || txtInputTemp.charAt(track - 1) == "w" || txtInputTemp.charAt(track - 1) == "x" || txtInputTemp.charAt(track - 1) == "y" || txtInputTemp.charAt(track - 1) == "z" || txtInputTemp.charAt(track - 1) == "." || txtInputTemp.charAt(track - 1) == "'" || txtInputTemp.charAt(track - 1) == "-" || txtInputTemp.charAt(track - 1) == " ") { }
Any help is appreciated.
It can rewrite a-z to range specification.
somechar>="a" && somechar<="z"
But I have no idea how to shorten these symbols.
== "."
== "'"
== "-"
== " "
var somechar:String = txtInputTemp.charAt(track - 1);
if ((somechar>="a" && somechar<="z")||somechar == "."||somechar == "'"||somechar == "-"||somechar == " ")
{
// do something
}
Working Example: http://wonderfl.net/c/A9Hv
Option2: Use array.indexOf(char) == -1 or not.
var someArray: Array = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",".","'","-"," "];
var somechar:String = txtInputTemp.charAt(track - 1);
if (someArray.indexOf(somechar) != -1)
{
// Do something
}

How to Create Maps and Keys?

I'm trying to give names to some variables. But I'm getting error TypeError: Error #1010
var squareArr:Object = {
b1: {
piece: wn1_txt,
pieceLoc: {
x: "47",
y: "297"
}
},
c1: {
piece: wb1_txt,
pieceLoc: {
x: "97",
y: "297"
}
},
...
addChild(squareArr.b1.piece);
addChild(squareArr.c1.piece);
...
var i:int;
if ((mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "3") || (mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "2") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "8") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "3") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "2")
|| (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "8") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "3") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "2") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "8") || (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "3")
|| (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "2") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "8")) {
for(i=1; i<=8; i++) {
for( num=97; num<105; num++){
if (squareArr[String.fromCharCode(num) + i].piece == wb1_txt) {
oldSquare = String.fromCharCode(num) + i;
}
}
}
newSquare = mvB.charAt(mvB.length - 2) + mvB.charAt(mvB.length - 1);
currentPiece = Object(squareArr[oldSquare]).piece;
TweenLite.to(currentPiece, 0.3, {x:squareArr[newSquare].x, y:squareArr[newSquare].y, ease:Linear.easeNone, onComplete:isMovingFunction});
...
Check what items you access in squareArr, do they defined, etc.
For example, check your iteration logic:
var squareName:String;
for (i = 1; i <= 8; i++) {
for (num = 97; num < 105; num++) {
squareName = String.fromCharCode(num) + i;
if(squareName in squareArr){
if (squareArr[squareName].piece == wb1_txt) {
oldSquare = String.fromCharCode(num) + i;
}
}else{
trace("There is no " + squareName + " property");
}
}
}

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;
}
}