oddities | Simulation of convoy of self-driving cars
kandi X-RAY | oddities Summary
kandi X-RAY | oddities Summary
Simulation of convoy of self-driving cars.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of oddities
oddities Key Features
oddities Examples and Code Snippets
Community Discussions
Trending Discussions on oddities
QUESTION
I'm trying to figure out what dictates if a value is returned from a PowerShell function or not, and I've run into some oddities. The about_return docs say:
In PowerShell, the results of each statement are returned as output, even without a statement that contains the Return keyword.
But this seems to glaze over details. If I run this:
...ANSWER
Answered 2022-Feb-07 at 21:09This section discusses the specific statements from your sample functions.
See the bottom section for background information.
$n = 1
and$n++
are assignments and therefore do not produce output.$n
is an expression whose value is output$null
- ditto, but even though it is output, it doesn't display by default($n++)
- due to enclosure in(...)
- turns the assignment into an expression and therefore does output the assigned value (too).- However, because you've used the post-increment form of the assignment, it is the old value that is output, not the now incremented value; to increment first (pre-increment) and then output, use
(++$n)
- However, because you've used the post-increment form of the assignment, it is the old value that is output, not the now incremented value; to increment first (pre-increment) and then output, use
[System.Console]::WriteLine("Hello")
prints directly to the console, which bypasses PowerShell's system of output streams.- This means you cannot capture or redirect such output from inside PowerShell (see the next section).
Tip of the hat to iRon for his help.
PowerShell, following the model of traditional shells, is organized around streams - see the conceptual about_Redirection help topic for an overview of all 6 streams that PowerShell supports.[1]
That is, any statement - and therefore potentially multiple ones - in a script or function can write to any of the output streams.
The primary output stream, meant to convey data, is the success output stream (whose number is 1
), and only it is sent through the pipeline by default, and therefore by default only it is captured in a variable, suppressed, or redirected to a file.
There are two ways to write to the success output stream, i.e. to produce data output:
Explicitly, with a
Write-Output
call - although that is rarely needed.Typically implicitly, by neither capturing, suppressing, nor redirecting output produced by a statement.
In other words: Output from any command (e.g.,
Get-ChildItem *.txt
) or expression (e.g,1 + 2
or(42).ToString('x')
) is sent to the success output stream by default.Unlike in traditional programming languages,
return
is not needed to produce output - in fact, its primary purpose is to exit the enclosing scope independently of any output the scope produces, though as a syntactic convenience you can combine the two aspects:return
is in effect the same as the following two statements, the first of which (potentially) produces output, the second of which exits the scope:; return
This implicit output behavior is convenient and and allows for concise, expressive code, but can also be a pitfall: it is easy to accidentally produce output - typically from a .NET method whose return value isn't needed (see this question for an example).
iRon's GitHub feature request #15781 discusses one potential way to remedy this problem: introduction of an opt-in strict mode that only permits using explicit output statements (
Write-Output
,return
) in order to produce output.This answer shows troubleshooting techniques you can use with the currently available features.
As for assignments - e.g. $n = 1; $n += 1; ++$n; $n--
:
- By default they do not produce output.
- A hybrid case is the chaining form of a multi-assignment, e.g.
$a = $b = 1
, which assigns1
to both variables: statement-internally the assignment value is passed through, but the statement as a whole has no output.
- A hybrid case is the chaining form of a multi-assignment, e.g.
- However, as an opt-in you can make them pass the value(s) being assigned through via
(...)
, the grouping operator; e.g.($n = 1)
both assigns1
to variable$n
and outputs1
, which allows it to participate in larger expressions, such as($n = 1) -gt 0
- Note that the related
$(...)
(subexpression operator) and@(...)
(array-subexpression operator) do not have that effect - they wrap one or more entire statement(s), without affecting the enclosed statements' intrinsic output behavior; e.g.$($n = 1)
does not produce output, because$n = 1
by itself doesn't produce output; however,$(($n = 1))
does, because($n = 1)
by itself does.
- Note that the related
As for output enumeration behavior:
By default, PowerShell enumerates collections that are being output, in the spirit of streaming output: That is, it sends a collection's elements to the pipeline, one by one.
In the rare event that you do need to output a collection as a whole - which in general should be avoided, so as not to confound other commands participating in a pipeline, which usually do expect object-by-object input - you have two options:
, $collection
(sic; uses an aux. one-element wrapper array)- More explicitly, but less efficiently:
Write-Output -NoEnumerate $collection
- See this answer for more information.
As for outputting $null
:
$null
is output to the pipeline, but by default doesn't show.$null
by itself produces no visible output,but the following returns
$true
, demonstrating that the value was sent:
QUESTION
I am getting the current time from an NTP server. The reference epoch of NTP is 0:00:00.000 on 1 January 1900 and the library I use for NTP returns the number of seconds that elapsed since that reference epoch. As you can see, it works similarily to Unix time, except that it uses a different reference epoch. My goal is therefore to convert this NTP timestamp to a unix timestamp, while avoiding all those weird things like leap years, leap seconds and all those other weird things that humans did to their time scale.
The naive approach would obviously be to calculate the number of seconds that happened between the NTP reference epoch and the Unix reference epoch, store that as a constant and subtract that from the NTP timestamp, but I have a feeling that I would be too stupid for that and forget some of the aforementioned oddities. My question is therefore whether Python has some built-in function or whether there's a library to do just that.
...ANSWER
Answered 2022-Feb-01 at 18:26The ntplib python library converts the NTP timestamp to/from Unix time as seconds since 1-Jan-1970.
QUESTION
Python 3.9
I have a numpy ndarray of strings. The actual array has thousands of strings, but let's say:
...ANSWER
Answered 2022-Jan-18 at 18:01import numpy as np
words_master = np.array(['CARES', 'BARES', 'CANES', 'TARES', 'PARES', 'BANES', 'BALES', 'CORES', 'BORES', 'MARES']
QUESTION
I have a parquet
folder created with dask
containing multiple files of about 100MB each. When I load the dataframe with df = dask.dataframe.read_parquet(path_to_parquet_folder)
, and run any sort of computation (such as df.describe().compute()
), my kernel crashes.
Things I have noticed:
- CPU usage (about 100%) indicates that multithreading is not used
- memory usage shoots way past the size of a single file
- the kernel crashes after system memory usage approaches 100%
I tried to create a reproducible example, without success, but I discovered some other oddities, seemingly all related to the newer pandas
dtypes that I'm using:
ANSWER
Answered 2021-Dec-17 at 05:28It seems the main error is due to NAType
which is not yet fully supported by numpy
(version 1.21.4
):
QUESTION
I'm on a team that's working on a number of disease modeling efforts, and we're wanting to collect historical weekly influenza data from the WHO on a number of countries. The data are nominally available at https://apps.who.int/flumart/Default?ReportNo=12, but the website and underlying API are built in a really strange way that make it difficult to scrape.
I am aware of https://github.com/mobinalhassan/WHO-Data-Downloader, which is some nice open source code that's written to collect the data, but it uses Selenium, and I'm hoping to avoid Selenium and just use pure requests since Selenium can be kind of a pain to setup.
The WHO FluMart websiteThe WHO FluMart website first shows a simple form that allows a user to select 1 or more countries and a time frame of interest, and when the user hits the "Display report" button, the website queries a backend to show data in a table. Depending on the query, it can take 10-30+ seconds for the query to return. Here's a screenshot:
My goal is to collect the data shown in this table for a number of countries.
API oddities (AFAIK)When a user fills out the form at the top and hits "Display report", a POST
request is submitted to https://apps.who.int/flumart/Default?ReportNo=12 that includes the obvious data, as well as some not-obvious data. Here's an example from the above screenshot:
ANSWER
Answered 2022-Jan-06 at 01:28There are a couple complexities that occur when scraping this site:
- In order to get the actual data from a request to the site's endpoint, the entire headers of the original browser's request must be sent, containing in particular the user agent and cookies.
- The
data
payload of thePOST
request should be encoded as it is displayed in the browser's developer network settings.
QUESTION
I'm trying to get a feel for how well a surface fits my data points by graphing everything and rotating the surface around to check for any oddities in the surface behavior relative to the scattered point in 3d space.
The problem is that when I rotate the render to do this, the plots disappear. How can I make the plots persist?
You can repro with the below code - mainly taken from the amazing answers at Python 3D polynomial surface fit, order dependent.
...ANSWER
Answered 2021-Dec-30 at 04:25A simple thing you can do is setting the transparency of your surface to a lower value than your scatter plot. See example below where I used a transparency value equal to 0.4 with the line ax.plot_surface(xx, yy, zz, zorder=10,alpha=0.4)
.
And the output gives:
QUESTION
I want to create a large lookup table of key value pairs, attempting it like this:
...ANSWER
Answered 2021-Nov-21 at 07:16This github issue pointed out by @technocrat talks about a known bug in earlier versions of RStudio of disabling null external pointer checks, and has since been solved by adding an additional preference check in .rs.describeObject()
of
QUESTION
I'm trying to deploy a .NET Core 3.1 Azure App Service on Linux using a Bicep template from Azure CLI. The app service and corresponding app service plan are deployed correctly but the app service stack settings are empty on the Azure portal and I have to set these manually. I tried setting the metadata property on the 'Microsoft.Web/sites' resource and also on the 'Microsoft.Web/sites/config' resource, but the result was the same.
This is my app service plan:
...ANSWER
Answered 2021-Nov-09 at 18:04The Metadata parameter is not available anymore in the SiteConfig
. The stack setting can be mentioned LinuxFxVersion
.
So, solution will be Instead of using dotnet|3.1
, You should use DOTNETCORE|3.1
.The over all code will be as below:
QUESTION
I was inspecting the memory maps of a Python process on a Linux system and found something very surprising. Normally, when I inspect the maps for a Python process they look like this:
...ANSWER
Answered 2021-Nov-03 at 11:51Do you know what can cause this effect or in what conditions this can happen?
An executable can trivially mmap
(parts of) itself. This could be done to e.g. examine its own symbol table (necessary to print crash stack trace), or to extract some embedded resource.
The maps for the executable (python3.9) appear first and the map for a shared library that is opened appear after the ones in the executable.
This is only true by accident, and only for non-PIE executables.
Non-PIE executables on x86_64
are traditionally linked to load at address 0x400000
, and the shared libraries are normally loaded starting from below the main stack.
If you link a non-PIE executable to load at e.g. 0x7ff000000000
, then it will likely appear in the /proc/$pid/maps
after shared libraries.
Update:
the python binary here is certainly not mmapping itself, so that explanation doesn't apply
- You can't know that -- you almost certainly haven't read all the code in Python 3.9 and every module which you load.
- There is no need to guess where these
mmap
ed regions are coming from, you can just look.
To look, run your program under GDB and use catch syscall mmap
followed by where
. This will allow you to see where each and every mapping came from.
QUESTION
I like the fp
method for collecting call stacks with perf record
since it's lightweight and less complex than dwarf
. However, when I look at the call stacks/flamegraphs I get when a program uses the C++ standard library, they are not correct.
Here is a test program:
...ANSWER
Answered 2021-Jul-06 at 13:04With your code, 20.04 x86_64 ubuntu, perf record --call-graph fp
with and without -e cycles:u
I have similar flamegraph as viewed with https://speedscope.app (prepare data with perf script > out.txt
and select out.txt in the webapp).
Is it possible to get correct fp call stacks with libstdc++ without compiling it myself (which seems like a lot of work)?
No, call-graph method 'fp' is implemented in linux kernel code in very simple way: https://elixir.bootlin.com/linux/v5.4/C/ident/perf_callchain_user - https://elixir.bootlin.com/linux/v5.4/source/arch/x86/events/core.c#L2464
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install oddities
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page