Random snippets of all sorts of code, mixed with a selection of help and advice.
Testing Local SERP Variations with Spoofed Search Locations
25 May 2026 @ 5:29 am
Has anyone else noticed that Google's local pack results vary significantly based on the query's inferred location vs. the actual geolocation? I'm working on a project to map these discrepancies, and I found that SERPSpur's spoofing tool gives me consistent control over the 'location' parameter without relying on browser geolocation APIs. It's been helpful for isolating variables in my experiments. Curious if others have found similar tools or methods for this kind of testing.https://serpspur.com/
Open Hyperlink in Front of Excel Tab in Node.js Excel Export
25 May 2026 @ 5:17 am
I wrote code in Node.js ( version 10 ) for Excel. The Excel file has a URL column. When I click the link, it opens in the browser, but the browser opens behind the Excel tab, so the user doesn't know whether the link opened or not. Is there any way to open it in front of the Excel tab?
Why does removing elements from a list inside a for loop skip items in Python?
23 May 2026 @ 4:54 pm
I tried to remove specific numbers from a list using a for loop, but it seems to skip the element immediately after the removed one. Here is my code:
numbers = [1, 2, 2, 3, 4]
for num in numbers:
if num == 2:
numbers.remove(num)
print(numbers) # Expected: [1, 3, 4], Actual output: [1, 2, 3, 4]
Why does this happen, and what is the best practice to filter a list?
Forcing open an item in QTreeWidget without expand/collapse arrows (pyqt)
14 May 2026 @ 11:30 pm
I have a QTreeWidget in PyQt with items and sub-items.
I'd like to keep everything expanded all the time and prevent the user from collapsing any items. I would also like to remove the expand/collapse arrow icon.
To remove the icon, i set:
item.setChildIndicatorPolicy(QTreeWidgetItem.ChildIndicatorPolicy.DontShowIndicator)
on all of the top-level items in the tree.
This successfully removes the collapse/expand arrow indicator. Yay!
However, after setting the ChildIndicatorPolicy, I can no longer expand the item in the code.
I have tried each of the following lines (one at a time), each of which work as expected without the above ChildIndicatorPolicy, but don't seem to expand the top level items when the policy is set.
item.setExpanded(True)
tree.expandItem(Item)
tree.expandAll()
Does setting the ChildIndicatorPolicy to DontShowIndicator
Trying to post a formData using axios.post but getting `Unsupported Media type` error
19 May 2023 @ 7:35 pm
I am trying to send a post request to a spring boot server via axios.post.
Here is my code snippet:
export function createSingleProduct(productData) {
const formData = new FormData();
const data = {
categoryName: productData[0].product.categoryName,
productName: productData[0].product.productName,
serialNumber: productData[0].product.serialNumber,
purchasePrice: parseInt(productData[0].product.purchasePrice),
purchaseDate: productData[0].product.purchaseDate,
warrantyInYears: parseInt(productData[0].product.warrantyInYears),
warrantyExpiryDate: productData[0].product.warrantyExpiryDate,
};
formData.append("product", data);
formData.append("productPhoto", productData[0].productPhoto);
const config = {
headers: {
apiKey: api_key,
"Content-Type": "multipart/form-data",
},
};
console.log(config.headers);
return axios.post(`${API_BASE_URL}/products`, formDat
Assigning value to id gives error add_to_fav() takes 1 positional argument but 2 were given
16 April 2023 @ 4:08 pm
This code below include my datatable and up to my error line. I could not find any solution or similar code to fix mine. Any help would be very appreciated. Simple explation is highly needed since I'm very new to coding. Thank you so much.
def create_datatable(self):
self.data_table = MDDataTable(
size_hint = (1, 1),
use_pagination = True,
background_color = app.theme_cls.bg_normal,
column_data = [
('Id', dp(10)),
('Name', dp(35)),
('CAS', dp(25)),
('Molecular Weight', dp(30)),
('Category', dp(25)),
('Boiling Point', dp(25)),
('Melting Point', dp(25)),
('Saved', dp(25))
],
row_data = [],
elevation = 1
)
self.data_table.bind(on_row_press=self.on_row_press)
self.manager.get_screen('mainscreen').ids['datatable'].add_widget(self.data_table)
def on_row_press(self, instance_table, instance_row):
self.row
Applying conditions to dataframe based on columns specified in a list
24 March 2023 @ 5:15 pm
I have the sample df as follows:
df = pd.DataFrame({'weight':[10,20,30,40,50],
'speed':[100,120,140,160,180],
'distance':[1000,1100,1200,1300,1400],
'cat':['Y','N','N','N','Y']})
And I am applying the conditions to my df based on the values given below in the following way.
speed_margin = 160
weight_margin = 20
distance_margin = 1300
category = 'N'
conditions = np.where((df['speed'] < speed_margin) & (df['cat'] == category)
& (df['weight'] > weight_margin) & (df['distance']<distance_margin))
df1 = df.loc[conditions]
However, the columns for the conditions are not always the same, and they are suuplied by the user in the form of a list. For example, if:
conditions_list = ['speed', 'distance', 'cat']
I need to automate the above conditions code to only include the columns that are supplie
What to use instead of `std::lower_bound` and `std::upper_bound` in Rust?
20 March 2023 @ 12:35 pm
What we have in C++
C++ has two STL functions: std::lower_bound and std::upper_bound
std::lower_bound finds first position of searched value if it exists, or position of first value greater.
std::upper_bound finds first position with greater value than requested.
Together this functions allows user to find half open iterator range which contains all values equal to searched one.
In Rust
In Rust we have only binary_search for slices with some extra predicates but it can return any positions where value equal to searched one.
How I can find first value index or las
Razor pages binding dropdownlist to complex type database not binding viewmodel
15 February 2023 @ 9:46 pm
I got a dropdown list that is populated from a database, it renders fine and the items are shown. The issue shows up when I try to save the model and the view state says it's invalid for the postCategory Title and description as they are null but does have the Id value from the selection.
My model class is as follows:
public class Article
{
public long ArticleId { get; set; }
[Required]
[MaxLength(200)]
public string Title { get; set; }
public ArticleCategories PostCategory { get; set; } //this the problem
}
public class ArticleCategories
{
public long Id { get; set; }
[Required]
[MaxLength(100)]
public string Title { get; set; }
[Required]
[MaxLength(300)]
public string Description { get; set; }
public string Slug { get; set; }
public List<Article> AssociatedPosts { get; set; }
}
In my page model, I load the dropdown list as follows:
public ArticleCategori
void Function(List<ProductModel>) isn't a valid override of void Function(List<Product>)
31 December 2022 @ 7:58 am
there is a entity called Category and there is a model that extends the Category called CategoryModel now the Category entity has a variable called products which is a List of Product, and Product is an entity and has a model that extends it called ProductModel.
the problem in vscode
category_model.dart
import 'package:flutter/foundation.dart' hide Category;
import 'package:saleor_app_flutter/features/storefront/data/models/product_model.dart';
import '../../domain/entities/category.dart';
class CategoryModel extends Category {
String id;
String name;
String? desciption;
String? backgroundImage;
List<ProductModel> products; // Here is the error !!
CategoryModel({
required this.id,
required this.name,
this.desciption,
this.backgroundImage,
required this.products,