PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label visual-studio-code. Show all posts
Showing posts with label visual-studio-code. Show all posts

Wednesday, December 21, 2022

[FIXED] How to change the colour of region/endregion in VS Code?

 December 21, 2022     customization, syntax, visual-studio-code     No comments   

Issue

Does anyone know how to change the colour of #region/#endregion? This is greyish in VS Community but not on VS Code.

Thank you in advance.


Solution

Because the terms #region/#endregion are part of a comment, looking at their scopes with the command Developer: Inspect TM Scopes gives you only a comment scope so if you change the comment scope by the following tokenColorCustomization:

"editor.tokenColorCustomizations": {
    "comments": "#ffa600b0"
}

will change all comments - probably not what you want. Plus you can only change the fontColor and fontStyle (like italics) there.

Better is using the extension Highlight to find, via a regex, what you want to highlight.

Using //#region - your language may have different comment indicators at the start. If so, modify the first capture group (//\\s*) below.

  "highlight.regexes": {

    "(//\\s*)(#region|#endregion)": [

      // the first capture group, the '//' uncolored here, but must have the entry below
      //  you could color those separately if you wish
      {},

      // capture group: #region or #endregion
      {
        // "overviewRulerColor": "#ffcc00",
        "backgroundColor": "#f00",
        "color": "#fff",
        // "fontWeight": "bold",
        "borderRadius": "3px",
      },
    ]
  }


Answered By - Mark
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, December 14, 2022

[FIXED] How to get comments and string in regex?

 December 14, 2022     regex, syntax, syntax-highlighting, visual-studio-code     No comments   

Issue

i have create a programming language KAGSA, and i have to create a syntax highlighter i start with VSCode highlighter i write every thing well but i have problem with regex of strings (more than one line) and comments (more than one line) this is the code : Match is the code: Comments :

"comments": {
            "patterns": [{
                "name": "comment.line.shebang.kagsa",
                "match": "//..*|/\\*(.*?|\n)*\\*/|//|/\\**\\*"
            }]
        },

The problem is wit the /*Comment*/ comment. and string code :

"strings": {
            "name": "string.quoted.double.kagsa",
            "patterns": [{
                "name": "string.quoted.double.kagsa",
                "match": "'(.*?)'|\"(.*?)\"|``(.*?|\n)*``"
            }]
        },

my problem is with ``String`` and the Color i get :

