settings.json: parse error reading settings file - meteor

This is my json in the settings.json file:
{ "public": { "Name": "yashwanth" }, "private": { "oAuth": {
"linkedin": { "clientId": "", "secret": "" } } } }
And when I run my app
meteor --settings settings.json
the console says
While preparing to run: settings.json: parse error reading settings
file

I know its an old post but I am answering it just in case anyone encounters this issue. It turns out that it all boils down to the encoding of the file. If the file contains some invalid characters (as in not properly encoded) then meteor complains and you won't be able to parse the file successfully. A really simple workaround to this problem is to copy and paste the 'package.json' located in the root folder to the same folder and rename it to 'settings.json'. You can then edit this file manually by typing in the desired contents. Another thing you should always avoid is to use single quotes. You should avoid using single quotes for name/value pairs and you should always use double ones. A good website for json validation is JSONLint as it will identify any syntax errors you might have. Finally, it is worth noting that Notepad++ should not have any issues saving the file in the desired format. Make sure you use UTF-8 for the encoding.
Hope this helps anyone reading this and having the same problem.
Cheers

Parse error occurs if you have an invalid json string in your settings.json.
The content of your settings.json seems to be valid however, it is possible that
your file contains hidden chars (like UTF byte order mark) possibly because of copy / paste.
Remove the file and recreate it with an editor so that you are sure json has no hidden chars.

After investigating thoroughly, I found out the encoding of the json is the one causing issues. It was saved in UTF-8-BOM, changing it to UTF-8 solved the issues.

Related

Vscode settings problems

So I'm editing my settings in JSON and it all works well but this error keeps popping up:
"Expected comma jsonc(514)"
This is my code:
"css.lint.emptyRules": "ignore",
This is the whole json file just in case:
Whole Json file
You are missing a comma after the "gitlens.advanced.messages" object and before "css.lint.emptyRules": "ignore". That should solve your issue, also I highly advise you to take a look here JSON Syntax

Running Go from the command line nested JSON

I can think of workarounds on how to get this working however I'm interested in finding out if there's a solution to this specific problem.
I've got a go program which requires a json string arguement:
go run main.go "{ \"field\" : \"value\" }"
No problems so far. However, am I able to run from the command line if one of the json values is another json string?
go run main.go "{ \"json-string\" : \"{\"nestedfield\" : \"nestedvalue\"}\" }"
It would seem that adding escape characters incorrectly matches up the opening and closing quotes. Am I minuderstanding how this is done or is it (and this is the side I'm coming down on) simply not possible?
To reiterate, this is a question that has piqued my curiosity - I'm aware of alternative approaches - I'm hoping for input related to this specific problem.
Why don't you just put your json config to the file and provide config file name to your application using flag package
Based on the feedback from wiredeye I went down the argument route instead. I've modified the program to run on:
go run main.go field:value field2:value json-string:"{\"nestedfield\":nestedvalue}"
I can then iterate over the os.Args and get the nested json within my program. I'm not using flags directly as I don't know the amount of inputs into the program which would have required me to use duplicate flags (not supported) or parse the flag to a collection (doesn't seem to be supported).
Thanks wiredeye

Overwrite an existing file programmatically

I have a QDialogBox where there is an option to upload a file.
I can upload files and save them to a folder. It works fine.
But if in case there is a file that already exists in the folder, I am not sure how to handle that scenario.
I want to warn the user that the file with same name already exists.
Is there a Windows API that I can use in this case? (because when we manually save an existing file, we get a warning, how can I use that?)
If someone can point me to that documentation, it will be great.
If you are using a QFileDialog, confirmOverwrite is activated by default, so, if getSaveFileName() returned a non-empty QString, then that means the user accepted to overwrite the file. Other way, you get an empty QString.
Then, you can check if the file exists, and remove it in that case, but you know that the user was Ok with that.
There is always a potential race condition when saving files. Checking to see if the file exists first is not safe, because some other process could create a file with the same name in between the check and when you actually write the file.
To avoid problems, the file must be opened with exclusive access, and in such a way that it immediately fails if it already exists.
If you want to do things properly, take a look at these two answers:
How do I create a file in python without overwriting an existing
file
Safely create a file if and only if it does not exist with
python
You can use QDir::entryList() to get the file names in a directory if you're not using a QFileDialog.
QDir dir("/path/to/directory");
QStringList fileNames = dir.entryList();
Then iterating through file names, you can see if there's a file with the same name. If you need it, I can give an example for that too. It'd be C++, but easily adaptable to Python.
Edit: Smasho just suggested that using QDir::exists() method. You can check if the file name exists in the directory with this method instead of iterating like I suggested.
if(dir.exists(uploadedFileName))

Getting extension of the file in FileUpload Control

At the moment i get file extension of the file like :
string fileExt = System.IO.Path.GetExtension(filUpload.FileName);
But if the user change the file extension of the file ( for example user could rename "test.txt" to "test.jpg" ), I can't get the real extension . What's the solution ?
You seem to be asking if you can identify file-type from its content.
Most solutions will indeed attempt the file extension, but there are too many different possible file types to be reliably identifiable.
Most approaches use the first several bytes of the file to determine what they are.
Here is one list, here another.
If you are only worried about text vs binary, see this SO question and answers.
See this SO answer for checking if a file is a JPG - this approach can be extended to use other file headers as in the first two links in this answer.
Whatever the user renames the file extension to, that is the real file extension.
You should never depend on the file extension to tell you what's in the file, since it can be renamed.
See "how can we check file types before uploading them in asp.net?"
There's no way to get the 'real' file extension - the file extension that you get from the filename is the real one. If file content is your concern, you can retrieve the content type using the .ContentType property and verify that it is a content type that you are expecting - eg. image/jpg.

imagemagick with foreign characters

ImageMagick doesnt seem to work with foreign characters. I use the following code
It works fine until a letter in the path or the file has a foreign character. How do i convert images to thumbs on my asp.net site? Is there a plug in or another app or version i may use?
Process app = new Process();
app.StartInfo.FileName = #"bin\convert.exe";
app.StartInfo.Arguments = string.Format(#"""{0}"" -resize ""{2}"" ""{1}""", file, newfile, param);
app.Start();
app.WaitForExit();
I would change the name of the file. You probably want to be doing some conversion of the file name anyway to help keep yourself safe from attacks embedded in a file's name. It's usually a bad idea to launch a subprocess with any string that a user can control. If you're catching uploaded files, move them to some new name before running convert.exe - like a name generated from a uuid, for instance.
A workaround is to change the filename to something ascii safe then rename/move it to the name/path you want with full unicode characters.
Answering this question may not be helpful for now but it might be useful for someone.
Converting file path to UTF-8 encoding worked for me.

Resources