Apparent Multiple Failures Using Google Chrome Versions 30 to 33 - jssor

I've been developing the Image Slider Theme(dated 02/20/2015 - Jssor Slider 18.0 Development Kit)(Jssor.Slider.FullPack\demos-no-jquery\image-slider-2.source.html with jssor.slider.min.js). I have not modified the javascript code. I'm finding failures of various script implementations in Chrome versions 30 through 33 with this Image Slider and several other in the Development Kit. Previous January Development Kit also shows errors. No problems with any other browsers or versions of those browsers that are not already indicated and/or addressed.
I have found that tweaking the function SetPosition "elseif" from:
" else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 30 && $Jssor$.$BrowserVersion() < 34)"
to:
" else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 32 && $Jssor$.$BrowserVersion() < 34)"
function SetPosition(elmt, position) {
var orientation = _DragOrientation > 0 ? _DragOrientation : _PlayOrientation;
var x = _StepLengthX * position * (orientation & 1);
var y = _StepLengthY * position * ((orientation >> 1) & 1);
if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() < 38) {
x = x.toFixed(3);
y = y.toFixed(3);
}
else {
x = Math.round(x);
y = Math.round(y);
}
if ($Jssor$.$IsBrowserIE() && $Jssor$.$BrowserVersion() >= 10 && $Jssor$.$BrowserVersion() < 11) {
elmt.style.msTransform = "translate(" + x + "px, " + y + "px)";
}
else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 30 && $Jssor$.$BrowserVersion() < 34) {
elmt.style.WebkitTransition = "transform 0s";
elmt.style.WebkitTransform = "translate3d(" + x + "px, " + y + "px, 0px) perspective(2000px)";
}
else {
$Jssor$.$CssLeft(elmt, x);
$Jssor$.$CssTop(elmt, y);
}
}
I'm using this as a quick-fix until I can delve into it further. Has anyone noticed anything along this line?

The following code is to improve performance of sliding left<->right for chrome (version 30 to 33).
else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 30 && $Jssor$.$BrowserVersion() < 34) {
elmt.style.WebkitTransition = "transform 0s";
elmt.style.WebkitTransform = "translate3d(" + x + "px, " + y + "px, 0px) perspective(2000px)";
}
After about a year, chrome went to version 40. Now it's time to remove it.
Thanks.

Related

How to format a number into thousands, millions and billions with dart/flutter?

How to get a number converted into something like this: 12K, 1.5M, 4.2B from a normal number like: 134900.
This is a minimalist function, of course you'll have to add validation code to verify if the number is valid before executing the function. Otherwise Enjoy ...
void main() {
double num = 1250;
var myNumber = k_m_b_generator(num);
print(myNumber);
}
String k_m_b_generator(num) {
if (num > 999 && num < 99999) {
return "${(num / 1000).toStringAsFixed(1)} K";
} else if (num > 99999 && num < 999999) {
return "${(num / 1000).toStringAsFixed(0)} K";
} else if (num > 999999 && num < 999999999) {
return "${(num / 1000000).toStringAsFixed(1)} M";
} else if (num > 999999999) {
return "${(num / 1000000000).toStringAsFixed(1)} B";
} else {
return num.toString();
}
}
You can use flutter's NumberFormat class with the compact function.
formatNumber(dynamic myNumber) {
// Convert number into a string if it was not a string previously
String stringNumber = myNumber.toString();
// Convert number into double to be formatted.
// Default to zero if unable to do so
double doubleNumber = double.tryParse(stringNumber) ?? 0;
// Set number format to use
NumberFormat numberFormat = new NumberFormat.compact();
return numberFormat.format(doubleNumber);
}
The answer is not entirely correct. If you test it, you will see what i meant. Base on the answer above, I created this solution:
String numberFormat(int n) {
String num = n.toString();
int len = num.length;
if (n >= 1000 && n < 1000000) {
return num.substring(0, len - 3) + '.' + num.substring(len - 3, 1 + (len - 3)) + 'k';
} else if (n >= 1000000 && n < 1000000000) {
return num.substring(0, len - 6) + '.' + num.substring(len - 6, 1 + (len - 6)) + 'm';
} else if (n > 1000000000) {
return num.substring(0, len - 9) + '.' + num.substring(len - 9, 1 + (len - 9)) + 'b';
} else {
return num.toString();
}
}