[the output color][https://i.stack.imgur.com/NPbS0.png]


Solution

You have this issue because match doesn't work for multiline string literals. I found a similar problem. As said by Gama11 in his answer:

Try to use a begin / end pattern instead of a simple match.



Answered By - Tim Shidlovskii
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, December 13, 2022

[FIXED] What is `^` in Visual Studio Code key bindings notation

 December 13, 2022     key-bindings, notation, shortcut, syntax, visual-studio-code     No comments   

Issue

I'd like to open Source Control with a keyboard shortcut.

From the tooltip I can see, that a shortcut exists: tooltip shows the shortcut (^ shift G)

My problem: How do I type the caret character? On my keyboard it's (shift + 6). However this does not work for shortcuts.


Solution

In some environments ^ stands for the Control key. Visual Studio Code uses that notation on its MacOS version.

macOS Linux
Integrated terminal Integrated terminal


Answered By - Álvaro González
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, November 24, 2022

[FIXED] Why do my custom modules not get updated?

 November 24, 2022     angular, module, visual-studio-code     No comments   

Issue

I've written a library with several custom modules but I'm recently having trouble updating them. I haven't worked on this project for quite a while but I don't recall having any issues with this last time. I'm working with Visual Studio Code and encountered an error including one of the modules in a way it isn't supposed to, so I've added a check into one of its functions.

private transferRadius(buttons: HTMLButtonElement[], alignment: string): void {
  if(buttons.length === 0) { return; }

  if (alignment === 'vertical') {
    this.buttonGroup.nativeElement.style.borderTopLeftRadius = this.getButtonRadius(buttons[0], 'top-left');
    this.buttonGroup.nativeElement.style.borderTopRightRadius = this.getButtonRadius(buttons[0], 'top-right');
    this.buttonGroup.nativeElement.style.borderBottomRightRadius = this.getButtonRadius(buttons[buttons.length - 1], 'bottom-right');
    this.buttonGroup.nativeElement.style.borderBottomLeftRadius = this.getButtonRadius(buttons[buttons.length - 1], 'bottom-left');
  } else {
    this.buttonGroup.nativeElement.style.borderTopLeftRadius = this.getButtonRadius(buttons[0], 'top-left');
    this.buttonGroup.nativeElement.style.borderTopRightRadius = this.getButtonRadius(buttons[buttons.length - 1], 'top-right');
    this.buttonGroup.nativeElement.style.borderBottomRightRadius = this.getButtonRadius(buttons[buttons.length - 1], 'bottom-right');
    this.buttonGroup.nativeElement.style.borderBottomLeftRadius = this.getButtonRadius(buttons[0], 'bottom-left');
  }
}

I've installed the updated module into my project and when I take a look at the .mjs file of my module in the node_modules folder I can see the changes added. However, when I run ng build and/or ng serve the changes do not show up in the browser and I'm still running into the exception I'm trying to get rid of. This is not a cache issue, because I'm generally reloading the page with ctrl + f5, I've also cleared the cache and opened the site in Firefox for the first time (so there is no cache at all) with the same issue - which also means it's not a browser issue either.

This is what the .mjs file looks like in Chrome's developer tools:

transferRadius(buttons, alignment) {
  if (alignment === 'vertical') {
    this.buttonGroup.nativeElement.style.borderTopLeftRadius = this.getButtonRadius(buttons[0], 'top-left');
    this.buttonGroup.nativeElement.style.borderTopRightRadius = this.getButtonRadius(buttons[0], 'top-right');
    this.buttonGroup.nativeElement.style.borderBottomRightRadius = this.getButtonRadius(buttons[buttons.length - 1], 'bottom-right');
    this.buttonGroup.nativeElement.style.borderBottomLeftRadius = this.getButtonRadius(buttons[buttons.length - 1], 'bottom-left');
  }
  else {
    this.buttonGroup.nativeElement.style.borderTopLeftRadius = this.getButtonRadius(buttons[0], 'top-left');
    this.buttonGroup.nativeElement.style.borderTopRightRadius = this.getButtonRadius(buttons[buttons.length - 1], 'top-right');
    this.buttonGroup.nativeElement.style.borderBottomRightRadius = this.getButtonRadius(buttons[buttons.length - 1], 'bottom-right');
    this.buttonGroup.nativeElement.style.borderBottomLeftRadius = this.getButtonRadius(buttons[0], 'bottom-left');
  }
}

As you can see, the check for an empty array is missing. I also have a similar issue with another module, whose contents do not show up at all, which is again due to a missing update. I initially forgot to set the selector properly, thus my line selector: 'mat-editor[content]', shows up as args: [{ selector: 'lib-mat-editor', template: "<div class=\"mat-editor\"></div>" }] and hence, the element <mat-editor _ngcontent-jtc-c50=""></mat-editor> has no <div> child.

I've tried to find out where the project gets deployed to but only found out that it's likely just stored in the memory and not on the physical disk. I've also checked the dist folder in the project after an ng build, but that one only has a runtime...js, polyfills...js, and main...js as well as an index.html and some resources. No sight of the module at all (I assume it's somewhere included in the .js files?). How can I get my custom modules to update in the browser?


Solution

After a lot of diggin in, turns out the culprit was the webpack cache, although I don't know why it didn't replace the cached contents of the modules with the changed code - an explanation would be very welcome.

Anyways, adding the following to the angular.json file to disable the webpack cache worked for me.

"cli": {
  "cache": {
    "enabled": false
  }
},


Answered By - Otto Abnormalverbraucher
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, November 21, 2022

[FIXED] How to disable blue warning underline sign in flutter/dart extension?

 November 21, 2022     dart, flutter, visual-studio, visual-studio-code     No comments   

Issue

