Tuesday, May 16, 2017

Note: Windows environmental variables

I ran into this problem today:
My JAVA_HOME environmental variable was defined on the user level, but I wanted to use it in Path on the system level. Well, this just does not work.
I had to define JAVA_HOME on the system level, to be able to include %JAVA_HOME%\bin in the Path.

Friday, May 12, 2017

Getting Started with Semantic UI

Whichever way you choose to work with Semantic UI, do not forget to import jQuery too, and don't forget to add it before Semantic UI.

In most cases you'll end up using a semantic.js and a semantic.css file in your website.

There are more ways to get your hand on the ones that fulfill your needs:

Default Theme

To use Semantic UI's default theme from a precompiled resource these are your options:

  • Reference the files from an online source, i.e. cdnjs.comsemantic.min.jssemantic.min.css.
  • Download your copy of the Semantic UI source. (You'll get the lightweight semantic-ui-css package this way)
  • Add semantic-ui-css to your node project as a dependency.
    Alternately you can add semantic-ui as a node project dependency too, in this case the precompiled resources will be in the dist folder.

Non-default Theme

To use a different theme than the default, you'll have to compile your resources yourself.


Using semantic-ui repository

Build your themed semantic-ui resources with the tools of the main repo:
(for more information and installing the prerequisites see the official guide)
  1. git clone or download the Semantic-UI repo
  2. run npm install
  3. in your /src/theme.config file, change the 'default' theme name to the theme you want to use in the components you want to use. (you can browse the /themes folder to review the possible choices)
  4. run gulp build
  5. your themed compiled resources will land in the /dist folder

Using semantic-ui-less repository

Building your themed semantic-ui resources using the lightweight semantic-ui-less repo is much more complicated than one would expect.
Follow this guide to make it work: Artem Butusov Blog Webpack + Customizable Semantic UI 2.x (LESS) (I found the guide in this issue of semantic-ui-less)

Tuesday, May 9, 2017

A day at batch scripting

Documentation: An A-Z Index of the Windows CMD command line
Tutorial: Batch Script Tutorial
  • string comparison in IF is by default case sensitive. To make it case insensitive, use the /i switch. (source)
  • if the last line of your code before a closing parentheses is a ::comment, like this:
    @echo off
    IF 1==1 (
     echo 1
     echo 2
     ::echo 3
    )
    then you'll get this error:
    ) was unexpected at this time.
  • if the script stops after executing a command to a command line tool (i.e. npm install ), you're probably calling it without CALL. You should call it with CALL (i.e. CALL npm install). (source)
  • hidden files and folders do not get detected with FOR %%a in (*) or in FOR /D %%a in (*). Here's how to query for hidden fires/folders.
  • Use @echo off to avoid printing every executed line.
  • if you do a SETLOCAL make sure to use ENDLOCAL at the end
  • variables (source):
    • SET foo=1 --> set environmental variable
      %foo% --> refer to environmental variable
      !foo! --> refer to environmental variable with delayed expansion
    • %%a --> FOR loop variable referred to in batch script
      %a --> FOR loop variable referred to in command line
  • variable declaration and spaces and quotes -- pay attention to these.
  • delayed expansion: (source and example) --> use it if you need to create and modify variables within loops.
    @echo off
    setlocal enabledelayedexpansion
    set searchfor=a c
    for %%a in (a b c d) do (
        set item="%%a"
     set found=0
     ( for %%b in (%searchfor%) do (
      set candidate="%%b"
      if "!item!"=="!candidate!" (
       set found=1
      )
     )
     )
     if "!found!"=="0" (
      echo "!item!" did not match any of the search terms
     ) else (
      echo "!item!" was a match
     )
    )
    endlocal
  • functions
    • documentation: read here
    • maximum length of a label is not 8 characters anymore
    • execution order: (source)
      it is very important to do the navigation with goto :eof and goto :end. If these navigations are left out it can cause code segments to run multiple times
      @echo off
      call :foo
      call :foo2
      goto end
      
      :foo
       echo foo
       goto :eof
      :foo2
       echo foo2
       goto :eof
      :end
       echo done
    • processing input arguments (source for foo; source for foo2)
      @echo off
      call :foo 1 2 3
      call :foo2 a b c
      goto end
      
      :foo
       for %%a in (%*) do (
        echo %%a
       )
       goto :eof
      :foo2
       echo %~1
       echo %~2
       echo %~3
       goto :eof
      :end