How to find direction with flutter compass?

Is there any way to find a specific direction with a Flutter compass. Does that compass indicate a specific long and lat coordinates?
This is the standard code for Qibla compasses I use in my apps to get the offset:
double getOffsetFromNorth(double currentLatitude, double currentLongitude,
double targetLatitude, double targetLongitude) {
var la_rad = radians(currentLatitude);
var lo_rad = radians(currentLongitude);
var de_la = radians(targetLatitude);
var de_lo = radians(targetLongitude);
var toDegrees = degrees(atan(sin(de_lo - lo_rad) /
((cos(la_rad) * tan(de_la)) - (sin(la_rad) * cos(de_lo - lo_rad)))));
if (la_rad > de_la) {
if ((lo_rad > de_lo || lo_rad < radians(-180.0) + de_lo) &&
toDegrees > 0.0 &&
toDegrees <= 90.0) {
toDegrees += 180.0;
} else if (lo_rad <= de_lo &&
lo_rad >= radians(-180.0) + de_lo &&
toDegrees > -90.0 &&
toDegrees < 0.0) {
toDegrees += 180.0;
}
}
if (la_rad < de_la) {
if ((lo_rad > de_lo || lo_rad < radians(-180.0) + de_lo) &&
toDegrees > 0.0 &&
toDegrees < 90.0) {
toDegrees += 180.0;
}
if (lo_rad <= de_lo &&
lo_rad >= radians(-180.0) + de_lo &&
toDegrees > -90.0 &&
toDegrees <= 0.0) {
toDegrees += 180.0;
}
}
return toDegrees;
}
then you add the offset to the flutter_compass rotation to get the offset for each
sensor update and apply the result to the special header.

Is a Separate Function Preferred for 2 Lines of Repeated Code in Swift?

I am designing a small game, and have decided on an initial way to distribute points based on the number of seconds elapsed between the time a question was asked and an enter button was pressed.
I understand that best practice is to create a function to call when lines are going to be repeated, but it seems to me that it may be a little excessive to call it when there are only two lines repeated four times. Using the code below, would it be "proper" or preferred for me to create a function for the last two lines in each section?
//Assigns points to score based on elapsed time and updates score
func updateScore() {
timer.invalidate()
if timeToAnswer < 3 {
questionScore = 10 //10 points for answering so quickly
score = score + questionScore //Updates score
timeToAnswer = 0 //Resets var timeToAnswer
}
else if (timeToAnswer >= 3) && (timeToAnswer < 6) {
questionScore = 7
score = score + questionScore
timeToAnswer = 0
}
else if (timeToAnswer >= 6) && (timeToAnswer < 11) {
questionScore = 10 - timeToAnswer
score = score + questionScore
timeToAnswer = 0
}
else {
questionScore = 1
score = score + questionScore
timeToAnswer = 0
}
}
Thank you very much to anybody that offers assistance or advice.
You can do it in a better way.
You can use switch statement, too. Anyway:
func updateScore() {
timer.invalidate()
if timeToAnswer < 3 {
questionScore = 10
}
else if (timeToAnswer >= 3) && (timeToAnswer < 6) {
questionScore = 7
}
else if (timeToAnswer >= 6) && (timeToAnswer < 11) {
questionScore = 10 - timeToAnswer
}
else {
questionScore = 1
}
score = score + questionScore //Updates score
timeToAnswer = 0 //Resets var timeToAnswer
}

Formula of Hijri date