Can someone tell me how to disable the warning underlines in my code? I have posted the picture below. The blue wiggly signs are a pain while writing more codes. I tried to disable the SDK Formatter from the extension settings but it didn't work for me.

The blue lines pictured above


Solution

You are missing const keyword there.

void main() => runApp(
      const MaterialApp(
        home: Text("hello"),
      ),
    );

Linting code is good practice. But it's totally up to you to lint the code. If you want to disable linting, remove this line in pubspec.yaml,

  flutter_lints: ^1.0.0  // remove this line

and finally delete the analysis_options.yaml file in your project directory



Answered By - Shaan Mephobic
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can we save all files in (VSCode) like we do in Visual Studio

 November 21, 2022     keyboard-shortcuts, visual-studio, visual-studio-code     No comments   

Issue

How can we save all the files in Visual Studio Code like we do in Visual Studio by pressing Ctrl+Shift+S ?


Solution

It doesn't look like VS Code has a built-in single-press keyboard shortcut to save all open files on Windows.

The simplest way would be to use the menu accelerators: ALT+F, followed by ALT+L.

Alternatively, you can change the key binding by editing the keyboard preferences:

VS Code with File menu open, Preferences, Keyboard Shortcuts highlighted

Add the binding to the right half of the screen, then restart VS Code:

// Place your key bindings in this file to overwrite the defaults
[
    { 
      "key": "ctrl+shift+s", 
      "command": "workbench.action.files.saveAll" 
    }
]

enter image description here



Answered By - jessehouwing
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, November 14, 2022

[FIXED] How to link shared library on linux using cmake?

 November 14, 2022     c++, cmake, external, linux, visual-studio-code     No comments   

Issue

How to link shared library on linux platform? I downloaded sfml library using apt cmd and I tried to run simple example:

main.cpp

#include <SFML/Graphics.hpp>

int main()
{
    // Make a window that is 800 by 200 pixels
    // And has the title "Hello from SFML"
    sf::RenderWindow window(sf::VideoMode(800, 200), "Hello from SFML");
    return 0;
}

But I keep getting undefined reference even though vs code sees files and lets me jump directly to them using ctrl button.

cmake:

cmake_minimum_required(VERSION 3.0.0)
project(sflmProject VERSION 0.1.0)

include(CTest)
enable_testing()

