Category Archives: Cheat sheets - Page 2

My default ports cheat sheet

I usually come in contact with many systems and servers that all have many different ports. Some I remember and some I don’t, so I put them here for easy access 🙂

  • DBs:
    • MySQL: 3306
    • PostgreSQL: 5432
    • MariaDB: 3306
    • Mimer SQL: 1360
    • OracleDB: 1521
    • IBM DB2: 50000
    • Pervasive SQL: 3351 (transactional)/1583 (relational)
    • SQL Server: 1433
  • Java Frameworks
    • Spring framework: 8080
    • Play! framework: 9000
  • Javascript Frameworks:
    • NextJS: 3000
    • Angular: 4200
    • Vue: 8080
  • Mule
    • HTTP Listener Configuration: 8081
  • WebMethods
    • IS: 5555
    • Diagnostics: 9999
    • MWS: 8080
  • ActiveMQ
    • AMQP: 5672
    • OpenWire: 61616
    • MQTT: 1883/8883(SSL)
    • STOMP: 61613
    • Web interface: 8161
    • WebSocket: 61614
  • IBM MQ
    • Queue Manager: 1414
    • AMQP: 5672
    • MQTT: 1883
  • Server:
    • HTTP: 80
    • HTTPS: 443
    • SSH: 22
    • FTP: 21
    • SMTP: 25 (legacy)/587
    • SMTPS: 465
  • Misc web applications
    • Webmin: 10000

My Kotlin features cheat sheet

Kotlin is a new and quite exciting language for both mobile and backend development. It has many nifty constructs. This is my Kotlin features sheet cheat that I will use whenever I need to switch from another language and to Kotlin. Maybe it can help you too 🙂

    // Let's start with a HelloWorld example
    println("Hello Kotlin!")

Variables

    // Immutable variables (only getters are provided)
    val readonly = 10

    // Mutable variables (getters and setters are provided)
    var mutable = "Hello"
    mutable = "Hello again"

    // Explicit typing
    val student: Student = Student
    val year: Int = 49

    // Implicit typing
    val student = Student
    val year = 42

    // Variable destruction
    val (model, color, price) = car
    println("I have a $color $model that set me back $price SEK")
    // Ex. "I have a red S60 that set me back 250 000 SEK"

String concatenation

    // 'In string' concatenation
    println("My daughter is $readonly years of age")
    // Ex. "My daughter is 10 yeas of age"

    // 'In string' concatenation with string functions
    println("In ten years my daughter will be ${readonly.plus(10)}")
    // Ex. "In ten years my daughter will be 20"

Switch statement

    // Kotlin switch
    var x = 23
    when (x) {
        in 1..10 -> println("x is between 1 and 10")
        !in 10..20 -> println("x is not between 1 and 10")
        else -> println("default branch")
    }

NULL

    // Mark variables that can be null
    val name: String  = "Niklas"
    var work: String? = "Goverment"

    name = null // NOT allowed     
    work = null // Allowed
    

Spread operator

    // Spread operator
    val subscriptions = arrayOf("subscription a", "subscription b")
    val hardware = arrayOf("iPhone 12", "iPhone X")
    val shoppingCart = arrayOf(*subscriptions, *hardware)
    // shoppingCart: 
    // ["subscription a", "subscription b", "iPhone 12", "iPhone X"]

Range

    // Range operator
    for (x in 1..10) {
        println(x)
    }
    // 12345678910

Pair

    // Pair object
    val hands = "Left" to "Right"
    println(hands.first)  // "Left"
    println(hands.second) // "Right"

Check variable type

val model = "Volvo"
val price = 123000.50
val cars: List<any> = listOf(model, price)

for(car in cars) {
  when (car) {
    is String -> {
      println("Model: $car")
    }
    is Double -> {
      println("Price: $car")
    }
    else -> {
      println("Not an attribute")
    }
  }
}

Short function syntax

fun sum(a: Int, b: Int) = a + b
println(sum(2, 4)) // 6

Default arguments

fun printWO(productId: Int, amount: Int = 1, by: String = "mail") {
  println("$amount of $productId by $by")
}

printWO(123456)             // "1 of 123456 by mail"
printWO(123456, 10)         // "10 of 123456 by mail"
printWO(123456, 10, "DHL")  // "10 of 123456 by DHL"

Data class

data class Phone(var model: Int, val color: String)

val phone = Phone(123456, "Purple")

println(phone)       // Phone(model=123456, color=Purple) - toString()
println(phone.model) // 123456 - Built in getters
phone.color = "Blue" // Built in setter
println(phone)       // Phone(model=123456, color=Blue)

val (model, color) = phone // Destructuring data classes

Singelton

object MySingletonClass {
  init {
    println("Hello World!")
  }
  var name = "I a Singelton"
  fun printName(){
    println(name)
  }
}

fun main() {     
    MySingletonClass.printName()  // "I a Singelton"
}

My Git cheat sheet

INIT

Init an empty Git repository or reinitialize an existing one

git init

Clone a repository

git clone https://mygitbucket.com/niklas/my_project.git

Pull in new changes from remote

git pull

Do a dry-run fetch to see what is comming

 git fetch --dry-run

BRANCH

Create a branch locally and checkout the branch

git checkout -b <name of branch>

Push the branch to remote

 git push origin <name of branch>

Delete local branch

git branch -d <name of branch>

Delete remote and local

git branch -D <name of branch>

Show all branches

 git branch -a

List all remotes

git remote -v

Rename a local branch that you have checked out

git branch -m <new name>

Rename a branch you have not checked out

git branch -m <old name> <new name>

SUBTREE

Add a remote subtree to your project. ‘common’ is here the name of the subtree

git remote add common https://mygitbucket.com/niklas/my_project.git

Do a ‘common pull’ i.e. pull a remote branch into to subtree. ‘common’ is here the name of the subtree (and folder)

git subtree pull -P common common my-subtree-branch --squash

LOG

Pretty print log with oneline

git log --pretty=oneline

Git log with graph

git log --all --decorate --oneline --graph

Check commits only in the current branch (descendent to master)

git log master..

Check commits that differ between branches (descendent to other branch)

git log master..<name of branch>

PATCH

Create patch files for every commit in a interval of SHA’s

git format-patch <start SHA>..<stop SHA>

HEAD and other short codes work too
Create ONE patch file for all commits in the last 10 commits (from HEAD and back)

git format-patch -10 HEAD --stdout > my.patch

Apply a patch

git apply my.patch

STASH

Show the content of your current stash

git stash show

Show a diff of the content of your stash and current code base

git stash show -p

Stash all uncommited modifications

git stash

Apply last saved stash to your current code

git stash apply

Apply last saved stash to your current code AND delete the stash

git stash pop

Manually delete the stash

git stash drop

TAG

List all tags

git tag

Create a “lightweight” tag

git tag <tag name> <SHA*>

* SHA is optional. Without it you will tag the place you are at
Create a “heavyweight” tag

git tag -a <tag name> -m <message> <SHA*>

* SHA is optional. Without it you will tag the place you are at
Remove a tag

git tag -d <tag name>

MISC

List all commits waiting to get pushed

git cherry -v

Disable ssl verification on a specific domain

git config --global http."https://git.niklasottosson.com/".sslVerify false

Remove folder in Git and leave folder intact on disc

git rm -r --cached <folder>

-r is needed for folders (not files)
–cached is the magic the leaves the folder on disc and only removes it from Git