Category Archives: Scripting

Tips, examples and discussions for Power Shell, Bash and Windows Command Prompt.

Working SCSS Sourcemaps with Angular 6

If you are an Angular developer, you’ve probably noticed that since Angular 2+ they break with almost every release. After wasting many hours in futile attempts to fix them and going through numerous report on Angular GitHub page I finally got to a setup that works.

Fixing dependencies (vendor) sourcemaps

  1. Open angular.json and find targets->build->configurations
  2. Add a new configuration after production. Name it serve.
    "configurations": {
      "production": {
        ...
      }
      "serve": {
        "extractCss": true
      }
    
  3. Change serve task to use the new config by changing targets->serve->options
    "options": {
      "browserTarget": "PROJECT_NAME:build:serve"
    
  4. Open package.json and update start scripts
    "scripts: {
        ...
        "start": "ng serve --source-map --vendor-source-map --ssl",
    }
    
  5. Run your project with npm start. Inspect your markup. You’ll see dependencies SCSS using the source maps and showing correct paths.

Continue reading Working SCSS Sourcemaps with Angular 6

How to read an HTML page with UTF8 encoding using PowerShell

Yesterday I was working on a project that requires heavy HTML pages content scraping.

What I wrote were several PowerShell files which were scraping the content using Invoke-WebRequest and Invoke-RestMethod. And everything was great and smooth… until I got to an HTML page with some Greek letters inside. To my surprise both PowerShell built in functions failed miserably when I tried to retrieve those UTF8 encoded pages. In short, I was bombarded with ℠and ¢ here and there.

So, after I lost several hours trying to figure out what’s going on and experimenting with all kinds of options it turned out It’s impossible to read properly a UTF8 encoded page without BOM with Invoke-WebRequest.

Here is a simple function I wrote which uses .NET classes to tackle the problem.

Note that this is just a simple example and it lacks the extensible functionality you get with Invoke-WebRequest.

Reusing page jQuery in a Greasemonkey script

Many times I’ve used a RIA or a website and wanted it to behave differently or have an additional functionality that I need. Thanks to Greasemonkey this is possible.

We live in a jQueritifed world where most of the web pages use jQuery.

That’s why on of the things that I need to do most of the time when I write a userscript is to reuse the jQuery from the webpage without loading a new jQuery instance from the web. This will make my script much more responsive and who needs to load something that is already there.

Save your time by not reinventing the wheel and just use the boilerplate code I’m using for my Greasemonkey scripts.

Continue reading Reusing page jQuery in a Greasemonkey script