lila | dynamic language running on the JVM with efficient multiple | Runtime Evironment library
kandi X-RAY | lila Summary
Support
Quality
Security
License
Reuse
- Fallback method handling
- Compiles one level n
- Add a multi method
- Compiles multiple methods
- Internal helper for building a Lila object
- Creates a target handle for the given arguments
- Returns an array of MethodHandle objects matching the specified types
- Compile an ASM
- Dumps the given dispatch tree to a file
- Call the next method
- Compile the ASM operator
- Compiles the ASM handle
- Prepare for DNF
- Compiles an ASM handle
- Computes the linearization of a class
- Returns true if this is false otherwise
- Concatenates two arrays
- Default fallback method handle
- Returns the fallback method for the call site
- Converts this node to DNF
- Dumps the state of the node
- Writes the dump to the given output stream
- Performs a benchmark of a Lila function
- Compares two methods
- Dumps the contents of this node
- Creates a call site with the given name and value
lila Key Features
lila Examples and Code Snippets
Trending Discussions on lila
Trending Discussions on lila
QUESTION
I am trying to find the preceding row to a specific occurrence in a database, or rather some data from it.
In this example I would like to find the movement_method of the preceding row (sorted by timestamp) before a user visited the pub. So in tom's example I would like to know that tom went home by car before visiting the pub. (it doesn't matter how he traveled to the pub but rather the used method before going to the pub)
I have an example database with: user, location, movement_method, timestamp:
user location movement_method timestamp tom work car 2022-03-02 14:30 tom home car 2022-03-02 20:30 tom pub bus 2022-03-02 22:30 tom home foot 2022-03-03 02:30 jane school bus 2022-03-02 08:30 jane home bus 2022-03-02 14:30 jane pub foot 2022-03-02 21:30 jane home bus 2022-03-02 23:30 lila work bus 2022-03-02 08:30 lila home bus 2022-03-02 16:30 jake friend car 2022-03-02 15:30 jake home bus 2022-03-02 20:30 jake pub car 2022-03-02 20:30 jake home car 2022-03-03 02:30For this database the result I would want would be: | user | preceding_movement_method | | ---- | ------- | | tom | car | | jane | bus | | jake | bus |
- lila is not being reported because she never visited the pub
- I only need to know the preceding movement_method before visiting the pub (sorted by time)
- the movement_method which was used to go to the pub is not relevant
My current approach is to have a partition or window function for "preceding_movement_method" but I'm stuck finding the "preceding" entry before the one which fits the where statement.
So I'm looking for something like this pseudocode:
select user,
(select preceding movement_method
from movement_database
where location = 'pub'
order by timestamp) as preceding_movement_method
from movement_database
ANSWER
Answered 2022-Apr-01 at 09:31Well, I'm not sure if it's a typo but the user jake has an IDENTICAL timestamp at home as at pub's which is an unlikely event. The code may seem a bit complicated, but it does take the problem into consideration.
select t1.`user`, movement_method from movement t1 join
(select m.`user`, max(m.`timestamp`) mx from movement m
join
(select `user`,`timestamp` from movement where location ='pub') t
on m.`user` = t.`user`
where m.`timestamp` <=t.`timestamp` and m.`location`!='pub'
group by `user`) t2
on t1.`user`=t2.`user` and t1.`timestamp`=mx and t1.location!='pub';
QUESTION
Create a program, palindrome.py, that has a function that takes in one string argument and prints a sentence indicating if the text is a palindrome. The function should consider only the alphanumeric characters in the string, and not depend on capitalization, punctuation, or whitespace. If the string is a palindrome, it should print: It's a palindrome! However, if the string is not a palindrome, it should print: It's not a palindrome!
The Problem
My code is not printing whether it is a palindrome when there are spaces inside the string, but does print that it is not a palindrome despite having spaces. I included replace(), zip(), and reversed() in my code to account for the spaces and the reversed words, but it is not printing the desired result.
What am I missing or doing wrong in my code?
import sys
def palindrome(words):
if ' ' in words:
palindromes = words[::-1]
if palindromes == words:
return "It's a palindrome!"
return "It's not a palindrome!"
print(palindrome(sys.argv[1]))
Example Test Cases
Test Case 1
tests 1 Run python3 palindrome.py 'Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned' and match its output to an expected value.
Test Case 2
test 2 Run python3 palindrome.py 'Ed, I saw Harpo Marx ram Oprah W. aside' and match its output to an expected value.
Outputs
Expected Output: "It's a palindrome!"
Actual Output: "It's not a palindrome!"
ANSWER
Answered 2022-Mar-18 at 08:47Your whole code is indented in the first if
condition, which means it would work only if your entry string has a space in it.
On top of that, do you use quotes or double quotes when you add your argument ? Because using sys.argv[1]
takes the 1st argument.
python3 palindrome.py hey yeh # does not work
python3 palindrome.py "hey yeh" # is supposed to work
The probleme with your code example is that among every non alphabetic caracters you are only trying to handle the space.
def palindrome(words):
words = ''.join(filter(str.isalnum, words.lower()))
palindrome = words[::-1]
if palindrome == words:
return ("It's a palindrome!")
return ("It's not a palindrome!")
print(palindrome(sys.argv[1]))
QUESTION
Consider the following SQL run on SQL Server. The only difference between these two blocks is that one has the Default Namespace Set. Why does the one with the default namespace fail to parse?
I realize there are other ways to parse xml within sql server. I am just trying to understand the oddity in these two examples explicitly. Any help is appreciated.
DECLARE @idoc INT, @doc VARCHAR(1000);
SET @doc ='
';
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc;
-- SELECT statement as written returns 0 records.
SELECT *
FROM OPENXML (@idoc, '/ROOT/Customers')
EXEC sp_xml_removedocument @idoc;
GO
DECLARE @idoc INT, @doc VARCHAR(1000);
SET @doc ='
';
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc;
-- SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/ROOT/Customers')
EXEC sp_xml_removedocument @idoc;
GO
Relevant Link: Proc sp_xml_preparedocument Documentation
SQL Server 2014
ANSWER
Answered 2022-Feb-17 at 19:25The first doc has a default namespace so the names, so ROOT and Customers are in the namespace "Test", and the XPath expression "/ROOT/Customers" doesn't match them. You need to introduce a namespace alias for "Test" to use in your XPath expression.
You do this by providing a dummy XML doc with the alaised namespace declarations as the third argument to sp_xml_preparedocument, like this:
DECLARE @idoc INT, @doc VARCHAR(1000);
SET @doc ='
';
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc, N'';
-- SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/d:ROOT/d:Customers')
EXEC sp_xml_removedocument @idoc;
GO
QUESTION
I have a long list, and I want to add the first letter into another cell with psql command.
A header Another header John J Lila L Dwane D Zaba Z Kiol K Longi L Uthe U Hell HLike this.
ANSWER
Answered 2022-Feb-07 at 10:57You can use the left()
postgres function to extract the first charater from a string, see the manual. Try something like this :
SELECT "A header", left("A header", 1) AS "Another header"
FROM your_table
QUESTION
Selenium Python get_attribute("src") returns None, eventhough there is a "src" attribute
Code Trials:
link = f"https://duckduckgo.com/?q={searchtext}&iax=images&ia=images"
driver = webdriver.Firefox()
driver.get(link)
time.sleep(2)
tabbutton = driver.find_element(By.CSS_SELECTOR, "div.tile:nth-child(3)")
webdriver.ActionChains(driver).click(tabbutton).perform()
imagelink = driver.find_element(By.CSS_SELECTOR, "div.detail__pane:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1) > img:nth-child(3)")
src = imagelink.get_attribute("src")
print(src)
It always prints "None" and every other attribute is working. The html is:
ANSWER
Answered 2022-Feb-01 at 15:25To print the value of the src attribute you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "img.detail__media__img-highres[alt^='Flower Blume Pflanze Lila Gelb - ZoPix']"))).get_attribute("src"))
Using XPATH:
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//img[@class='detail__media__img-highres js-detail-img js-detail-img-high' and @alt='Flower Blume Pflanze Lila Gelb - ZoPix.NET']"))).get_attribute("src"))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
QUESTION
Welcome,
for a long time I'm struggling with the problem of redirecting the url to a separate url in case the a special baerer token is given, I don't want to change any parameter just make a match and send this match to another url. My setup is apache 2.4.41 typical request from postman: https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467
the redirection should be like this: http://tomcat-local:10022/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467
What I've tried so far in apache2.conf
RewriteCond %{QUERY_STRING} ^access_token=(988738467)$
RewriteRule (.*) http://tomcat-local:10022/ [R=301,L]
The goal is that a client with a specific token will be served by a specific tomcat server
Please help me, maybe I'm doing something wrong, I tried also RedirectMatch, unfortunately without success, all regexes I tested on https://regex101.com/
EDIT:
Still Nothing,I don't understand what's wrong. My config
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,P,L]
# disable some HTTP request types for security reasons
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD|OPTIONS)$
RewriteRule .* - [F]
Access_log :
"GET /rest/auto-com/complete_addr?in_country=FR&in_line=73%20avenue%20des%20lilas&access_token=988738467 HTTP/1.1" "complete_addr" 200 200 1225 "-" "PostmanRuntime/7.28.4"
Solved
RewriteEngine On
RewriteOptions InheritDown
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,P,L]
# disable some HTTP request types for security reasons
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD|OPTIONS)$
RewriteRule .* - [F]
Greetings Paul
ANSWER
Answered 2022-Jan-27 at 10:28Finally this issue was solved by adding RewriteOptions InheritDown
before the rewrite rules, and adding RewriteEngine On
to all the virtualhosts.
Try:
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,R=301,L]
This will redirect:
https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467
tohttp://tomcat-local:10022/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467
ifaccess_token
is988738467
https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?abc=123&access_token=988738467
tohttp://tomcat-local:10022/rest/auto-com/complete_addr?abc=123&access_token=988738467
Although I gave you this solution, I am still very confused on why you want to do an external redirect to a local page. I believe you want a proxy pass.
Explanation why the Rewrite*
on the question didn't work:
^access_token
in^access_token=(988738467)$
means thataccess_token
must be the first in the query string.(988738467)$
means that988738467
must be at the end of the query string.
With the above issues, only https://https://xxxdddyyy.dqco1.firma-online.com/anything?access_token=988738467
will work with your RewriteCond
.
For internal redirect to backend server:
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,P,L]
You might want to have the modules mod_proxy
and mod_proxy_http
enabled.
Your configuration should be:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,P,L]
# disable some HTTP request types for security reasons
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD|OPTIONS)$
RewriteRule .* - [F]
Make sure mod_rewrite is enabled. I suggest you to remove IfModule
to avoid confusion when some day mod_rewrite
is disabled. Because IfModule
will cause no error to show up, and it will cause confusion.
Adding RewriteOptions InheritDown
outside the virtualhosts, causes the rules to be inherited by the virtualhosts.
So, all the virtualhosts will be using it.
By default in Apache, the rules specified outside virtualhosts is not inherited by virtualhosts.
QUESTION
I'm stuck on how to calculate the total amount and total price of my cart in this project. The task is to create a simple (beginners) e-commerce website where a customer should be able to click on a product and add it to their cart (with the name, amount and price displayed of the product, the amount and price should update correctly according to how many times a customer clicks on the button attached to the product).
And I can only use javascript (or html if necessary).
I have the website mostly working. Everything can be added to the cart and the cart keeps track of the amount and price for each product.
But I can't figure out how to make it so when I press the buy button, below the cart, the total amount and total price of all the products added to the cart is displayed in a string beneath the cart.
I've tried searching online for answers but I can't seem to figure it out.
Please help! :)
Anything you can think of is greatly appreciated because at this point I'm completely clueless. And worth to note, I'm really new to javascript!
Here are my javascript code thus far:
var products =
[
{
"name": "Aloe Vera",
"image": "bilder/severin-candrian-dgvFsLfIX9E-unsplash.jpg",
"origin": "Nederländerna",
"description": "Lättskött suckulent med tjocka gröna blad. En av världens äldsta läkeväxkter. Trivs på soliga platser. Låt den torka ut mellan varje vattning.",
"height": "120cm",
"care": "Trivs ljust, men undvik direkt solljus. Vattna undertill och inte på växten, men låt jorden torka mellan varje vattning. Ge flytande näring från vår till höst. Eventuell omplantering ska göras på våren.",
"price": 59
},
{
"name": "Marmorblad",
"image": "bilder/severin-candrian-8nONCr6eTeg-unsplash.jpg",
"origin": "Brasilien",
"description": "Fin och spännande växt med kontrastrika blad med grönt mönster och lila undersida på bladen. Denna dekorativa planta passar perfekt i en kruka på golvet eller på en piedestal eller ett sidobord.",
"height": "65cm",
"care": "Ge den lite utrymme så att bladen kan sträcka ut sig väl både uppåt och åt sidorna och skapa en grön och harmonisk atmosfär i hemmet. Trivs i ljus och halvskugga, undvik direkt solljus. Håll jorden lätt fuktig. Gillar att bli duschad på bladen.",
"price": 299
},
{
"name": "Lyktranka",
"image": "bilder/severin-candrian-xGpYDi-0348-unsplash.jpg",
"origin": "Sydafrika, Swaziland och Zimbabwe",
"description": "Även känd som Hjärtan på tråd. Lyktrankan är mycket lätt att sköta och är en vacker hängväxt med små mörkgröna hjärtformade blad med ett silverskimrande mönster. Plantan kan bli över en meter, vilket gör den väl lämpad som hängväxt eller i en hög kruka.",
"height": "15 cm",
"care": "Trivs ljust, undvik direkt solljus. Låt den torka lätt mellan vattningarna.",
"price": 79
}
];
let cart = {} ;
function initCart() {
for (let product of products) {
cart[product.name] = 0;
}
}
function renderCart() {
let tbody = document.querySelector("#cart > tbody");
tbody.innerHTML = "";
for (let product of products) {
let row = tbody.insertRow(-1);
let cellName = row.insertCell(-1);
let cellAmount = row.insertCell(-1);
let cellPrice = row.insertCell(-1);
let amount = cart[product.name];
cellName.textContent = product.name;
cellAmount.textContent = amount;
cellPrice.textContent = amount * product.price;
}
}
function increment(name) {
console.log("Name: " + name);
cart[name]++;
renderCart();
}
function buy() {
document.getElementById("totalCart").textContent = "Du har lagt till " + count + " st" + " produkter." + " " + "Vilket blir en summa på " + total + " kr" + "." ;
}
var count = countCart() ;
var total = totalCart() ;
function countCart() {
var totalCount = 0 ;
for (var i in cart) {
totalCount += cart[i].amount ;
}
return totalCount ;
}
function totalCart() {
var totalPrice = 0 ;
for (var i in cart) {
totalPrice += cart[i].price ;
}
return totalPrice ;
}
function renderProducts() {
const template = `
`;
const container = document.querySelector("#products");
for (let product of products) {
let item = document.createElement("div");
item.classList.add("item", "ml-2");
item.innerHTML = template;
item.querySelector("img").src = product.image;
item.querySelector(".name").textContent = product.name;
item.querySelector(".origin").textContent = product.origin;
item.querySelector(".height").textContent = product.height;
item.querySelector(".care").textContent = product.care;
item.querySelector(".description").textContent = product.description;
item.querySelector(".price").textContent = product.price;
item.querySelector(".button").addEventListener("click", () => increment(product.name));
container.appendChild(item);
}
}
window.onload = function() {
renderProducts();
initCart();
renderCart();
}
And my html:
Varukorg
Produkt
Antal
Pris
Växter
Sorry some of the words are in Swedish! The only words you probably need to know is:
"lägg i varukorgen" = add to cart
"köp" = buy
"pris" = price
"antal" = amount
"produkt" = product
ANSWER
Answered 2022-Jan-16 at 20:33Your issue is that your cart
is only storing the following information in key-value pairs: the key is the product name, and the quantity is the value. There is no price information in the cart
object at all, therefore computing it requires looking up the original products
array.
Moreover, count
and total
are declared outside the buy()
function, yet the function, when invoked, does not update these values. These values are only set at runtime and is not updated after.
Therefore the quickest solution is to rewrite your buy()
function into something like this, while removing the countCart()
and totalCart()
functions:
function buy() {
var count = Object.values(cart).reduce((sum, cur) => sum += cur, 0);
var total = Object.entries(cart).reduce((sum, cur) => {
const [product, quantity] = cur;
return sum += products.find(p => p.name === product).price * quantity;
}, 0);
document.getElementById("totalCart").textContent = "Du har lagt till " + count + " st" + " produkter." + " " + "Vilket blir en summa på " + total + " kr" + ".";
}
Explanation of the code:
count
is pretty straight forward: you get all the values in yourcart
object and sum them up usingArray.prototype.reduce
total
is a bit complicated: you need to iterate through yourcart
in a way that gives you access to with the key (product name) and value (the quantity). Object.entries() can do that for you. Then it is a matter of looking up theproducts
array of object to retrieve the price for a given product, and multiplying the quantity.
var products = [{
"name": "Aloe Vera",
"image": "bilder/severin-candrian-dgvFsLfIX9E-unsplash.jpg",
"origin": "Nederländerna",
"description": "Lättskött suckulent med tjocka gröna blad. En av världens äldsta läkeväxkter. Trivs på soliga platser. Låt den torka ut mellan varje vattning.",
"height": "120cm",
"care": "Trivs ljust, men undvik direkt solljus. Vattna undertill och inte på växten, men låt jorden torka mellan varje vattning. Ge flytande näring från vår till höst. Eventuell omplantering ska göras på våren.",
"price": 59
},
{
"name": "Marmorblad",
"image": "bilder/severin-candrian-8nONCr6eTeg-unsplash.jpg",
"origin": "Brasilien",
"description": "Fin och spännande växt med kontrastrika blad med grönt mönster och lila undersida på bladen. Denna dekorativa planta passar perfekt i en kruka på golvet eller på en piedestal eller ett sidobord.",
"height": "65cm",
"care": "Ge den lite utrymme så att bladen kan sträcka ut sig väl både uppåt och åt sidorna och skapa en grön och harmonisk atmosfär i hemmet. Trivs i ljus och halvskugga, undvik direkt solljus. Håll jorden lätt fuktig. Gillar att bli duschad på bladen.",
"price": 299
},
{
"name": "Lyktranka",
"image": "bilder/severin-candrian-xGpYDi-0348-unsplash.jpg",
"origin": "Sydafrika, Swaziland och Zimbabwe",
"description": "Även känd som Hjärtan på tråd. Lyktrankan är mycket lätt att sköta och är en vacker hängväxt med små mörkgröna hjärtformade blad med ett silverskimrande mönster. Plantan kan bli över en meter, vilket gör den väl lämpad som hängväxt eller i en hög kruka.",
"height": "15 cm",
"care": "Trivs ljust, undvik direkt solljus. Låt den torka lätt mellan vattningarna.",
"price": 79
}
];
let cart = {};
function initCart() {
for (let product of products) {
cart[product.name] = 0;
}
}
function renderCart() {
let tbody = document.querySelector("#cart > tbody");
tbody.innerHTML = "";
for (let product of products) {
let row = tbody.insertRow(-1);
let cellName = row.insertCell(-1);
let cellAmount = row.insertCell(-1);
let cellPrice = row.insertCell(-1);
let amount = cart[product.name];
cellName.textContent = product.name;
cellAmount.textContent = amount;
cellPrice.textContent = amount * product.price;
}
}
function increment(name) {
console.log("Name: " + name);
cart[name]++;
renderCart();
}
function buy() {
var count = Object.values(cart).reduce((sum, cur) => sum += cur, 0);
var total = Object.entries(cart).reduce((sum, cur) => {
const [product, quantity] = cur;
return sum += products.find(p => p.name === product).price * quantity;
}, 0);
document.getElementById("totalCart").textContent = "Du har lagt till " + count + " st" + " produkter." + " " + "Vilket blir en summa på " + total + " kr" + ".";
}
function renderProducts() {
const template = `
`;
const container = document.querySelector("#products");
for (let product of products) {
let item = document.createElement("div");
item.classList.add("item", "ml-2");
item.innerHTML = template;
item.querySelector("img").src = product.image;
item.querySelector(".name").textContent = product.name;
item.querySelector(".origin").textContent = product.origin;
item.querySelector(".height").textContent = product.height;
item.querySelector(".care").textContent = product.care;
item.querySelector(".description").textContent = product.description;
item.querySelector(".price").textContent = product.price;
item.querySelector(".button").addEventListener("click", () => increment(product.name));
container.appendChild(item);
}
}
window.onload = function() {
renderProducts();
initCart();
renderCart();
}
Varukorg
Produkt
Antal
Pris
Växter
QUESTION
I have a script that used to work for calculating zonal statistics (median), but now I get the AttributeError: 'DatasetReader' object has no attribute 'affine'. Here is my code:
with rasterio.open(f'{project_data}/ras.tif') as raster:
array = raster.read(1)
affine = raster.affine
stat = zonal_stats(f'{project_data}/Lila.shp', array, affine=affine,
stats=['median'], geojson_out=True)
result = {"type": "FeatureCollection", "features": stat}
outname = f'{project_data}/files/Lala_test.geojson'
with open(outname, 'w') as outfile:
json.dump(result, outfile)
I unsucessfully tried to install rioxarray yesterday with Anaconda, and I am using an virtual conda - environment (Python 3.8 Interpreter), could that be the problem? If yes, how can I fix that? I am on windows 10...
ANSWER
Answered 2022-Jan-13 at 21:13affine
has been deprecated. transform
now accepts GDAL and Affine style transforms.
From Migrating to Rasterio 1.0 affine.Affine() vs. GDAL-style geotransforms:
https://rasterio.readthedocs.io/en/latest/topics/migrating-to-v1.html
Since the above changes, several functions have been added to Rasterio that accept a transform argument. Rather than add an affine argument to each, the transform argument could be either an Affine() object or a GDAL geotransform, the latter issuing the same deprecation warning.
The original plan was to remove the affine argument + property, and assume that the object passed to transform is an Affine(). However, after further discussion it was determined that since Affine() and GDAL geotransforms are both 6 element tuples users may experience unexplained errors and outputs, so an exception is raised instead to better highlight the error.
QUESTION
Is there a way to regex from digit to digit?
I have this tracklist:
01. Intro 02. Waage 03. Hyänen (feat. Samra) 04. Ich will es bar (feat. Haftbefehl) 05. Am Boden bleiben (feat. Casper & Montez) 06. Panzerglas (feat. Face) 07. Sobald Du gehst 08. 90’s (feat. Olson) 09. Erzähl‘ mir nix (feat. Nio) 10. Dope & 40s 11. Lila (feat. Bosca) 12. Wo ich wohn‘ 13. Bahnen 14. 200K
which I tried to split with /\d\d([^\d]*)/g
into objects. But I got as a result:
0: ""
1: ". Intro "
2: ""
3: ". Waage "
4: ""
5: ". Hyänen (feat. Samra) "
6: ""
7: ". Ich will es bar (feat. Haftbefehl) "
8: ""
9: ". Am Boden bleiben (feat. Casper & Montez) "
10: ""
11: ". Panzerglas (feat. Face) "
12: ""
13: ". Sobald Du gehst "
14: ""
15: ". "
16: ""
17: "’s (feat. Olson) "
18: ""
19: ". Erzähl‘ mir nix (feat. Nio) "
20: ""
21: ". Dope & "
22: ""
23: "s "
24: ""
25: ". Lila (feat. Bosca) "
26: ""
27: ". Wo ich wohn‘ "
28: ""
29: ". Bahnen "
30: ""
31: ". "
32: ""
33: ""
34: "0K"
How do I include the numbers 01
, 02
, 03
... and what are the possibilites for cases like track 14 where the title track is 200k
?
ANSWER
Answered 2021-Dec-25 at 19:17You can use
text.split(/\s+(?=\d+\.\s)/)
See the regex demo. Details:
\s+
- one or more whitespaces(?=\d+\.\s)
- a positive lookahead that requires one or more digits,.
and a whitespace to occur immediately to the right of the current location.
See the JavaScript demo:
const text = "01. Intro 02. Waage 03. Hyänen (feat. Samra) 04. Ich will es bar (feat. Haftbefehl) 05. Am Boden bleiben (feat. Casper & Montez) 06. Panzerglas (feat. Face) 07. Sobald Du gehst 08. 90’s (feat. Olson) 09. Erzähl‘ mir nix (feat. Nio) 10. Dope & 40s 11. Lila (feat. Bosca) 12. Wo ich wohn‘ 13. Bahnen 14. 200K";
text.split(/\s+(?=\d+\.\s)/).forEach( x =>
console.log(x))
If you need to make sure the bullet numbers come in incrementally, you need to adjust the code to
const text = "01. Intro containing 26. chars 02. Waage 03. Hyänen (feat. Samra) 04. Ich will es bar (feat. Haftbefehl) 05. Am Boden bleiben (feat. Casper & Montez) 06. Panzerglas (feat. Face) 07. Sobald Du gehst 08. 90’s (feat. Olson) 09. Erzähl‘ mir nix (feat. Nio) 10. Dope & 40s 11. Lila (feat. Bosca) 12. Wo ich wohn‘ 13. Bahnen 14. 200K";
var chunks = text.split(/\s+(?=\d+\.\s)/)
chunks = chunks.reduce(
function(acc, currentValue, index) {
if (index>0) {
const num = Number(currentValue.match(/^\d+/)[0])
if (num - num_prev === 1) {
acc.push(currentValue); num_prev = num;
} else {
acc[acc.length-1] += ` ${currentValue}`;
}
return acc;
} else {
acc = [currentValue]; num_prev = 1;
return acc;
}
}, [])
chunks.forEach( x =>
console.log(x))
QUESTION
I have my 3 arrays which I put into these variables:
$title = $_REQUEST['test_bestellte_title'];
$anzahl = $_REQUEST['test_bestellte_anzahl'];
$groesse = $_REQUEST['test_bestellte_groesse'];
I want to insert this array of values into the sql table like
ID | Anzahl | title | groesse
-----------------------------------------
1 | 4 | Schulkind Shirt gelb | S
1 | 5 | Friends Shirt lila | M
1 | 3 | Shirt Sesamstraße | S
1 | 4 | Shirt Sesamstraße | L
But I have no clue how to insert it like shown above
I split them up with for each so far, that's where I'm stuck
foreach ($anzahl as $einzelanzahl) {
echo $einzelanzahl['test_bestellte_anzahl'];
}
foreach ($title as $einzeltitle) {
echo $einzelname['test_bestellte_groesse'];
}
foreach ($groesse as $einzelgroesse) {
echo $einzelgroesse['test_bestellte_artikel'];
}
Thanks in advance!
ANSWER
Answered 2021-Dec-09 at 14:53Assuming the three arrays are always keyed identically, use a single loop:
$arrayOne = array('a', 'b', 'c', 'd');
$arrayTwo = array('w', 'x', 'y', 'z');
$arrayThree = array('m', 'n', 'o', 'p');
foreach ($arrayOne as $key => $valueOne) {
$valueTwo = $arrayTwo[$key];
$valueThree = $arrayThree[$key];
// save your table row to database...
echo "key: $key one: $valueOne two: $valueTwo three: $valueThree
";
}
/* output:
key: 0 one: a two: w three: m
key: 1 one: b two: x three: n
key: 2 one: c two: y three: o
key: 3 one: d two: z three: p
*/
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lila
Compile the runtime: ``ant``
Install the dependencies: ``jruby -S gem install bitescript parslet``
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page