Firebase RealTime Rules how to fix decimal number decimal length? - firebase-realtime-database

I am trying to set real time database rules:
"lat": {
".validate": "newData.isNumber() && newData.val().length < 20" //not allowing input
},
"lng": {
".validate": "newData.isNumber()" // working fine
},
"radius": {
".validate":"newData.isNumber() && newData.val() % 1 === 0.0 && newData.val() <= 99" //working fine
},
with lat, lng i am trying to set max length of 20 where user can enter
22.810690365833796
but not
22.810690365833796999999999999999999999999999
and input should be number
newData.val().length < 20
is working on string but not on number
kindly help

Related

How to display Quarters in gantt chart

I'm trying to use your gantt chart library to create something with milestones as follow:
I would like to have Quarter 1 / 20XX, Quarter 2 / 20XX etc... instead of these 1 2 3 4 5 6... numbers on top, I been inspecting and trying almost anything and I think I need you help, as I could not figure it out. I did try using tickInterval and tickAmount on the xAxis but it seems to do whatever it wants and I'm a little frustrated now... please provide me with any help, thank you forehand.
This is how I did it, I hope this helps anybody like me, going crazy without examples :-( (simplified for space reasons)
xAxis: [{
...
title: { text: 'Quarters' },
units: [
['month', [3]],
],
useHTML: true,
labels: {
align: "center",
format: '{value: %b-%y}',
formatter: function AxisLabelsFormatterCallbackFunction() {
var providedLocalDate = new Date(this.value);
var realDate = new Date(providedLocalDate.getTime() + (providedLocalDate.getTimezoneOffset() * 60 * 1000));
var month = realDate.getMonth();
var QuarterNumber;
if (month >= 0 && month <= 2)QuarterNumber = 1;
if (month >= 3 && month <= 5) QuarterNumber = 2;
if (month >= 6 && month <= 8) QuarterNumber = 3;
if (month >= 9 && month <= 11) QuarterNumber = 4;
var year = realDate.getFullYear().toString();
var year2digits = year.substring(year.length - 2, year.length);
return 'Q' + QuarterNumber + '-<span class="font-weight-bold">' + year2digits + '</span>';
},
},
Use xAxis.labels.format(xAxis.labels.formatter as well) or xAxis.dateTimeLabelFormats to format labels depending on provided data:
Example:
xAxis: [{
labels: {
format: 'Month: {value: %m}'
}
}],
API Reference:
https://api.highcharts.com/gantt/xAxis.dateTimeLabelFormats
https://api.highcharts.com/gantt/xAxis.labels.format
Demo:
https://jsfiddle.net/BlackLabel/5hopuL8f/

How do I correct my code to enable my Expect Advisor to take trades?

My EA was taking only 1 trade at a time on a single currency pair, it ignores the other pairs till the current trade is closed. I decided to modify it. Now it's no more trading at all.
int Hour = TimeHour(TimeCurrent());
int DayOfWeek = DayOfWeek();
int total = OrdersTotal();
int count=0;
for(int i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == _Symbol && OrderMagicNumber()==MagicNumber)
{
Alert("Inside Order Select if");
// Checking if spread is less than 2.0 pips.
if(current_spread <= AllowableSpread)
{
// Checking for days of the week
if(DayOfWeek >= 1 && DayOfWeek <= 5)
{
// Checking for time of the day
if(Hour >= 3 && Hour <= 20)
{
if(ADXValue > 25)
{
if(RSIValue > 50 || RSIValue < 20)
{
if(PreviousFast<PreviousSlow && CurrentFast > CurrentSlow)
ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, Slippage, Ask-(StopLoss*pips), Ask+(TakeProfit*pips), NULL, MagicNumber, 0, Green);
if(ticket<0)
Print("OrderSend failed with error #",GetLastError());
else
Print("OrderSend placed successfully");
}
if(RSIValue < 50 || RSIValue > 70)
{
if(PreviousFast>PreviousSlow && CurrentFast < CurrentSlow)
ticket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, Slippage, Bid+(StopLoss*pips), Bid-(TakeProfit*pips), NULL, MagicNumber, 0, Red);
if(ticket<0)
Print("OrderSend failed with error #",GetLastError());
else
Print("OrderSend placed successfully");
}
}
}

Real length of a Thai UTF-8 encoded string in Delphi

Thai is a very special language. You can write vowels (32 in total) as in any other languages right after the consonant, or IN FRONT of it, or ON TOP of it, or ON THE BOTTOM of it (ok, just the short and long "u" sound can go on the bottom, but anyway...).
Furthermore, there are other modifiers (the 4 tone markers, the ga-ran, the mai-tai-ku and other ones) that can go ON TOP of an already existing vowel!
For example:
ที่ดีที่สุด (the best)
As you can see, if I try to print it with a monospaced font, the "real length" would be of 5 characters, but all the UTF-8 strlen routines give me back 11 characters - which is TOTALLY CORRECT, but I need to know the "actual space" that the string will use on screen/on printer, when printed monospaced.
Sure, an easy solution would be to list all the special characters that can go on the top or on the bottom of the word, and remove them from the total count.
Since I am not sure I can find all the special characters, is there already a routine made in any language so that I can translate it in Delphi?
Thank you
In C++:
/*---------------------------------------------------------------------------*/
/* thai_tcslen */
/*---------------------------------------------------------------------------*/
long thai_tcslen(_TCHAR *buff)
{
long bufpos = 0;
long normal_length = _tcslen(buff);
long thai_length = 0;
for (bufpos = 0; bufpos < normal_length; ++bufpos) {
if ( *(buff+bufpos) != _T('Ñ')/*mai han na kaad*//*-047*/
&& *(buff+bufpos) != _T('Ô')/*sara ee *//*-044*/
&& *(buff+bufpos) != _T('Õ')/*sara eeeee *//*-043*/
&& *(buff+bufpos) != _T('Ö')/*sara uu *//*-042*/
&& *(buff+bufpos) != _T('×')/*sara uuuuu *//*-041*/
&& *(buff+bufpos) != _T('Ø')/*sara oo *//*-040*/
&& *(buff+bufpos) != _T('Ù')/*sara ooooo *//*-039*/
&& *(buff+bufpos) != _T('ç')/*mai tai khoo *//*-025*/
&& *(buff+bufpos) != _T('è')/*mai aek *//*-024*/
&& *(buff+bufpos) != _T('é')/*mai toe *//*-023*/
&& *(buff+bufpos) != _T('ê')/*mai cha ta wah *//*-022*/
&& *(buff+bufpos) != _T('ë')/*mai tree *//*-021*/
&& *(buff+bufpos) != _T('ì')/*ka ran *//*-020*/
) {
++thai_length;
}
}
return thai_length;
} /* thai_tcslen */
in VB6:
Public Function ThaiStringLength(ByRef ThaiString As String) As Long
Dim b As String, noLengthChars(13) As Byte
b = ThaiString
noLengthChars(0) = 209
noLengthChars(1) = 212
noLengthChars(2) = 213
noLengthChars(3) = 214
noLengthChars(4) = 215
noLengthChars(5) = 216
noLengthChars(6) = 217
noLengthChars(7) = 231
noLengthChars(8) = 232
noLengthChars(9) = 233
noLengthChars(10) = 234
noLengthChars(11) = 235
noLengthChars(12) = 236
Dim o As Long
For o = 0 To 12
If InStr(b, Chr(noLengthChars(o))) > 0 Then
b = Replace(b, Chr(noLengthChars(o)), "")
End If
Next
ThaiStringLength = Len(b)
End Function

Is it possible to get the duration (time) video through Youtube data API v3.0

Is it possible to get the duration
(time) video through Youtube data API v3.0.
If so, how?
You will have to make a call to the Youtube Data API's Video resource after you make the search call. You can put up to 50 video id's in search, so you wont have to call it for each element.
https://developers.google.com/youtube/v3/docs/videos/list
You'll want to set part=contentDetails, because duration is there.
For example the following call:
https://www.googleapis.com/youtube/v3/videos?id=9bZkp7q19f0&part=contentDetails&key={YOUR_API_KEY}
Gives this result:
{
"kind": "youtube#videoListResponse",
"etag": "\"XlbeM5oNbUofJuiuGi6IkumnZR8/ny1S4th-ku477VARrY_U4tIqcTw\"",
"items": [
{
"id": "9bZkp7q19f0",
"kind": "youtube#video",
"etag": "\"XlbeM5oNbUofJuiuGi6IkumnZR8/HN8ILnw-DBXyCcTsc7JG0z51BGg\"",
"contentDetails": {
"duration": "PT4M13S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true,
"regionRestriction": {
"blocked": [
"DE"
]
}
}
}
]
}
The time is formatted as an ISO 8601 string. PT stands for Time Duration, 4M is 4 minutes, and 13S is 13 seconds.
Please refer to this question for more details
Here is how I did it from .NET and C#.
First include the "contentDetails" part
var searchListRequest = youtubeService.Videos.List("snippet,contentDetails");
Second convert the duration to something more programmatically manageable as follows:
TimeSpan YouTubeDuration = System.Xml.XmlConvert.ToTimeSpan(searchResult.ContentDetails.Duration);
I hope this is helpful
using javascript
function converTime(d) {
//ignore the "PT" part
d = d.search(/PT/i) > -1? d.slice(2) : d;
let h, m, s;
//indexes of the letters h, m, s in the duration
let hIndex = d.search(/h/i),
mIndex = d.search(/m/i),
sIndex = d.search(/s/i);
//is h, m, s inside the duration
let dContainsH = hIndex > -1,
dContainsM = mIndex > -1,
dContainsS = sIndex > -1;
//setting h, m, s
h = dContainsH? d.slice(0, hIndex) + ":" : "";
m = dContainsM? d.slice(dContainsH ? hIndex + 1 : 0, mIndex) : dContainsH? "0" : "0";
s = dContainsS? d.slice(dContainsM ? mIndex + 1 : hIndex + 1, sIndex) : "0";
//adding 0 before m or s
s = (dContainsM || dContainsS) && s < 10? "0" + s: s;
m = (dContainsH || dContainsM) && m < 10? "0" + m + ":" : m + ":";
return d !== "0S" ? h + m + s : "LIVE"
}
console.log(converTime("PT6M7S"));

ASP.NET MVC UpdateModel breaks when decimal points supplied for integer property

In the rendered view, if a user enters a value such as "1.0" or "1.2" instead of "1" then UpdateModel throws an exception if the property in question is an integer.
Is there a decent fix for this?
You could simply block the user from entering a decimal point (or letters also in the code I provided) in the text box. I use the below code for that purpose.
$(document).ready(function() {
$("#txtboxToFilter").keydown(function(event) {
// Allow: backspace, delete, tab, escape, and enter
if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress if it is not
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
});
});

Resources