Code snippets for your daily life

Find useful snippets, bookmark and share them with other developers.

Latest Snippets

  • // boolean: in form of a question
    const isVisible = true
    const hasChildren = false
    // constant: a true constant value
    const EULER_NUMBER = Math.E
    const PI = Math.PI
    // string: singular
    const simpleString = 'Hello World'
    const anotherString = 'Lorem ipsum
    // object: mostly singular
    const someData = {...}
    // array: always plural
    const arrayItems = [...].map(item => item)
    // function: combination of verb and noun          
    function getData() {...}
    function findUser() {...}
    // class: first letter is always capital
    class ClassName {...}

    October 4th, 2019

    # Naming convention

    Add to bookmarks

    It's always good to have a naming convetion so you can immediately see if you're working with a class, function or a boolean.

  • const getBottomVisiblity = () =>
      document.documentElement.clientHeight + window.scrollY >=
      (document.documentElement.scrollHeight || document.documentElement.clientHeight)
    // output: true

    October 1st, 2019

    # Get page bottom visibility

    Add to bookmarks

    Returns true if the document height plus the currently scrolled pixel number is larger/equal to the document's content height or rather document height.

    Apply that function to a scroll event listener and you can always check if the page bottom is visible.

  • const arrayToHtmlList = (array, listClass) =>
      (el => (
        (el = document.querySelector('.' + listClass)),
        (el.innerHTML += => `<li>${item}</li>`).join(''))
    arrayToHtmlList(['hello', 'world', '42'], 'classOfTheList')

    September 29th, 2019

    # Append array elements to HTML list

    Add to bookmarks

    This snippet converts all elements of an array to a list of <li> tags and appends them to the list of the given class.

  • const allEqual = array => array.every(value => value === array[0])
    // output: false
    allEqual([42, 1, 'hello'])
    //output: true
    allEqual([42, 42, 42])

    September 27th, 2019

    # Check if all elements of an array are equal

    Add to bookmarks

    The function checks if every element of the array is strictly equal to the first element.

  • # get the process id (pid) of the port
    $ sudo lsof -i :1234
    # use the pid you received a step before and kill the process
    $ sudo kill -9 <PID>

    September 26th, 2019

    # Kill a specific port via Terminal

    Add to bookmarks

    If a port is in use and you need it, use your Terminal to kill the process.