Tuesday, August 1, 2017

GIT: useful commands

Checkout and start tracking remote branch:
git checkout --track origin/branchname
Publish and create tracking connection for new local branch:
git push -u <remote> <branch>
Revert changes made to your working copy:
git checkout .
Revert changes made to the index: (i.e., that you have added). Warning this will reset all of your unpushed commits to master!
git reset
Revert a change that you have committed:
git revert <commit 1> <commit 2>
Remove untracked files (e.g., new files, generated files):
git clean -f
Remove untracked directories (e.g., new or automatically generated directories):
git clean -fd
Remove ignored files (e.g., IDE configuration):
git clean -fX
Remove ignored directories (e.g., IDE configuration, target dir)
git clean -fdX
Rebase develop branch to master. (Develop will be checked out):
git rebase master develop
Delete branch with all its commits:
git branch -D <branch-name>
Create patch file of staged changes (ignore whitespace differences, like line endings):
git diff --cached --ignore-space-change >> patch.diff
Clean up list of remote branches
git remote prune <origin>

sources:

Vagrant: frequently used commands

In everyday life you'll probably use the following two commands the most: vagrant halt to shutdown your machine, and vagrant up --provision to turn it on again.

vagrant up
This command creates and configures guest machines according to your Vagrantfile.
vagrant halt
This command shuts down the running machine Vagrant is managing.
vagrant destroy
This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process. After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.
vagrant up --provision
Same as vagrant up, but with forcing the provisioners to run.

source: Vagrant CLI documentation

Wednesday, July 5, 2017

Vue.js Component options

I wanted to collect in one place, what are all the script options that I could use within a Vue Component.

Source documentation:

Let's go with a component template first:
.....
<template>
  <div></div>
</template>

<script>
export default {

  // Options -- Data
  data() {},
  props: {},
  computed: {},
  methods: {},
  watch: {},

  // Options -- Lifecycle Hooks
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {},
  beforeUpdate() {},
  updated() {},
  activated() {},
  deactivated() {},
  beforeDestroy() {},
  destroyed() {},

  // Options -- Assets
  directives: {
    // custom directives
  },
  filters: {},
  components: {},

  // Options -- Misc
  name: "", // only to be used as component option.
  model: { prop: "", event: ""},
}
</script>

<style>
</style>
....

There are some more options that are not available on Component templates:
.....
new Vue({
  el: '#some-element',
  template: '<div v-show="someChildProperty">Child</div>',
  render: function (createElement) {
    return createElement(
      'h' + this.level,   // tag name
      this.$slots.default // array of children
    )
  }
})
....

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

Friday, April 28, 2017

IntelliJ IDEA - frequently used keyboard shortcuts

Ctrl+Shift+A
Find action by name.
Shift+Shift
Search everywhere.
Alt+Enter
Show the list of available intention actions .
Ctrl+Space
Invoke code completion.
Ctrl+H
Type Hierarchy
Ctrl+P
Parameter Info
Ctrl+Q
Quick Documentation
Ctrl+F
Ctrl+R
Find/replace text string in the current file.
Ctrl+Shift+F
Ctrl+Shift+R
Find/replace text in the project or in the specified directory.
Ctrl+Alt+L
Reformat Code
Ctrl+Alt+O
Optimize Imports
Ctrl+Alt+I
Auto-Indent Lines
Shift+F6 
Refactor - Rename...
Ctrl+F6 
Refactor - Change Signature...
Ctrl+Alt+V
Refactor - Extract Variable...
Ctrl+Alt+C 
Refactor - Extract Constant...
Ctrl+Alt+F 
Refactor - Extract Field...
Ctrl+Alt+P 
Refactor - Extract Parameter...
Ctrl+Alt+M 
Refactor - Extract Method...
Ctrl+Alt+N 
Refactor - Inline...
Ctrl+D
Edit - Duplicate Line or Selection
Ctrl+Y
Edit - Delete Line
Ctrl+Shift+J
Edit - Join Lines
Tab
Shift+Tab
Edit - Indent/Unindent  Selection
Ctrl+/
Code Folding - Comment/Uncomment with Line Comment
Ctrl+Shift+/
Code Folding - Comment/Uncomment with Block Comment
Ctrl+W
Ctrl+Shift+W
Selection - Extend/Shrink  Selection
Alt+Shift+Insert OR Mouse Middle Click
Selection - Column Selection Mode (multi line editing)
Alt+Insert
Insert Live Template (see more here)