Random snippets of all sorts of code, mixed with a selection of help and advice.
ajax array insert into database without page reload
29 May 2026 @ 9:57 pm
I'm trying to insert product_name, product_quantity and price into a database via ajax and php.
This is my code so far. It does work with product name but I can't get it working including product price and quantity for each one of the product names .
This code is throwing the error
console.error('Fetch error:', error);
$jsonInput = file_get_contents('php://input');
$decodedData = json_decode($jsonInput, true);
if (!isset($decodedData['items']) || !is_array($decodedData['items'])) {
echo json_encode(['status' => 'error', 'message' => 'Invalid or missing array data']);
exit;
}
$itemsArray = $decodedData['items'];
// 3. Prepare SQL query to prevent SQL Injection
$stmt = $conn->prepare("INSERT INTO shopping_carts_quotes (product_name) VALUES (?)");
In R: How to deduplicate (based on two identical columns) and merge the remaining columns into a single row for a large dataframe?
29 May 2026 @ 9:53 pm
Example data:
ID<-c("A","A","A","A","A","A","B","B","B")
HFAdmission<-c("2020-01-01", "2020-02-01", "2020-03-01", NA, NA, NA, "2020-06-01", "2020-07-01", NA)
link_type<-c("Linked", "HF only", "HF only", "HES only", "HES only", "HES only", "Linked", "HF only", "HES only")
ADMIDATE<-c(NA,NA,NA,"2020-03-01","2020-04-01","2020-05-01",NA,NA, "2020-07-01")
newdate<-c(NA, "2020-02-01", "2020-03-01", "2020-03-01","2020-04-01","2020-05-01", NA, "2020-07-01", "2020-07-01")
df<-data.frame(ID, HFAdmission,link_type,ADMIDATE,newdate)
as.Date(df$HFAdmission)
as.Date(df$ADMIDATE)
as.Date(df$newdate)
df should look
Previous Day Low Breakout Extended Line
29 May 2026 @ 9:52 pm
“I have marked the Previous Day Low line. Now, on any timeframe, if any candle breaks that low line, I want to draw a new horizontal line at the low of that breakout candle. The new line should extend only to the right side, and only the first breakout candle should be marked — not every candle below the level.”
How can I avoid using LLMs as a software developer?
29 May 2026 @ 9:39 pm
Introduction
I've been developing software very successfully for many years. The reason I have chosen this profession is multifold:
I'm a creative person and I need to create things
I have an insatiable drive to think
Financial compensation one may expect for doing this
I can do my thing without constantly socializing with superficial small-talk
The drive to solve real-world problems and to be a force for the better
To work from home
It has been a great ride to do this and I achieved quite a lot of things. Yet, the industry gradually deteriorated. I do know that sometimes libraries and APIs are needed, but I witnessed too many times the drive to use some library only to solve some problem we could have otherwise easily solved, which to me meant that the specific decision was "going with the vibes" rather than a rational choice. Sure thing, there
Compose Multiplatform iOS: Can ComposeUIViewController provide intrinsic content size to SwiftUI UIViewControllerRepresentable?
29 May 2026 @ 9:29 pm
I'm using Compose Multiplatform on iOS and embedding a ComposeUIViewController inside SwiftUI.
My hierarchy is:
SwiftUI ScrollView
└── UIViewControllerRepresentable
└── ComposeUIViewController
Example :
struct ComposeContainer: UIViewControllerRepresentable {
let factory: () -> UIViewController
func makeUIViewController(context: Context) -> UIViewController {
factory()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
ScrollView {
ComposeContainer {
Main_iosKt.ChatViewController()
}
.fixedSize(horizontal: false, vertical: true)
}
The ComposeUIViewController is created like this:
fun buildComposeViewController(
content: @Composable () -> Unit
): UIViewController =
ComposeUIViewController {
content()
}
When inspecting the
Сomma-separated sequence of declarators in C89
29 May 2026 @ 8:30 pm
What does C89 standard say about the order of evaluation of expressions in a comma-separated sequence of declarators with initializers? I did not find the answer in the "Declarations" section, nor in "Initialization", nor in "Program execution". I just found that there are sequence points in the end of expressions in initializers (Annex C). For example:
int t = 1;
void block (void)
{
int a = (t *= 2), b = (t *= 3);
/* Is it guaranteed that a==2 and b==6 ? */
}
Getting GPS points to show up on plot
29 May 2026 @ 8:12 pm
I'm trying to make an animation of animal movements using the Seabird Tracking Animation Exercise (RPubs - gganimate tutorial) to help my own data. However when I go to plot the map my points do not show up. My basemap extent is set to the correct extent but the basemap that shows up is not correct. Any suggestions as to what might be going wrong?
For context, I'm using my own data to make a visualization of an individual animal's movements that show movement to the same breeding area year over year.
I expect the points from my df to show up on the map extent but nothing shows up.
Map extent it gives me:
xmin ymin xmax ymax
-93.10445 30.96946 -93.00416 31.04072
map_bbox25 <- map_extent25
map_bbox26 <- map_extent26
map_bbox25 <- c (left=-93.2, bottom=30.9, right= -92.9, top=31.1)
map_bbox26 <- c (left=-93.2, bottom=30.
Is there any other ways to convert a MapEntry to Map?
29 May 2026 @ 7:39 pm
I'm a beginner at Dart and I was doing a DSA problem to find the frequency of numbers in a list. And I have created a map with numbers as keys and frequencies of that number as its value. And then finally, I want to return the highest frequent number and its frequency as a Map. Here is my function code.
MapEntry<int, int> findMostFrequent(List<int> numbers) {
final frequency = <int, int>{};
//count logic here
for (int i = 0; i < numbers.length; i++) {
// frequency.update(numbers[i], (number) => number + 1, ifAbsent: () => 1); //here is the one lined version
//here is the full logic
if (!frequency.containsKey(numbers[i])) {
frequency[numbers[i]] = 1;
} else {
frequency[numbers[i]] = frequency[numbers[i]]! + 1;
}
}
return frequency.entries.reduce((a, b) {
final aValue = a.value;
final bValue = b.value;
if (aValue == bValue) {
return a.key > b
Is it possible to make a string array using malloc/calloc in c++?
29 May 2026 @ 7:27 pm
So, i have this assignment that requires me making dynamic arrays, the thing is that one of those arrays needs to be an array of structs, and the struct that it needs has strings, but also i cannot use new or delete meaning i need to use calloc, it looks kinda like this:
#include <iostream>
#include <string>
using namespace std;
struct person{
string name;
string post;
int age;
char accessLvl;
};
int main(){
int members = 2;
person *guard = (person*)malloc( sizeof(person)* members);
cout<<"How many guards are active: "<<endl;
cin>>members;
person *temp = (person*)realloc(guard, sizeof(person)*members);
if(temp == NULL){
free(guard);
return 1;
}
guard = temp;
for(int i = 0; i < members; i++){
cout<<"\nname: ";
getline(cin, guard[i].name);
cout<<"post: ";
getline(cin, guard[i].post);
Can I use the LLVM linker (or related tool) to embed the data from a file into an object file?
29 May 2026 @ 7:09 pm
Using the GNU linker, it is possible to embed the contents of a file into an object file (and eventually, an executable). For example, suppose my input is foo.bin and I want an object file named bar.o; I would write:
ld --format binary --relocatable -o bar.o foo.bin
(discussed in more detail in this question). Is it possible to do this with the LLVM linker? Or a related LLVM tool? If so, how? And if not - is that a real deficiency, or is it just that GNU ld is very "flexible" in what it's willing to do for you?
Note: I'm mainly concerned with GNU/Linux systems, where the executable format is ELF.