28 February 2017

Git | Github | Summary and get started

Quick setup

  • Install git, sudo apt-get install git
  • Create Github account
  • In terminal, generate SSH key cd ~/.ssh && ssh-keygen leave passphrase empty, just press enter until the key is created
  • While still in ssh directory, cat id_rsa.pub and copy the entire key
  • Go to your Github setting, SSH and add SSH. paste the key in the key field. Give it a proper name and save
  • Go back to terminal, setup username and email on git git config --global user.name "john" and git config --global user.email "john.doe@gmail.com" Remember the username and email address muss be the same as the ones used for Github account
  • Go back to Github, create a new repository.
  • Now go to the folder of your application. cd /path/of/your/application and run these command
  • git init
  • git add -A
  • git commit -m "any message e.g. 'my first commit'"
  • Add your ssh URL or copy paste from your Github repository page git remote add origin ssh://login@IP/path/to/repository
  • git push -u origin master

27 February 2017

Javascript | Important functions

  • document.querySelctor('.class_name') using query selector you can grab the html tags by its class
  • example of query selector and event listener within a module
    'click' in above example is the type of listener. You can find any kind of listener on this event reference
  • To add an event listener to any key of a keyboard e.g. 'Enter' (13) key, you can do it like this:
  • change keyCode to any code of the keyboard.
    You can find the code of any key of your keyboard from keycode.info

Important concept or features in programming languages.

Ternary operator

Javascript: var result = (condition) ? (value1) : (value2) ; in this code, the 'var result' will have either 'value1' or 'value2' depend on the condition provided.

Javascript | Basic Knowledge

IIFE

IIFE or 'immediately invoked function expression' is basically an anonymous function wrapped in parenthesis.

add function is private and publicTest is a public function
variable x is still exist even though the anonymous function has already returned. This is possible thanks to the power of 'closure'. All variables inside the IIFE are private and the functions inside the return statement are public.
IIFE can also have arguments like this:
Go to browser console and call 'hello' to see the output

Closures

In Javascript you can have nested functions or function inside a function. The inner functions will have access to all variables of the parent function. This feature, combined with IIFE build another Javascript feature called 'closure'.

Modules

Javascript doesn't natively support classes. To implement classes in Javascript, we use modules. To create a module, we combine self-invoking function (IIFE), encapsulation and closures altogether
Three modules in an application. The third module connected the other modules

Callback function

Callback function is basically a function that is passed to another function as a parameter or an argument. Do not attach the ( ) (function brackets) to the callback function, because the function will be called only if the parent function is called. So the calling process is done by the parent function. 
ctrlAddItem is passed as parameter. No function brackets needed.

24 February 2017

How to access your windows documents folder from the ubuntu bash

  1. make sure you are in root. cd ~
  2. type in cd /mnt and ls to list the content
  3. Now you can go to the volume where your data stored using cd path/../
  4. To go to 'Documents' from root, cd /mnt/c/Users/YourUserName/Documents

How to install Ubuntu linux bash on windows 10

As developer, it sometimes easier to use bash to do some process. e.g. it's easier to install Git from the bash and also it's easier to commit a file or create and delete a branch from the command line.

Steps:
  1. Go to start >> settings >>  Update & security
  2. Go to For developers and active the Developer mode radio button. 
  3. Go to Programs and Features >> Turn Windows features on or off
  4. Select the check box on Windows Subsystem for Linux(Beta)
  5. Reboot your computer
  6. To use the bash, go to start, type in "Ubuntu" or "bash"

22 February 2017

Python | Basic Syntax And Rules

Indentation

  • Very important! in Python indentation is relevant! see this examples:
  • Indentation is correct!
    Wrong indentation gives different result

Operators

  • To check if one variable is exist in another variable, use in
  • To check if a variable is equal to a specific value, use is
  • in and is
  • In python, 5 ** 3 means 5 to the power of 3 and it will return 125 as a result
  • In python and most of programing languages, \n means 'new line'. But how if we want to print out a path like this "C:\Arkad\Desktop\notepad"? if you write print("C:\Arkad\Desktop\notepad") you'll get this result:
  • \n means newline
    To avoid this, put 'r' before the quote sign. like this print(r"C:\Arkad\Desktop\notepad")
    put 'r' before the quote sign
  • In Python you can do 'multiplication' operations with strings name = "John" and name * 5 this will return "John John John John John"
  • To create an array or a list, variable = [12 , 15 , 10 ]
  • To add elements to a list, variable + [10 , 9]
  • how to add items to a list
  • In Python, colon operator like this variable[0:2] will return the first and second elements of the list. it means index '2' is not included. This is different to e.g. Matlab where an array is started with number '1' and the colon operator include the number coded

String format

  • The number inside the curly brackets refers the index of the arguments inside the round brackets. '0' means the first argument etc.
  • '{2}' means 'third argument'

Looping

  • For loop in Python can be very flexible. Look at this code: