moment.js and October 2021 wierd resuutls - momentjs

Adding 24 hours to the 31 October 2021, I was aspecting getting the 1st of November
in 2020 was so, but in 2021 is not .... or I did some stupid mistake...
could anyone help me:
console.log("October 2021")
var a = moment("2021103100", "YYYYMMDDHH").add(23, 'hours').format('YYYYMMDDHH');
console.log(a);
var a = moment("2021103100", "YYYYMMDDHH").add(24, 'hours').format('YYYYMMDDHH');
console.log(a);
var a = moment("2021103100", "YYYYMMDDHH").add(25, 'hours').format('YYYYMMDDHH');
console.log(a);
console.log("October 2020")
var a = moment("2020103100", "YYYYMMDDHH").add(23, 'hours').format('YYYYMMDDHH');
console.log(a);
var a = moment("2020103100", "YYYYMMDDHH").add(24, 'hours').format('YYYYMMDDHH');
console.log(a);
var a = moment("2020103100", "YYYYMMDDHH").add(25, 'hours').format('YYYYMMDDHH');
console.log(a);
console.log("October 2022")
var a = moment("2022103100", "YYYYMMDDHH").add(23, 'hours').format('YYYYMMDDHH');
console.log(a);
var a = moment("2022103100", "YYYYMMDDHH").add(24, 'hours').format('YYYYMMDDHH');
console.log(a);
var a = moment("2022103100", "YYYYMMDDHH").add(25, 'hours').format('YYYYMMDDHH');
console.log(a);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
https://codepen.io/stefanosedano/pen/gOxxora?editors=1011

Related

Layer error: Image.reduceRegion: Too many pixels in the region. Found 13758042614, but maxPixels allows only 10000000. E

Hi I'm new to google earth engine so I am struggling with a (probably) quite basic error.
Here is my code - the issue is with the Sunglint Corrected layer.
I'm trying to correct sentinel-2 images for Sunglint so that I can remote sense seagrass.
I think the issue is something to do with incorrect scaling, although I'm very unsure how to fix this. Plz help!
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-05-01', '2021-09-30')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
.filterBounds(roi)
.select(['B2','B3','B4','B1', 'B8']);
var rgbVis = {
min: 0.0,
max: 1000,
bands: ['B3', 'B2', 'B4'],
};
Map.addLayer(dataset, rgbVis, 'Filtered Collection');
var mosaic = dataset.mosaic();
var medianComposite = dataset.min();
Map.addLayer(medianComposite, rgbVis, 'Median Composite', 0);
var hansenImage = ee.Image('UMD/hansen/global_forest_change_2015');
var datamask = hansenImage.select('datamask');
var mask = datamask.eq(2);
var maskedComposite = medianComposite.updateMask(mask);
Map.addLayer(maskedComposite, rgbVis, 'masked');
Map.addLayer(maskedComposite, {
bands: ['B4', 'B3', 'B2',],
min: 0,
max: 1000
}, 'BOA');
var B2 = maskedComposite.select(['B8', 'B2']);
var B3 = maskedComposite.select(['B8', 'B3']);
var B4 = maskedComposite.select(['B8', 'B4']);
var lfitB2 = B2.reduceRegion({
reducer: ee.Reducer.linearFit(),
geometry: glint,
scale: 10,
//maxPixels: 1000,
//bestEffort: true
});
var lfitB3 = B3.reduceRegion({
reducer: ee.Reducer.linearFit(),
geometry: glint,
scale: 10,
});
var lfitB4 = B4.reduceRegion({
reducer: ee.Reducer.linearFit(),
geometry: glint,
scale: 10,
});
//print('B2 OLS estimates:', lfitB2);
//print('B2 y-intercept:', lfitB2.get('offset'));
//print('B2 Slope:', lfitB2.get('scale'));
//print('B3 Slope:', lfitB3.get('scale'));
//print('B4 Slope:', lfitB4.get('scale'));
var slope_B2 = ee.Image.constant(lfitB2.get('scale')).clip(roi).rename('slope_B2');
var slope_B3 = ee.Image.constant(lfitB3.get('scale')).clip(roi).rename('slope_B3');
var slope_B4 = ee.Image.constant(lfitB4.get('scale')).clip(roi).rename('slope_B4');
var min_B8 = ee.Image.constant(maskedComposite.select('B8').reduceRegion(ee.Reducer.min(),roi, 3).get('B8')).rename('min_B8');
var glint_factors = ee.Image([slope_B2, slope_B3, slope_B4, min_B8]);
var S2 = maskedComposite.addBands(glint_factors);
/*var deglint_B2 = S2.select('B8').subtract(min_B8);
var deglint_B2 = slope_B2.multiply(deglint_B2);
var deglint_B2 = S2.select('B2').subtract(deglint_B2);
Map.addLayer(deglint_B2);*/
var deglint_B2 = S2.expression(
'Blue - (Slope * (NIR - MinNIR))', {
'Blue': S2.select('B2'),
'NIR': S2.select('B8'),
'MinNIR': S2.select('min_B8'),
'Slope': S2.select('slope_B2')
}).rename('B2');
var deglint_B3 = S2.expression(
'Green - (Slope * (NIR - MinNIR))', {
'Green': S2.select('B3'),
'NIR': S2.select('B8'),
'MinNIR': S2.select('min_B8'),
'Slope': S2.select('slope_B3')
}).rename('B3');
var deglint_B4 = S2.expression(
'Red - (Slope * (NIR - MinNIR))', {
'Red': S2.select('B4'),
'NIR': S2.select('B8'),
'MinNIR': S2.select('min_B8'),
'Slope': S2.select('slope_B4')
}).rename('B4');
var S2_deglint = ee.Image([deglint_B2, deglint_B3, deglint_B4]);
Map.addLayer(S2_deglint, {
bands: ['B4', 'B3', 'B2'],
min: 0.0,
max: 0.2
}, 'Sunglint Corrected');
var linkedMap = ui.Map();

Wordpress Woocommerce - Send order data to GoogleSheets via Webhooks

So I wrote this code and it is not working as it should, it is pulling data from woocommerce Webhook with a "code.gs" code in GoogleSheets.
Problem is, if var product_name = myData.line_items[1].name; (and [2], [3] and [4].... and others) does not exist, the code does not work in GoogleSheets...
What i would like to achieve is, when i have two products in an order (myData.line_items[1].name exists, myData.line_items[2].name exists,...) that GoogleSheets would make a new line with that data for each one of the products.
function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}
function doPost(e) {
var myData = JSON.parse([e.postData.contents]);
var order_number = myData.number;
var order_created = myData.date_created;
var product_name = myData.line_items[0].name;
var product_qty = myData.line_items[0].quantity;
var product_total = myData.line_items[0].total;
var produktsku = myData.line_items[0].sku;
var product_name = myData.line_items[1].name;
var product_qty = myData.line_items[1].quantity;
var product_total = myData.line_items[1].total;
var produktsku = myData.line_items[1].sku;
var product_namea = myData.line_items[2].name;
var product_qtya = myData.line_items[2].quantity;
var product_totala = myData.line_items[2].total;
var produktskua = myData.line_items[2].sku;
var product_nameb = myData.line_items[3].name;
var product_qtyb = myData.line_items[3].quantity;
var product_totalb = myData.line_items[3].total;
var produktskub = myData.line_items[3].sku;
var product_namec = myData.line_items[4].name;
var product_qtyc = myData.line_items[4].quantity;
var product_totalc = myData.line_items[4].total;
var produktskuc = myData.line_items[4].sku;
var product_named = myData.line_items[5].name;
var product_qtyd = myData.line_items[5].quantity;
var product_totald = myData.line_items[5].total;
var produktskud = myData.line_items[5].sku;
var order_total = myData.total;
var billing_email = myData.billing.email;
var billing_first_name = myData.billing.first_name;
var billing_last_name = myData.billing.last_name;
var billing_countryshort = myData.billing.country;
var payment_method = myData.payment_method_title;
var shipping_method = myData.shipping_lines[0].method_title;
var shipping_total = myData.shipping_lines[0].total;
var shipping_total = myData.shipping_lines[0].total;
var klingi = "1";
var timestamp = new Date();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([timestamp,order_created,order_number,product_name,produktsku,product_qty,product_total,order_total,billing_email,billing_first_name,billing_last_name,payment_method,shipping_method,shipping_total,billing_countryshort]);
if( produktskua ) {
sheet.appendRow(["Izdelek 2", "",order_number,product_namea,produktskua,product_qtya,product_totala]);
};
if( produktskub ) {
sheet.appendRow(["Izdelek 3", "",order_number,product_nameb,produktskub,product_qtyb,product_totalb]);
};
if( produktskuc ) {
sheet.appendRow(["Izdelek 4", "",order_number,product_namec,produktskuc,product_qtyc,product_totalc]);
};
}
Any ideas?
It stops working, even if I wrap it, it works only if value exists...
if( myData.line_items[1].name ) {
var product_namea = myData.line_items[1].name;
var product_qtya = myData.line_items[1].quantity;
var product_totala = myData.line_items[1].total;
var produktskua = myData.line_items[1].sku;
};
When assigning your post data to variables, you can use the ternary operator
This allows you to verify either a certain postData exists, and if not - assign an empty string to the variable in order to prevent problems with Google Sheets.
Syntax:
condition ? exprIfTrue : exprIfFalse
Sample:
var product_namea = (myData.line_items[2].name) ? myData.line_items[2].name : " ";
Also: Be careful with overwriting variable names, in your code you
have e.g. twice var product_name
Is solved like this:
function doPost(e) {
var myData = JSON.parse([e.postData.contents]);
var timestamp = new Date();
var order_created = myData.date_created;
var billing_first_name = myData.billing.first_name;
var billing_phone = myData.billing.phone;
var billing_email = myData.billing.email;
var shipping_address = myData.billing.address_1 + myData.billing.address_2;
var order_total = myData.total;
var order_number = myData.number;
var billing_last_name = myData.billing.last_name;
var billing_countryshort = myData.billing.country;
var payment_method = myData.payment_method_title;
var shipping_method = myData.shipping_lines[0].method_title;
var shipping_total = myData.shipping_lines[0].total;
var quantity_prvi = myData.line_items[0].quantity;
var linetotal_prvi = myData.line_items[0].total;
var produktsku_prvi = myData.line_items[0].sku;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([billing_countryshort,timestamp,order_created,"Order",order_number,billing_first_name,billing_last_name,shipping_address,billing_email,billing_phone,produktsku_prvi,quantity_prvi,linetotal_prvi,shipping_total,shipping_method,order_total,payment_method]);
var lineitems=""
for (i in myData.line_items)
if(i>0){
{
var quantity = myData.line_items[i].quantity;
var linetotal = myData.line_items[i].total;
var produktsku = myData.line_items[i].sku;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([billing_countryshort,timestamp,order_created,"Dodaten produkt",order_number,"","","","","",produktsku,quantity,linetotal]);
}
}
}

PayPal Plus stay on own page

I have implemented a small PayPal PLUS Demo in ASP.NET:
protected void Page_Load(object sender, EventArgs e)
{
var config = ConfigManager.Instance.GetProperties();
config.Add("clientId", "XXXXXXXXXXXXXXXXXXXXXXXXX");
config.Add("clientSecret", "XXXXXXXXXXXXXXXXXXXXXXXXX");
config.Add("mode", "sandbox");
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);
var itemList = new ItemList() { items = new List<Item>() { new Item() { name = "Item Name", currency = "USD", price = "15", quantity = "5", sku = "sku" } } };
var payer = new Payer() { payment_method = "paypal" };
var baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentWithPayPal.aspx?";
var guid = Convert.ToString((new Random()).Next(100000));
var redirectUrl = baseURI + "guid=" + guid;
var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&cancel=true", return_url = redirectUrl };
var details = new Details() { tax = "15", shipping = "10", subtotal = "75" };
var amount = new Amount() { currency = "USD", total = "100.00", details = details };
var transactionList = new List<Transaction> { new Transaction() { description = "Transaction description.", invoice_number = new Random().Next(999999).ToString(), amount = amount, item_list = itemList } };
var payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls };
var createdPayment = payment.Create(apiContext);
var approval_url = createdPayment.links.FirstOrDefault(x => x.rel == "approval_url").href;
hfApprovalUrl.Value = approval_url;
}
<asp:HiddenField runat="server" id="hfApprovalUrl"/>
<script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="ppplus"></div>
<script type="application/javascript">
var approval_url = $('#hfApprovalUrl').val();
var ppp = PAYPAL.apps.PPP({
"approvalUrl": approval_url,
"placeholder": "ppplus",
"mode": "sandbox",
"country": "DE"
});
</script>
Its works so far but if a choose a pay option (e.g. credit card) I will be redirected to PayPal.I want that the user stys on my own page. How can I do this?
Thanks!
Jan

GoogleMaps Markerclusterer InfoWindow same location, Cluster get content from Markers

i have problem, MarkerCluster undefined content from Markers.
I used MarkerCluster in same address (location) gridSize: 1
If pressing Cluster zoomOnClick:false, Cluster must getMarkers content
and open infowindow. but I get undefined undefined .
I chink this problem on this
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
var markers = cluster.getMarkers();
var content = '';
for (var i = 0; i < markers.length; i++) {
var marker = markers[i];
content += marker.name;
content += ("<br>");
}
var infowindow = new google.maps.InfoWindow();
infowindow.setPosition(cluster.getCenter());
infowindow.close();
infowindow.setContent(content);
infowindow.open(map);
google.maps.event.addListener(map, 'zoom_changed', function() {
infowindow.close();
});
});
Full code:
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(55.7522200, 37.6155600),
zoom: 11
});
var infoWindow = new google.maps.InfoWindow;
var iconPurple = new google.maps.MarkerImage('mapimages/purple.svg', new google.maps.Size(33, 31));
var iconBlue = new google.maps.MarkerImage('mapimages/blue.svg', new google.maps.Size(33, 31));
var iconYellow = new google.maps.MarkerImage('mapimages/yellow.svg', new google.maps.Size(33, 31));
var iconGreen = new google.maps.MarkerImage('mapimages/green.svg', new google.maps.Size(33, 31));
var iconPink = new google.maps.MarkerImage('mapimages/pink.svg', new google.maps.Size(33, 31));
var iconBrown = new google.maps.MarkerImage('mapimages/brown.svg', new google.maps.Size(33, 31));
var customIcons = [];
customIcons["room1"] = iconPurple;
customIcons["room2"] = iconBlue;
customIcons["room3"] = iconYellow;
customIcons["room4"] = iconGreen;
customIcons["room5"] = iconPink;
customIcons["room6"] = iconBrown;
var options = {
gridSize: 1,
zoomOnClick:false,
imagePath: 'mapimages/m'
};
downloadUrl(markers.php', function(data) {
var xml = data.responseXML;
var markerArray = [];
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute("name");
var address = markerElem.getAttribute("address");
var metro = markerElem.getAttribute("metro");
var type = markerElem.getAttribute("type");
var date = markerElem.getAttribute("date");
var status = markerElem.getAttribute("status");
var inrequest = markerElem.getAttribute("inrequest");
var phone = markerElem.getAttribute("phone");
var message = markerElem.getAttribute("message");
var area_room = markerElem.getAttribute("area_room");
var price = markerElem.getAttribute("price");
var floore = markerElem.getAttribute("floore");
var floors = markerElem.getAttribute("floors");
var rooms_furniture = markerElem.getAttribute("rooms_furniture");
var kitchen_furniture = markerElem.getAttribute("kitchen_furniture");
var repaint = markerElem.getAttribute("repaint");
var comment = markerElem.getAttribute("comment");
var distance = markerElem.getAttribute("distance");
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var html = "<h1>" + "м. " + metro + ", " + address + "</h1>"
+ "<h2>" + phone + " " + name + "</h2>"
+ "<h3>" + type + " " + area_room + "&nbspм " + price + " р. этаж " + floore + "/" + floors + "</h3>"
+ "<p>" + rooms_furniture + " " + kitchen_furniture + " " + repaint + "</p>"
+ "<h5>" + distance + " " + comment + " " + message + "</h5>" + "<h6>" + date + " " + inrequest + " " + status + "</h6>";
var marker = new google.maps.Marker({
map: map,
position: point,
icon: customIcons[type],
animation: google.maps.Animation.DROP
});
markerArray.push(marker);
marker.addListener('click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
});
var markerCluster = new MarkerClusterer(map, markerArray, options);
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
var markers = cluster.getMarkers();
var content = '';
for (var i = 0; i < markers.length; i++) {
var marker = markers[i];
content += marker.name;
content += ("<br>");
}
var infowindow = new google.maps.InfoWindow();
infowindow.setPosition(cluster.getCenter());
infowindow.close();
infowindow.setContent(content);
infowindow.open(map);
google.maps.event.addListener(map, 'zoom_changed', function() {
infowindow.close();
});
});
});
}
function downloadUrl(url,callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);//right here
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
enter image description here
The google.maps.Marker objects in the MarkerClusterer are not the same "marker" XML elements you are parsing to create the google.maps.Markers. The won't have a name property, unless you create one.
var marker = new google.maps.Marker({
map: map,
position: point,
icon: customIcons[type],
animation: google.maps.Animation.DROP,
name: name // <-- add this
});
proof of concept fiddle

How to get the content of <script> via simple_html_dom

I'm parsing text using SIMPLE HTML DOM.
I read the documentation but didn't find how to get the content of .
I want to get the this line /uploads/music/3/38/29_macho_skr-ft-a.l.a.m-repa-goydm.mp3 from this script. Is it possible? Any helps appreciated.
<script type="text/javascript" defer="defer">
var flashvars = {};
flashvars.skin = '/templates/topmusic/i/nobius_mk2/skin.xml';
flashvars.playlistxml = '<track><location>/uploads/music/3/38/29_macho_skr-ft-a.l.a.m-repa-goydm.mp3</location><creator>Macho_SkR ft A.L.A.M 2014-New</creator><title>Repa Goydm Manhattan Prod.</title></track>';
flashvars.autoplay = 'false';
flashvars.volume = '80';
flashvars.shuffle = 'false';
flashvars.repeat = 'true';
flashvars.key = '9GXNDFPR9ZPG1EPA1JHV';
flashvars.mousewheelfix = 'true';
var params = {};
var attributes = {};
attributes.id = 'ep_player1';
swfobject.embedSWF( '/engine/player/ep_player.swf');
</script>
So here is the answer:
foreach($html->find('.news_cont_pad script[defer="defer"]') as $element)
{
$linkkk = $element->innertext;
$link_e = explode('location', $linkkk);
$aaaa=$link_e[1];
$rest_r = substr($aaaa, 0, -2);
$rest_link = substr($rest_r, 1);
$rest_linkaa[] = 'http://xxx.xx'.$rest_link;
}

Resources