StackOverflow.com

VN:F [1.9.22_1171]
Rating: 9.4/10 (10 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

Mapping complex object in Automapper

27 April 2024 @ 2:32 am

The following are the Simple objects that works fine using Automapper: public class Source { public int Id {get;set;} public string Name {get;set;} } public class Destination { public int Id {get;set;} public string Name {get;set;} } SampleClass.cs using Automapper; public class SampleClass { private IMapper _mapper; public SampleClass(IMapper mapper) { _mapper = mapper; } public void Logic(Souce source) { var Dest = _mapper.Map<Destination>(source); } } The above mapping statement works fine and I see all the fields getting mapped from source to destination since it is a simple object . But my requirement is that, I have a complex object structure as follows : public class Source { public int Id {get;set;} public string Name {get;set;} public List<SourceChild> lstChild {get;set;} } public class SourceChild { public string Address{get;set;} } public class D

Using Node.js, fetching a webpage is different from on the browser

27 April 2024 @ 2:28 am

I am trying to use fetch on Node.js, to fetch the page: https://finance.yahoo.com/quote/META I can see on the browser it is at a price of $443.29 Also if I use view-source:https://finance.yahoo.com/quote/META on the browser and set Disable JavaScript to ON on Google Chrome's dev tool, I can see the following content: data-field="regularMarketPrice" data-trend="none" data-pricehint="2" data-value="443.29" active><span>443.29 However, if I do a fetch using Node.js, or even if I go to Chrome's dev tool and the Network tab, and reload the page, and then right click on the first network resource, and right click and choose Copy -> As Fetch (Node.js) I can get the equivalent of what Google Chrome used:

Django Ñ problem? ValueError: source code string cannot contain null bytes

27 April 2024 @ 2:28 am

I'm working on Django and connecting to a remote SQL Server database. I managed to make the connection to the database using the MSSQL engine, but when I run inspectdb, the generated file contains errors due to the character "Ñ", in the file they appear as ±. So when I try to run the server, I get the following error: ValueError: source code string cannot contain null bytes. refering to the generated file with inspectdb I suspect that the problem is related to the database encoded in Modern_Spanish_CI_AS and also Ñ character is causing trouble. So far, I've tried the following: In settings.py, in database options: 'unicode_results': True Also, 'extra_params': 'ClientCharset=utf8' Modifying in base.py: mssql: unicode_results = options.get('unicode_results', True) Some less elegant solutions like opening the generated file with Notepad and saving it in UTF-8 or ISO 885

Azure SQL - Private and Service Endpoints together

27 April 2024 @ 2:28 am

I have a requirement to configure both Private and Service endpoints on Azure SQL firewall. Here is a quick simulated scenario Scenario 1: Subnet1 of VNet 1 is configured with Azure SQL service endpoint and whitelisted in Azure SQL DB firewall (service endpoint). This allows VM1 to access the database without any issues. enter image description here Scenario 2: When I added a private endpoint from a different VNET (VNet2) to this Azure SQL DB to allow access from VM2 inside VNET 2, the existing connectivity between VM1 and DB is lost. enter image description here Is it because the addition of private endpoint to the SQL DB firewall allows all incoming connection to use

Is there a way I can use a getline string in some sort of if/case statement to get a specific line to be read from a txt file?

27 April 2024 @ 2:23 am

so im developing software for my brothers company, its just a little side project nothing really that major. This specific part of the software is meant to be able to let tenants put in an address, then put in a code, and it will then tell them what the house unlock code is. But Ive ran into an issue. I cant find a way where people would be able to put in the address, then have the software read the .txt file to the specific line with the house code and unlock code on it. #include <iostream> #include <string> #include <fstream> #include <sstream> #include <vector> void fileOP(std::ifstream& testdata, int linenumsought, std::string& address); int main() { std::ifstream testdata; testdata.open("testdata.txt"); int linenumsought; std::string address; std::cout << "Please enter address: "; std::getline(std::cin, address); fileOP(testdata, linenumsought, address);

AWS ECS mounting ca certificate to the container is it possible

27 April 2024 @ 2:23 am

to mount private ca certificates into the containers. In EKS we could mount secrets as files, but I’m not sure that’s possible in ECS. is it possible to mount a certificate to the ECS container .if so how can i achieve to do that using the terraform . can anyone please help me ? Not having the idea to carry out anything.

Why does synchronous code execute faster than asynchronous code

27 April 2024 @ 2:22 am

At present, I refactor the code in the project, because the code involves more database operations, so consider using asyncio, currently all database operations are implemented using asynchronous, and then test the original code (original code is synchronous) and asynchronous code, found that synchronous code is faster, why? About the difference between synchronous code and asynchronous code: operating database: synchronous code uses pymysql, asynchronous code uses aiomysql, asyncio; pandas was used for data calculation; The code logic is the same; The same computer; The same wifi; python version: synchronous code is 3.6, asynchronous code is 3.8; Django version: synchronous code is 3.2.25, asynchronous code is 4.2.11; Asynchronous code uses asynchronous views that Django supports, such as: @method_decorator(csrf_exempt, name='dispatch') class AsyncExampleView(View): async de

Using viridis Colormap For Matplotlib Plot Lines

27 April 2024 @ 2:22 am

I want to use the viridis colormap, yet it keeps reporting "AttributeError: Line2D.set() got an unexpected keyword argument 'cmap'". Here is what I attempted to do: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import numpy as np cmap = plt.get_cmap('viridis') df = pd.read_excel('c:\MET_Proj\WakeAngleAndSpatter.xlsm') fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 5)) axes[0].plot(df.iloc[3:20, 0], df.iloc[3:20, 1], label='Sample 1, 200W 200V', cmap='viridis') axes[0].set_xlabel('Length from start (mm)') axes[0].set_ylabel('Wake Angle (degrees)') axes[0].legend() axes[1].plot(df.iloc[3:20, 0], df.iloc[3:20, 2], label='Sample 1, 200W 200V', cmap='viridis') axes[1].set_xlabel('Length from start (mm)') axes[1].set_ylabel('Cumulative Spatters') axes[1].legend() norm = plt.Normalize(1.min(), 1.max()) line_colors = cmap(norm(1)) plt.show() If I remove any cmap related ar

How to get the tokenizer from ONNX export in Transformers.js

27 April 2024 @ 2:19 am

I have a bunch of checkpoints from cross-encoder/nli-deberta-v3-small and I was able to convert one to ONNX via the Transformer.js script as they recommend. Model link: https://huggingface.co/cross-encoder/nli-deberta-v3-small The goal is to use this as a rag re-ranker. Initially, I tried to use the pipeline to load the model, i.e.: pipeline("text-classification", model, { quantized: false }) - but that did not work - nor do I think the pipeline does the right thing for my task. This is what the exported ONNX dir looks like: enter image description here Next, I tried this (used the singleton pattern but I'm simplifying the code below): import { AutoModel,

How to determine a safe range of addresses to read from physical memory for 16gb of RAM?

27 April 2024 @ 2:11 am

I'm using RWEverything to read physical memory. It works fine, but if I try to read an address that is too big then it results in a BSOD. For example, 0x0000eef777340000 is going to BSOD me. How to calculate the maximum safe address to read from by knowing only my physical RAM size?