What is the formula of converting "Time since epoch" stamp such as 1525249213 to Hijri date (Year - Month - Day)?
I know there would be one day inaccuracy which is OK for me.
The algorithm I found is to convert the Date to a Julian Date then convert the julian date to Hijri.
P.S. I can not remember where I found it. I am not responsible for any error or miss-accuracy or an consequence bla bla bla of using this code.
unsigned long gregorian_to_julian(const int gyear, const int gmonth, const int gday) {
if (gmonth < 3) {
gyear -= 1;
gmonth += 12;
}
auto a = int(gyear / 100.0f);
auto b = (gyear == 1582 && (gmonth > 10 || (gmonth == 10 && gday > 4)) ? -10 :
(gyear == 1582 && gmonth == 10 ? 0 :
(gyear < 1583 ? 0 : 2 - a + int(a / 4.0f))));
return int(365.25f * (gyear + 4716)) + int(30.6001f * (gmonth + 1)) + gday + b - 1524;
}
std::array<int,3> julian_to_hijri(const unsigned long julian_datestamp) {
std::array<int,3> result;
auto y = 10631.0f / 30.0f;
auto epoch_astro = 1948084;
auto shift1 = 8.01f / 60.0f;
auto z = julian_day - epoch_astro;
auto cyc = int(z / 10631.0f);
z = z - 10631 * cyc;
auto j = int((z - shift1) / y);
z = z - int(j * y + shift1);
result[0] = 30 * cyc + j; //Hijri Year
result[1]= int((z + 28.5001f) / 29.5f); //Hijri Month
if (result[1] == 13) {
result[1]= 12;
}
result[2] = z - int(29.5001f * result[1]- 29);// Hijri day
return result;
}
P.S. there will be +-1 one day error in the result Hijri date.

Programming on the Nintendo DS - issue with collisions

Sorry if this question has already been asked, but I have not managed to find any advice on the internet for my issue. I am currently trying to program a little game on the Nintendo DS, in which the player has to move a sprite (currently a square) until it reaches the exit. For this, I use a sprite I have included using a grit file, and also a background enabled in tiled mode. However, I am having a problem when it comes to checking if the sprite is going to collide with a wall. Here is the code I have both for the background configuration (where I declare the tiles and the map) and also for the sprite movements (I didn't add the condition for all cases yet, as it didn't work well) :
void configureMaze_Sub() {
int row, col;
for (row = 0; row < 24; row ++) {
for (col = 0; col < 32; col ++) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 1;
if (col == 15 && (row != 12 && row !=4 && row != 19)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 1 || row == 22) && (col > 2 && col < 29)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((col == 3 || col == 28) && (row > 1 && row < 22 && row != 12)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 3 || row == 20) && (col > 4 && col < 27)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((col == 5 || col == 26) && (row != 9 && row != 15 && row > 3 && row < 20)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if (row == 8 && (col > 5 && col < 15)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if (row == 16 && (col > 15 && col < 26)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 12) && (col > 5 && col < 26)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
}
}
}
void gameplayMaze() {
int x = 103, y = 41, keys;
int maze_success = 0;
while (maze_success == 0) {
scanKeys();
keys = keysHeld();
int xmod = x / 8;
int ymod = x / 8;
if ((keys & KEY_RIGHT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
x++;
printf("%d \n", x);
}
if ((keys & KEY_LEFT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
x--;
}
if (keys & KEY_UP) {
y--;
}
if (keys & KEY_DOWN) {
y++;
}
oamSet(&oamSub,
0,
x, y,
0,
0,
SpriteSize_8x8,
SpriteColorFormat_256Color,
gfxSub,
-1,
false,
false,
false, false,
false
);
swiWaitForVBlank();
oamUpdate(&oamSub);
}
The main problem I have is to try to change from the coordinates of the tiles (which are 8x8) to the ones of the map, as for the coordinates of the sprite (256x192). If any of you have any hint to help me, I would be very grateful! I am still new to programming on the NDS, so I am still struggling to get the hang of it.