what does fileURLToPath(import.meta.url) do? - url

Okay so i was following a mern stack tutorial and the tutor wrote out some lines of code but didnt really explain them well. this is the code:
const path = require('path')
const {fileURLToPath} = require('url')
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use("/assets", express.static(path.join(__dirname, "public/assets")));
Now Im not stupid or a bad programmer. even though i dont really have an explanation for what the code is doing, i have a pretty good idea. the problem is that when i run my database, i get this error:
SyntaxError: Identifier '__filename' has already been declared
which is crazy because i havent used '__filename' anywhere else in the code. when i try to change '__filename' to 'filename' then i get this error:
SyntaxError: Cannot use 'import.meta' outside a module
Im so confused. Please can someone just tell me what the code does and why i am getting these errors and also how to fix the errors.

check your package.json() if it is having a
"type":"module"
if it has then remove it

Related

applying MSDDetector in colab

I have trouble writing the MSD detector correctly. However, it has no attribute ''create''.
I wrote the following code. But my session crashed for an unknown reason.
msd=cv2.xfeatures2d.MSDDetector()
kps1=msd.detect(I1)
I will appreciate any help.
unfortunately, you've found a bug here.
there should be a ´XXX_create()´ function, but someone forgot to expose it to the python api, by adding a CV_WRAP to the function signature here
(and no, you cannot use the 'ordinary' constructor, it does not produce a valid instance (will segfault, if you call any method on it !!))
please raise an issue here
if you're able to build from src, try to fix it locally, by changing that line to:
CV_WRAP static Ptr<MSDDetector> create(....

Syntax error in library code when including matrial design using Rails + Webpacker + Typescript + Angular

In my rails app, I get a syntax error somewhere in a huge js file that is presumably generated by webpacker. But it seems to be some sort of angular/material code. If I don't include material design, the error goes away, so it seems to be related to material design. This is the part that causes the syntax error:
function instantiateSupportedAnimationDriver() {
return !(function webpackMissingModule() { var e = new Error("Cannot find module '#angular/animations/browser'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())() ? new !(function webpackMissingModule() { var e = new Error("Cannot find module '#angular/animations/browser'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())() : new !(function webpackMissingModule() { var e = new Error("Cannot find module '#angular/animations/browser'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();
}
Note that telling me how to fix the syntax error doesn't help me. This code is not in my control and I wouldn't know how to effectively patch it. Besides, it's a frequently used piece of code, I doubt that it has a syntax error, probably something in plumbing is incorrect.
Some context: I probably don't get all the mechanics right. I am trying to make the combination Rails + Webpacker + Typescript + Angular + Material work. It's quite tricky, I find nothing useful on it on the web and I seem to be pretty much the first one to do it. I saw some suggestions to make an api-only rails app, but I don't like that...
I never really figured out why this caused a syntax error in a seemingly unrelated file, but I had some "unmet peer dependency" warnings and when I fixed them, this went away.

ROBLOX Lua Error in script: '=' expected near '<eof>'

Hello I am writing a scipt on ROBLOX and I have encountered a problem.
function showVictoryMessage(playerName)
local message = Instance.new("Message")
message.Text = playerName .." has won!"
message.Parent = game.Workspace
wait (2)
message.Destroy()
end
Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script: '=' expected near '< eof >'
I have never seen this error before, and the ROBLOX wiki page on Lua errors doesn't mention it.
I would very much appreciate help in this, because I don't personally know anyone who has coded in Lua.
Looks like a syntax error. message.Destroy() should be message:Destroy() according to this Roblox wiki page http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy
Also see the section Explosions, Messages, and More at URL http://wiki.roblox.com/index.php?title=Basic_Scripting which provides similar syntax using the colon (:) operator.
See also Difference between . and : in Lua and explanation of "possible side-effects of calculations/access are calculated only once" with colon notation.
Instead of message.Destroy() it should be message:Destroy()
Remember that '.' are used directory-wise and ":' are used for inbuilt functions.
WOOOOOOOO! It was a syntax error. The correct command is message:Destroy. Cause why would object.Destroy work and message.Destroy not?

Why does Corona give an error loading code that loads fine with lua?

I'm having problems with a specific line of code - building.transmitter:[operation](player, unpack({...})) that causes an error in Corona, yet this loads fine when it's run in Lua separately. I suspect it has something to do with the : being placed before the [operation] variable but I'm clueless why.
Specifically the module is written as,
local activate = {}
local function activate.transmitter(player, operation, ...)
building = player:getTile()
building.transmitter:[operation](player, unpack({...}))
end
return activate
The runtime errror that is appearing gives me
"error loading module from file, '<name>' expected near '['"
Edit - WOW! I didn't notice that when troubleshooting this in Corona I changed some of the lines of code to identify the problem. I then mistakenly tested the edited code in Lua and it ran fine. I didn't realize the code wasn't the original until siffiejoe pointed out the interpreter getting an error as well. Sorry for the mistake.
maybe Corona uses older version of Lua which does not support this syntax. You can try workaround instead of
building.transmitter:[operation](player, unpack({...}));
you can call
building.transmitter[operation](building.transmitter, player, unpack({...}));

cpSpaceHashEach - 2 problems at the same line

I'm trying to grasp basics of Chipmunk. In some tutorial I found a line:
cpSpaceHashEach(space->activeShapes, &updateShape, nil);
But I get 2 mistakes here:
1) Implicit declaration of function is invalid in C99
2) No member named 'activeShapes' in 'struct cpSpace'
What is wrong? Why doesn't it work? Do I need to include something else?
Just to clarify with some code in case anyone else runs into this problem, instead of
cpSpaceHashEach(space->activeShapes, &updateShape, nil);
you'd use:
cpSpaceEachShape(space, &updateShape, nil);
Apparently this change was done so it is easier to keep the code future-proof since the activeShapes were not meant to be used in this way.
Digging into the changelog: (https://github.com/slembcke/Chipmunk-Physics/blob/master/VERSION.txt)
If you look, you'll find that in Chipmunk 5.x cpSpace.*Shapes were marked as private members of the cpSpace struct in the header. Then, in Chipmunk 6.x, private access was disabled by default and a cpSpaceEachShape() function appeared that almost exactly replaced cpSpaceHashEach() + cpSpace.activeShapes that you are trying to do.

Resources