add_executable(sflmProject main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

compilation error:

main] Building folder: firstSFLMProject 
[build] Starting build
[main] Changes were detected in CMakeLists.txt but we could not reconfigure the project because another operation is already in progress.
[proc] Executing command: /usr/bin/cmake --build /home/black_wraith/Documents/AIR/S8/RealTime/firstSFLMProject/build --config Debug --target all -j 10 --
[build] -- Configuring done
[build] -- Generating done
[build] -- Build files have been written to: /home/black_wraith/Documents/AIR/S8/RealTime/firstSFLMProject/build
[build] Consolidate compiler generated dependencies of target sflmProject
[build] [ 50%] Building CXX object CMakeFiles/sflmProject.dir/main.cpp.o
[build] [100%] Linking CXX executable sflmProject
[build] /usr/bin/ld: CMakeFiles/sflmProject.dir/main.cpp.o: in function `main':
[build] /home/black_wraith/Documents/AIR/S8/RealTime/firstSFLMProject/main.cpp:16: undefined reference to `sf::String::String(char const*, std::locale const&)'
[build] /usr/bin/ld: /home/black_wraith/Documents/AIR/S8/RealTime/firstSFLMProject/main.cpp:16: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
[build] /usr/bin/ld: /home/black_wraith/Documents/AIR/S8/RealTime/firstSFLMProject/main.cpp:16: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
[build] /usr/bin/ld: /home/black_wraith/Documents/AIR/S8/RealTime/firstSFLMProject/main.cpp:63: undefined reference to `sf::RenderWindow::~RenderWindow()'
[build] collect2: error: ld returned 1 exit status
[build] gmake[2]: *** [CMakeFiles/sflmProject.dir/build.make:97: sflmProject] Error 1
[build] gmake[1]: *** [CMakeFiles/Makefile2:839: CMakeFiles/sflmProject.dir/all] Error 2
[build] gmake: *** [Makefile:121: all] Error 2
[build] Build finished with exit code 2

I tried to modify cmake like this but I just have no idea which file should I add:

cmake_minimum_required(VERSION 3.0.0)
project(sflmProject VERSION 0.1.0)

include(CTest)
enable_testing()

add_library(sfml SHARED /usr/include/SFML/*)
add_executable(sflmProject main.cpp)

target_link_libraries(sflmProject PRIVATE sfml)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

Solution

here is an example of cmake file for sfml on linux

cmake_minimum_required(VERSION 3.22)

project(sfml-program LANGUAGES CXX)

add_executable(${PROJECT_NAME} main.cpp)

find_package (SFML 2.5 COMPONENTS graphics audio network REQUIRED)

target_link_libraries (${PROJECT_NAME} PUBLIC sfml-system sfml-graphics sfml-audio sfml-network)


Answered By - naftali
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, November 8, 2022

[FIXED] Why is my HTML file not displaying to the browser?

 November 08, 2022     html, visual-studio-code     No comments   

Issue

I am learning how to use a text editor, and I've just created my first file with it. It previews with the correct output, but when I run it in the browser, it gives me a blank page.

As you can see, the doctype and html tags are in place, as well as the head and body. I am using Visual Studio Code as my text editor. Why will this not display anything in my browser? To be clear, it does preview, just won't display in browser

<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
</head>
<body>
  <h1>Hello World</h1>
</body>
</html>


Solution

It loaded on Fire Fox, just not on Google Chrome for some reason. I'm sorry for wasting everyone's time. As I have said, I am unfamiliar with VS Code. Thank you for all of your suggestions.



Answered By - coding_gecko972
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, November 6, 2022

[FIXED] How can I create a VSCode snippet to automatically insert namespace of files inside my src folder?

 November 06, 2022     php, regex, regex-group, visual-studio-code, vscode-snippets     No comments   

Issue

First off, I have the following psr-4 declaration for the src folder inside my composer.json file:

"autoload": {
        "psr-4": {
            "Src\\": "src/"
        }
    },

I would like to build a VSCode snippet that autogenerates the namespace of a new file that resides inside the src folder.

So far I have this inside php.json:

    "Namespace Src": {
        "prefix": "ns_src",
        "body": [
            "namespace ${RELATIVE_FILEPATH};",
        ],
        "description": "Namespace for file routes inside the src folder"
    },

Taking as an example the following file:

src/MyEntity/Application/MyUseCase.php

The desired result would be:

namespace Src\MyEntity\Application;

And right now this is what it returns to me:

namespace src/MyEntity/Application/MyUseCase.php;

So I need to tackle:

  • Upper case of src.
  • Replacement of forward slashes / into back slashes \.
  • Removal of everything that is after the last forward slash /.

I know there has to be a way to do this with regex. I have read this similar problem (VSCODE snippet PHP to fill namespace automatically) but I haven't quite got the hang of it after reading it. And I think the upper case problem could maybe be solved with \F as in here: https://www.regular-expressions.info/replacecase.html#:~:text=In%20the%20regex%20%5CU%5Cw,is%20not%20a%20word%20character.

Is this the right approach? Could you give me any tips on this problem?

Thank you so much.


Solution

You can use

"Namespace Src": {
    "prefix": "ns_src",
    "body": [
        "namespace ${RELATIVE_FILEPATH/^(?:.*[\\\\\\/])?(src)(?=[\\\\\\/])|[\\\\\\/][^\\\\\\/]*$|([\\\\\\/])/${1:+Src}${2:+\\\\}/g};",
     ],
    "description": "Namespace for file routes inside the src folder"
},

See the regex demo. Details:

  • ^(?:.*[\\\/])?(src)(?=[\\\/]) - start of string (^), then an optional occurrence of any zero or more chars as many as possible (.*) and a \ or / char ([\\\/]), and then src captured into Group 1, that is immediately followed with / or \
  • | - or
  • [\\\/][^\\\/]*$ - a \ or / char and then zero or more chars other than / and \ till end of string
  • | - or
  • ([\\\/]) - Group 2: a \ or / char.

The ${1:+Src}${2:+\\\\} replacement replaces in this way:

  • ${1:+Src} - if Group 1 matched, replace with Src
  • ${2:+\\\\} - if Group 2 matched, replace with \.


Answered By - Wiktor Stribiżew
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, November 5, 2022

[FIXED] How to modify environment variables (such as PATH) when using python.unittest in VS Code?

 November 05, 2022     environment-variables, python, unit-testing, visual-studio-code     No comments   

Issue

I'm writing a python unit test using unittest and I want to compile some Solidity contracts in the test setup.

However, when I did the compile by os.system() or subprocess.run(), it shows that solc, the Solidity compiler, not found. While it runs properly when running in a non-test python program.

After this happens, I found a further interesting things: when I print(os.environ) in both a test python program using unittest and a normal python program, the result is of hugh difference! Including the most important one: $PATH. It looks like the following:

****PATH in unittest****
/usr/bin
/usr/local/bin
...(mostly the default $PATH set by Linux)


****PATH in normal program****
/usr/bin
/.../myEnvs/.../bin
...(as same as my console's $PATH, which is exported in .bashrc)

Since I'm working with others to develop this program, I should NOT add path such as "myEnvs" in program (by using environment setting like env= parameter provided by subprocess.Popen()).

I think the abnormal $PATH in python.unittest is caused by some configurations introduced by VScode, so what are these configs? How could I modify them? or this "PATH inconsistence" is caused by some other reasons?


Solution

Okey..... After a period of time, I finally find out what happens:

  1. Exactly, The so-called "$PATH difference" is caused by VScode configurations in launch.json.
  2. You can create a new term like this and make your unittest configuration same as a normal debug:
{
    ...
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal", 
            "justMyCode": false,
            "args": []
        },
        {
            "name": "Python: Debug Tests",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "purpose": ["debug-test"],
            "console": "integratedTerminal", // Consistence with ```Python: CurrentFile```
            "justMyCode": false,
        },
    ]
}

  1. This Debug Test configuration can be used in different test mode, see more in VSCode doc - Debug tests.

  2. The critial one is "console", the default value is "internalConsole", which seems to share the same env with system defaults. While I should set it to "integratedTerminal", which is consistent with my own shell.



Answered By - Alexious
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, November 1, 2022

[FIXED] how can i see my html file on mobile device using live server in vscode?

 November 01, 2022     html, liveserver, server, visual-studio-code     No comments   

Issue

I'm using windows10 pro on PC and android on mobile. and i followed this process below.

Why can't I enter the url on my phone's browser to view my live site?

127.0.0.1 is a special-purpose IPv4 address reserved for loopback purposes. That is, this IP refers to >your computer itself.

By entering http://127.0.0.1:5500/index.html in your browser, you're requesting web page within your >computer.

In normal case, your computer will be in a NAT network (under same wi-fi AP for instance), and you'll be >assigned with a virtual IP. Normally it's 192.168.x.x.

You may enter the following command in your command prompt to see your IP address.

ipconfig

As a result, under your network interface card, you'll get your IP Address.

If the IP address belongs to virtual IP, then you may access it with your phone using

http://< Your IP Address >:5500/index.html

If it's not virtual IP, it is Public IP. Then, you'll have to configure appropriate Firewall settings >under this circumstance.

Hope this will help.

then i'm done this : Control Panel -> Windows Defender Firewall -> Allow an app or feature through Windows Defender Firewall -> Allowed "code.exe" app.

but on my mobile device, There is still ERR_ADDRESS_UNREACHABLE. and i also followed official instruction. still not work on my mobile device.. enter image description here

is there another method?


Solution

oh i found it!!!! if there is anyone who use public wifi don't do that... it works on only private wifi.. Thank you everyone for helping me i love you guys!!!!



Answered By - Lee TaeWon
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does my VS Code Live Server Extention show images when open on browser but images don't show when opening it with index.html file

 November 01, 2022     browser, css, html, liveserver, visual-studio-code     No comments   

Issue

So here is the issue I use VS Code and the live server exstention. but now when I open the website with Go Live in VS Code then the images i have inserted in the website displays perfectly as the should whut then when I open the website on the index.html file then I only het the alt text thats but in the html and the images dont display.

I have doulble and triple checked the paths and I also have moved the images to a new folder and changed the name and then changed all the sources in the HTML code but it did not change anything at all, I also tried using different browsers (Chrome, firefox, microsoft edge) did not find anything

<img
   class="section-main--img1"
  src="/img/3 items.png"
  alt="Picture of all 3 colors"
/>
<img
  class="section-main--img2"
  src="/img/all 3.png"
  alt="Picture of all 3 items"
/>
.section-main--img1 {
  width: 70%;
  grid-column: 1;
  grid-row: 2;
  justify-self: center;
}

.section-main--img2 {
  width: 60%;
  justify-self: center;
  align-self: center;
  grid-column: 3;
  grid-row: 3;
}

I have more images in my project but all of them are done in the exact same way.

Can someone help me with this issue please?


Solution

Read up on how relative URLs are resolved. They are relative to the URL of the HTML document. If you change the URL of the HTML document then the relative URL will resolve differently.

If you open http://localhost/index.html then /img/3 items.png is going to resolve to http://localhost/img/3 items.png

If you open file:///c/users/me/mywebsite/index.html then /img/3 items.png is going to resolve to file:///c/img/3 items.png … which is the wrong path.



Answered By - Quentin
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how can i run my html file with live server in chrome browser

 November 01, 2022     html, liveserver, visual-studio-code, vscode-extensions     No comments   

Issue

so I want to open html file with live server extension but in chrome browser , I don't know why but it's always open in edge browser


Solution

This is probably caused by the fact that Edge may be set as your default browser. Go to your Settings app, search "Default Browser" and modify your OS' default browser that way.



Answered By - IPSDSILVA
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why is Java program compiled by VSCode faster than one created by manually running javac?

 November 01, 2022     java, performance, visual-studio-code, vscode-extensions     No comments   

Issue

I hava a benchmark program as follows.

public class App {

    public static void main(String[] args) {
        int n_iters = Integer.parseInt(args[0]);
        long tInit = System.currentTimeMillis();
        int c = 0;

        for (int i = 0; i < n_iters; ++i) {
            for (int j = 0; j < n_iters; ++j) {
                for (int k = 0; k < n_iters; ++k) {
                    if (i * i + j * j == k * k) {
                        ++c;
                    }
                }
            }
        }

        System.out.println(c);
        System.out.println((System.currentTimeMillis() - tInit) / 1000.0);
    }
}

I put it under src directory. I compiled it by

javac src/App.java

VSCode Java extention also automatically created a working directory bin and compiled App.class under it.

Fist I ran java -cp src App 1000, it took about 1.8 seconds. Then I ran java -cp bin App 1000, this time it took 0.56 seconds.

Does it mean bin/App.class compiled by VSCode is faster than manually compiled src/App.class ? My understanding is that Java compiler does not do any optimization. JVM JIT does it. So these different runtimes don't make sense to me.

Note that there no any other source files or data files in src and bin. Other than cmd arg, the program does not depends on any external data neither.

I tested under the following environment.

  • OS: Windows 11
  • JDK: Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
  • VSCode Java Extention (redhat.java): v1.10.0

[edit]

VSCode Java extention uses ECJ compiler. https://github.com/redhat-developer/vscode-java/issues/2689

ECJ and javac compiles differently and for this task, ECJ did well. I'm still figuring out if I can get the same performance for this task with javac.


Solution

VS Code Java use ecj to compile the Java sources, which is a different compiler implementation from javac.

I think you can use javap -verbose xxx.class to check if there is any difference between the two compiled class files.



Answered By - Sheng Chen
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, October 19, 2022

[FIXED] How to run VSCode from the command prompt

 October 19, 2022     admin, cmd, runas, visual-studio-code, windows     No comments   

Issue

I for security reasons cannot run VSCode plainly. I have opened it in the past, but now due to specific reasons, I may only run VSCode from the command prompt. I've tried

start "path/to/file" code and start code "path/to/file"
but none work I'm on Microsoft Windows [Version 10.0.17134.407]

how may I run this by going to Windows+R then 'cmd' then start/ run?

Also it would be great if I could use this for a separate user.

I'm looking for something like:
Runas /user:user\admin /savecred "C:\Program Files (x86)\vs-code.exe"


Solution

Well shoot, as it turns out that after doing some experimentation I found out that there's a way. Do this:

  1. Simply stick this:

    runas /user:Techtiger255\admin /savecred "C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code\Code.exe"
    

    inside of a shortcut (.lnk file)

 

  1. Open your command line of choice (Powershell or Cmd) and enter the exact file path of your shortcut ex: "C:\Users\Standard\Desktop/VSCODE.lnk" and hit go, stupidly simple really, just had to find the code.exe file path.


Answered By - 255.tar.xz
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why is my function not working in vscode when it works in jupyternote book?

 October 19, 2022     function, jupyter-notebook, pep, python, visual-studio-code     No comments   

Issue

I am new to python and have recently started to study it full-time. I have been using vscode to type out my code I would run the script and it would show my output in the terminal window.

However, I cannot get a lot of the functions I create to display an output in the terminal window. However, as a comparison check, I ran the same code in a Jupyter notebook and it worked perfectly fine. I also tried running this code on another laptop in vscode running it as a python file. But nothing has worked.

Here is the code running as a python file in vscode:

Running as a python file

Here is the code running in a jupyter notebook in vscode:

Running in a jupyter notebook

I apologise if I have been unclear. Do feel free to ask any questions to get a better understanding. I am a noob at this, so any help would be really encouraging. Thanks :)


Solution

Jupyter display in the console the value of the last line of code in a cell.

In normal Python scripts this does not happen. If you want to see the output in the console you need to use the print() function or similar.

so in your case:

print(capitalize_letters("mcdonald"))

or

capitalized_word = capitalize_letters("mcdonald")
print(capitalized_word)


Answered By - f-starace
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, October 16, 2022

[FIXED] Why does Prettier not format code in VS Code?

 October 16, 2022     javascript, nuxt.js, prettier, visual-studio-code, vue.js     No comments   

Issue

In my Nuxt application where ESlint and Prettier are installed and enabled, I switched to Visual Studio Code.

When I open a .vue file and press CMD+ Shift + P and choose Format Document, my file does not get formatted at all.

My .prettierrc settings:

{
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true
}

I have so many source code lines, so I cannot format them manually. What am I doing wrong?


Solution

How I've sorted it after having super huge frustrations with Prettier stopping working in VSCode.

  1. Select VS Code -> View -> Command Palette, and type: Format Document With
  2. Then Configure Default Formatter... and then choose Prettier - Code formatter.

This sorted the problem for me magically.

Depending on your case this might help you...



Answered By - Miha
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, October 6, 2022

[FIXED] How to copy all text from the integrated vs-code terminal?

 October 06, 2022     terminal, visual-studio-code     No comments   

Issue

Is there a way to copy all the text from the integrated Visual Studio Code terminal? I have some output that I want to copy to a text file and save it.


Solution

I can just right-click in the terminal and chose Select All and then right-click and Copy. Does that not work for you?

There is an unbound command for the selection:

workbench.action.terminal.selectAll

and Ctrl+C for the copy.

If you do this a lot you could make a macro to do the whole thing: select, copy, open a new text file and paste.



Answered By - Mark
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to clear the entire terminal (PowerShell)

 October 06, 2022     powershell, terminal, visual-studio-code     No comments   

Issue

I had an issue. Using the clear or cls command in powershell clears only the visible portion of the terminal,I would like to know how to clear the entire terminal?

I use VSCode by the way.


Solution

To also clear the scrollback buffer, not just the visible portion of the terminal in Visual Studio Code's integrated terminal, use one of the following methods:

  • Use the command palette:

    • Press Ctrl+Shift+P and type tclear to match the Terminal: Clear command and press Enter
  • Use the integrated terminal's context menu:

    • Right-click in the terminal and select Clear from the context menu.
    • On Windows, you may have to enable the integrated terminal's context menu first, given that by default right-clicking pastes text from the clipboard:
      Open the settings (Ctrl+,) and change setting terminal.integrated.rightClickBehavior to either default or selectWord (the latter selects the word under the cursor before showing the context menu).
  • Use a keyboard shortcut from inside the integrated terminal (current as of v1.71 of VSCode):

    • On macOS, a shortcut exists by default: Cmd+K
    • On Linux and Windows, you can define an analogous custom key binding, Ctrl+K, as follows, by directly editing file keybindings.json (command Preferences: Open Keyboard Shortcuts (JSON) from the command palette), and placing the following object inside the existing array ([ ... ]):
{
    "key": "ctrl+k",
    "command": "workbench.action.terminal.clear",
    "when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
}

Using a command you can invoke from a shell in the integrated terminal:

Note: A truly cross-platform solution would require executing the VSCode-internal workbench.action.terminal.clear command from a shell, but I don't know how to do that / if it is possible at all - do tell us if you know.

  • Linux (at least as observed on Ubuntu):

    • Use the standard clear utility (/usr/bin/clear), which also clears the scrollback buffer.

    • From PowerShell, you may also use Clear-Host or its built-in alias, cls.

      • By contrast, [Console]::Clear() does NOT clear the scrollback buffer and clear just one screenful.
  • macOS:

    • Unfortunately, neither /usr/bin/clear nor PowerShell's Clear-Host (cls) nor .NET's [Console]::Clear() clear the scrollback buffer - they all clear just one screenful.

    • Print the following ANSI control sequence: '\e[2J\e[3J\e[H' (\e represents the ESC char. (0x1b, 27); e.g., from bash: printf '\e[2J\e[3J\e[H'; from PowerShell: "`e[2J`e[3J`e[H"

    • You can easily wrap this call in a shell script for use from any shell: create a file named, say, cclear, in a directory listed in your system's PATH variable, then make it executable with chmod a+x; then save the following content to it:

      #!/bin/bash
      
      # Clears the terminal screen *and the scrollback buffer*.
      # (Needed only on macOS, where /usr/bin/clear doesn't do the latter.)
      
      printf '\e[2J\e[3J\e[H'
      
  • Windows:

    • NO solution that I'm aware of: cmd.exe's internal cls command and PowerShell's internal Clear-Host command clear only one screenful in the integrated terminal (not also the scrollback buffer - even though they also do the latter in a regular console window and in Windows Terminal).

    • Unfortunately, the escape sequence that works on macOS ("`e[2J`e[3J`e[H" or, for Windows PowerShell, "$([char]27)[2J$([char]27)[3J$([char]27)[H") is not effective: on Windows it just clears one screenful.

    • (By contrast, all of these methods do also clear the scrollback buffer in regular console windows and Windows Terminal.)



Answered By - mklement0
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does the terminal display in my vscode look different?

 October 06, 2022     terminal, visual-studio-code     No comments   

Issue

So I initially used windows, but recently decided to switch to linux. In windows, my vscode terminal look like this: enter image description here

It shows which directory I am in. But when i try vscode in linux, i get this on run:

enter image description here

It shows nothing but sh-5.1, which i don't know what is it. And when i run a simple c program: enter image description here

the output is on the same line as the sh-5.1. How to change the terminal to look like in windows? (not exactly the same, I mean at least show the directory and generate a newline when done running program)


Solution

You can simply write:

bash

to your console since bash shell is the closest one to what you want. Your current shell is sh. To switch back to sh, you can write sh again. To see other available shells in your computer, you can write: cat /etc/shells

If you don't have bash installed on your computer (which is pretty unlikely), you can install it by:

sudo apt-get install bash


Answered By - meta6483
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing