Category: Quick Wins

Practical tips you can use today

  • How to start edge browser with work profile in command line.

    Imagine this: It’s Monday morning, you’ve just sat down at your desk, coffee in hand, ready to tackle your inbox. You hit your shiny new Stream Deck button to launch Outlook in Microsoft Edge, expecting your work profile to appear—only to be greeted by your personal account, memes and shopping carts included. Frustrating, right? If you’re juggling multiple profiles in Edge, you know the pain of always landing in the wrong one. Let’s fix that for good.

    Why Profiles Matter in Microsoft Edge

    Edge does a stellar job separating work and personal profiles, keeping your professional life distinct from your weekend browsing. But when you launch Edge from the command line (or automate it with tools like Stream Deck), it defaults to your personal profile. Not ideal if you’re trying to keep your work and personal worlds apart.

    The Command That Gets You There

    After some digging (and a few choice words), I found the solution. You can specify which profile Edge should use when launching a site. Here’s the magic command:

    start msedge --profile-directory="Profile 1" https://outlook.office.com/owa/

    How It Works

    • start msedge: Launches Microsoft Edge from the command line.
    • --profile-directory="Profile 1": Tells Edge which profile to use. “Profile 1” is usually your first added profile, but it can vary.
    • https://outlook.office.com/owa/: Opens Outlook Web Access directly in your chosen profile.

    Practical Tips & Gotchas

    • Find Your Profile Name: The profile directory name isn’t always obvious. To check yours, go to %LOCALAPPDATA%\Microsoft\Edge\User Data and look for folders like Profile 1, Profile 2, etc. Match the folder to your desired profile.
    • Spaces in Paths: If your profile name has spaces, keep the quotes around it. Otherwise, Edge will get confused.
    • Automating with Shortcuts: You can put this command in a batch file or use it with automation tools like Stream Deck, AutoHotkey, or Windows Task Scheduler.
    • Multiple Profiles: If you have more than two profiles, make sure you’re using the correct directory name. “Profile 1” is not always your work profile!

    My Take

    If you care about keeping your work and personal lives separate (and you should), this command is a must-have in your productivity toolkit. Don’t settle for Edge’s default behavior—take control and make your workflow seamless.

    Bonus: Open Any Site with Any Profile

    Want to open any site with a specific profile? Just swap out the URL:

    start msedge --profile-directory="Profile 2" https://github.com/

    Now go automate your day like a pro.

  • How to always show full right click menu in windows 11

    Picture this: You’re deep in code, right-clicking to quickly edit a file, only to be greeted by Windows 11’s minimalist context menu. The option you need? Hidden behind a “Show more options” click. Frustrating, right? As a developer, every extra click slows you down. Luckily, there’s a straightforward fix to bring back the classic, full right-click menu—no more hunting for your favorite commands.

    Why Did Microsoft Change the Menu?

    Windows 11 introduced a cleaner, more modern UI, but at the cost of burying many useful context menu options. While the intention was to reduce clutter, for power users and developers, this means extra steps for basic tasks like “Edit” or “Open with Notepad.” If you value speed and efficiency over aesthetics, restoring the full menu is a no-brainer.

    How to Restore the Full Context Menu

    You can revert to the classic right-click menu with a simple registry tweak. Here’s how:

    reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve
    taskkill /f /im explorer.exe
    start explorer.exe
    

    Step-by-Step Instructions

    1. Open Command Prompt as Administrator: Hit Win + S, type “cmd”, right-click and choose “Run as administrator.”
    2. Run the Registry Command: Paste the first line above. This creates a registry key that tells Windows to use the old menu.
    3. Restart Windows Explorer: The next two commands kill and restart Explorer, applying your changes instantly.

    Practical Tips & Gotchas

    • Backup Your Registry: Registry edits are powerful but risky. Always back up before making changes.
    • Reverting the Change: To undo, simply delete the {86ca1aa0-34aa-4e8b-a509-50c905bae2a2} key in the registry and restart Explorer.
    • Windows Updates: Major updates may reset this tweak. If your menu reverts, just repeat the steps.
    • Why Not Use Third-Party Tools? Registry edits are cleaner, don’t require extra software, and are less likely to break with updates.

    Final Thoughts

    Windows 11’s streamlined context menu might look pretty, but for those of us who live and breathe efficiency, it’s a step backward. Don’t settle for extra clicks—take control and restore your workflow. If you run into trouble, drop me a line; I’m always happy to help fellow devs cut through the nonsense.

  • How to get html code from console of a website

    Hook: The Power of the Browser Console

    Imagine this: you’re debugging a website late at night, and something isn’t rendering correctly. The CSS looks fine, the JavaScript isn’t throwing errors, but the page still isn’t behaving as expected. You suspect the issue lies in the generated HTML structure, but how do you quickly inspect or copy the entire HTML of the page? The answer lies in a tool that’s already at your fingertips: the browser console. Whether you’re a developer troubleshooting a bug, a designer analyzing a competitor’s layout, or a curious learner diving into web development, knowing how to extract a webpage’s HTML directly from the browser console is an essential skill.

    In this article, we’ll go beyond the basics of using document.documentElement.outerHTML. We’ll explore practical use cases, show you how to handle large HTML outputs, discuss security implications, and even touch on automating this process with scripts. By the end, you’ll not only know how to grab HTML from the console but also how to use this knowledge effectively and responsibly.

    Understanding document.documentElement.outerHTML

    The document.documentElement.outerHTML property is a JavaScript method that returns the entire HTML structure of the current webpage as a string. This includes everything from the opening <html> tag to the closing </html> tag. It’s a quick and straightforward way to access the full DOM (Document Object Model) representation of a page.

    Here’s a simple example:

    // Retrieve the entire HTML of the current page
    const html = document.documentElement.outerHTML;
    console.log(html);
    

    When you run this in your browser’s console, it will output the full HTML of the page. But before we dive into the “how,” let’s address an important topic: security.

    🔐 Security Note: Be cautious when running code in the browser console, especially on untrusted websites. Malicious scripts can exploit the console to trick users into executing harmful commands. Always verify the code you’re running and avoid pasting unknown scripts into the console.

    Step-by-Step Guide to Extracting HTML

    Let’s walk through the process of extracting HTML from a webpage using the browser console. We’ll include tips and tricks to make the process smoother.

    1. Open the Browser Console

    The first step is to access the browser’s developer tools. Here’s how to do it in popular browsers:

    • Chrome: Press F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac).
    • Firefox: Press F12 or Ctrl+Shift+K (Windows/Linux) or Cmd+Option+K (Mac).
    • Edge: Press F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac).
    • Safari: Enable “Develop” mode in Preferences, then press Cmd+Option+C.

    2. Run the Command

    Once the console is open, type the following command and press Enter:

    document.documentElement.outerHTML

    The console will display the entire HTML of the page. You can scroll through it, copy it, or save it for later use.

    💡 Pro Tip: If the output is too long and gets truncated, use console.log(document.documentElement.outerHTML) instead. This ensures the full HTML is displayed in a scrollable format.

    3. Copy the HTML

    To copy the HTML, right-click on the output in the console and select “Copy” or use the keyboard shortcut Ctrl+C (Windows/Linux) or Cmd+C (Mac). Paste it into a text editor for further analysis or modification.

    Handling Large HTML Outputs

    For complex websites with large DOM structures, the HTML output can be overwhelming. Here are some strategies to manage it:

    1. Save to a File

    Instead of copying the HTML manually, you can save it directly to a file using the following code:

    // Create a Blob and download the HTML as a file
    const html = document.documentElement.outerHTML;
    const blob = new Blob([html], { type: 'text/html' });
    const url = URL.createObjectURL(blob);
    
    const a = document.createElement('a');
    a.href = url;
    a.download = 'page.html';
    a.click();
    
    URL.revokeObjectURL(url);
    

    This script creates a downloadable file named page.html containing the full HTML of the page. It’s especially useful for archiving or sharing.

    2. Extract Specific Elements

    If you’re only interested in a specific part of the page, such as the <body> or a particular div, you can target it directly:

    // Get the HTML of the  tag
    const bodyHtml = document.body.outerHTML;
    console.log(bodyHtml);
    
    // Get the HTML of a specific element by ID
    const elementHtml = document.getElementById('myElement').outerHTML;
    console.log(elementHtml);
    
    💡 Pro Tip: Use browser extensions like “SelectorGadget” to quickly find the CSS selectors for specific elements on a page.

    Automating HTML Extraction

    If you need to extract HTML from multiple pages, consider automating the process with a headless browser like Puppeteer. Here’s an example:

    // Puppeteer script to extract HTML from a webpage
    const puppeteer = require('puppeteer');
    
    (async () => {
      const browser = await puppeteer.launch();
      const page = await browser.newPage();
      await page.goto('https://example.com');
    
      const html = await page.evaluate(() => document.documentElement.outerHTML);
      console.log(html);
    
      await browser.close();
    })();
    

    This script launches a headless browser, navigates to a specified URL, and logs the full HTML of the page. It’s a powerful tool for web scraping and automation.

    Security and Ethical Considerations

    While extracting HTML is a legitimate technique, it’s important to use it responsibly. Here are some guidelines:

    • Respect copyright and intellectual property laws. Don’t use extracted HTML to replicate or steal content.
    • Follow website terms of service. Some sites explicitly prohibit scraping or automated data extraction.
    • Avoid running untrusted scripts in the console. Always verify the source of the code.
    ⚠️ Gotcha: Some websites use obfuscation or dynamically generate HTML with JavaScript, making it harder to extract meaningful content. In such cases, tools like Puppeteer or browser extensions may be more effective.

    Conclusion

    Extracting HTML from a webpage using the browser console is a simple yet powerful technique that every developer should know. Here’s a quick recap:

    • Use document.documentElement.outerHTML to retrieve the full HTML of a page.
    • Handle large outputs with console.log or save the HTML to a file.
    • Target specific elements to extract only the content you need.
    • Automate the process with tools like Puppeteer for efficiency.
    • Always consider security and ethical implications when extracting HTML.

    Now it’s your turn: What creative uses can you think of for this technique? Share your thoughts and experiences in the comments below!

  • How to move files around with scp

    Picture this: it’s 3 AM, and you’re debugging an issue on a remote server. Logs are piling up, and you need to download a massive file to analyze it locally. Or maybe you’re deploying a quick patch to a production server and need to upload a configuration file. In moments like these, scp (Secure Copy) is your best friend. It’s simple, reliable, and gets the job done without unnecessary complexity. But like any tool, using it effectively requires more than just knowing the basic syntax.

    In this guide, we’ll go beyond the basics of scp. You’ll learn how to securely transfer files, optimize performance, avoid common pitfalls, and even troubleshoot issues when things go sideways. Whether you’re a seasoned sysadmin or a developer just getting started with remote servers, this article will arm you with the knowledge to wield scp like a pro.

    What is scp?

    scp stands for Secure Copy, and it’s a command-line utility that allows you to transfer files between local and remote systems over an SSH connection. It’s built on top of SSH, which means your data is encrypted during transfer, making it a secure choice for moving sensitive files.

    Unlike modern tools like rsync, scp is straightforward and doesn’t require additional setup. If you have SSH access to a remote machine, you can use scp immediately. However, this simplicity comes with trade-offs, which we’ll discuss later in the article.

    Downloading Files from a Remote Server

    Let’s start with the most common use case: downloading a file from a remote server to your local machine. Here’s the basic syntax:

    scp -i conn.pem [email protected]:/home/azureuser/output.gz ./output.gz

    Here’s what’s happening in this command:

    • -i conn.pem: Specifies the private key file for SSH authentication.
    • [email protected]: The username and IP address of the remote server.
    • :/home/azureuser/output.gz: The absolute path to the file on the remote server.
    • ./output.gz: The destination path on your local machine.

    After running this command, the file output.gz will be downloaded to your current working directory.

    💡 Pro Tip: Use absolute paths on the remote server to avoid confusion, especially when dealing with complex directory structures.

    Real-World Example: Downloading Logs

    Imagine you’re troubleshooting an issue on a remote server, and you need to analyze the logs locally:

    scp -i ~/.ssh/id_rsa admin@prod-server:/var/log/nginx/access.log ./access.log

    This command downloads the Nginx access log to your local machine. If the file is large, consider using the -C option to compress it during transfer:

    scp -C -i ~/.ssh/id_rsa admin@prod-server:/var/log/nginx/access.log ./access.log

    Compression can significantly speed up transfers, especially for text-heavy files like logs.

    Uploading Files to a Remote Server

    Uploading files is just as straightforward. The syntax is almost identical, but the source and destination paths are reversed:

    scp -i conn.pem ./config.yaml [email protected]:/etc/myapp/config.yaml

    In this example:

    • ./config.yaml: The file on your local machine that you want to upload.
    • [email protected]:/etc/myapp/config.yaml: The destination path on the remote server.
    ⚠️ Gotcha: Ensure the destination directory on the remote server exists and has the correct permissions. Otherwise, the command will fail.

    Real-World Example: Deploying Configuration Files

    Let’s say you’re deploying a new configuration file to a production server:

    scp -i ~/.ssh/id_rsa ./nginx.conf admin@prod-server:/etc/nginx/nginx.conf

    After uploading, don’t forget to reload or restart the service to apply the changes:

    ssh -i ~/.ssh/id_rsa admin@prod-server "sudo systemctl reload nginx"

    Advanced scp Options

    scp comes with several options that can make your life easier. Here are some of the most useful ones:

    • -C: Compresses files during transfer, which can speed up the process for large files.
    • -P: Specifies the SSH port if it’s not the default port 22.
    • -r: Recursively copies directories and their contents.
    • -p: Preserves the original access and modification times of the files.

    Example: Copying an Entire Directory

    To copy a directory and all its contents, use the -r option:

    scp -r -i conn.pem ./my_project [email protected]:/home/azureuser/

    This command uploads the entire my_project directory to the remote server.

    🔐 Security Note: Avoid using scp with password-based authentication. Always use SSH keys for better security.

    Common Pitfalls and Troubleshooting

    While scp is generally reliable, you may encounter issues. Here are some common problems and how to solve them:

    1. Permission Denied

    If you see a “Permission denied” error, check the following:

    • Ensure your SSH key has the correct permissions: chmod 600 ~/.ssh/id_rsa.
    • Verify that your user account has write permissions on the remote server.

    2. Connection Timeout

    If the connection times out, confirm that:

    • The remote server’s SSH service is running.
    • You’re using the correct IP address and port.

    3. Slow Transfers

    For slow transfers, try enabling compression with the -C option. If the issue persists, consider using rsync, which is more efficient for large or incremental transfers.

    When to Use scp (and When Not To)

    scp is great for quick, one-off file transfers. However, it’s not always the best choice:

    • For large datasets or incremental backups, use rsync.
    • For automated workflows, consider tools like sftp or ansible.

    That said, scp remains a valuable tool in your arsenal, especially for its simplicity and ubiquity.

    Key Takeaways

    • scp is a simple and secure way to transfer files over SSH.
    • Use options like -C, -r, and -p to enhance functionality.
    • Always use SSH keys for authentication to improve security.
    • Be mindful of permissions and directory structures to avoid errors.
    • For large or complex transfers, consider alternatives like rsync.

    Now it’s your turn: What’s your favorite scp trick or tip? Share it in the comments below!

  • How to execute a command(s) or a script via SSH

    Imagine this: you’re sipping coffee at your desk, and you suddenly need to check the status of a remote server. Do you really want to fire up a full-blown remote desktop or wrestle with clunky web dashboards? No way. With SSH, you can execute commands remotely—fast, simple, and scriptable. If you’re not using this technique yet, you’re missing out on one of the best productivity hacks in the sysadmin and developer toolkit.

    Running a Single Command Over SSH

    Want to check the uptime of a remote machine? Just send the command directly and get the output instantly:

    ssh [email protected] 'uptime'

    Tip: The command inside single quotes runs on the remote host, and its output comes right back to your terminal. This is perfect for quick checks or automation scripts.

    Executing Multiple Commands

    Sometimes, you need to run a sequence of commands. You don’t have to SSH in and type them one by one. Use a here document for multi-command execution:

    ssh [email protected] << EOF
    COMMAND1
    COMMAND2
    COMMAND3
    EOF

    Gotcha: Make sure your EOF delimiter is at the start of the line—no spaces! Also, remember that environment variables and shell settings may differ on the remote host.

    Running a Local Script Remotely

    Have a script on your local machine that you want to run remotely? You don’t need to copy it over first. Just stream it to the remote shell:

    ssh [email protected] 'bash -s' < myscript.sh

    Pro Tip: This pipes your local myscript.sh directly to bash on the remote machine. If your script needs arguments, you can pass them after bash -s like this:

    ssh [email protected] 'bash -s' -- arg1 arg2 < myscript.sh

    Best Practices and Pitfalls

    • Use SSH keys for authentication—never hardcode passwords in scripts.
    • Quote your commands properly to avoid shell interpretation issues.
    • Test locally before running destructive commands remotely. A misplaced rm -rf can ruin your day.
    • Check exit codes if you’re automating deployments. SSH will return the exit status of the remote command.

    Why This Matters

    SSH command execution is a game-changer for deployment, automation, and troubleshooting. It’s fast, scriptable, and—when used wisely—secure. So next time you need to automate a remote task, skip the manual steps and use these SSH tricks. Your future self will thank you.