Showing posts with label cheatsheet. Show all posts
Showing posts with label cheatsheet. Show all posts

Sunday, December 6, 2020

Note: Functional Interfaces in Java

 (source: Java SE 8 for the Really Impatient: Programming with Lambdas - 3.3. Choosing a Functional Interface)

Common Functional Interfaces

Functional Interface

Parameter Types

Return Type

Abstract Method Name

Description

Other Methods

Runnable

none

void

run

Runs an action without arguments or return value

Supplier<T>

none

T

get

Supplies a value of type T

Consumer<T>

T

void

accept

Consumes a value of type T

chain

BiConsumer<T, U>

T, U

void

accept

Consumes values of types T and U

chain

Function<T, R>

T

R

apply

A function with argument of type T

compose, andThen, identity

BiFunction<T, U, R>

T, U

R

apply

A function with arguments of types T and U

andThen

UnaryOperator<T>

T

T

apply

A unary operator on the type T

compose, andThen, identity

BinaryOperator<T>

T, T

T

apply

A binary operator on the type T

andThen

Predicate<T>

T

boolean

test

A Boolean-valued function

and, or, negate, isEqual

BiPredicate<T, U>

T, U

boolean

test

A Boolean-valued function with two arguments

and, or, negate

Functional Interfaces for Primitive Types

p, q is int, long, double; P, Q is Int, Long, Double

Functional Interface

Parameter Types

Return Type

Abstract Method Name

BooleanSupplier

none

boolean

getAsBoolean

PSupplier

none

p

getAsP

PConsumer

p

void

accept

ObjPConsumer<T>

T, p

void

accept

PFunction<T>

p

T

apply

PToQFunction

p

q

applyAsQ

ToPFunction<T>

T

p

applyAsP

ToPBiFunction<T, U>

T, U

p

applyAsP

PUnaryOperator

p

p

applyAsP

PBinaryOperator

p, p

p

applyAsP

PPredicate

p

boolean

test

Thursday, January 10, 2019

CSS: frequently used selectors

Basic selectors 

Wildcard selector: selects all elements
* {}
Type selector: selects all elements of the given type
div {}
Attribute selector ([]): selects all elements that has the given attribute
[src] {}
ID selector (#): selects the element with the given ID attribute
#menu {} /* or [id="menu"] {} */
Class selector (.): selects all elements with the given class attribute
.centered {} /* or [class~="centered"] {} */

Selector grouping

selector grouping (,): enables to specify common values in one place
div, #menu, .centered {}

Selector chaining

Selector chaining
div.#menu.centered[name="Menu"]:first-child::first-letter {}

Attribute value selectors

[attribute="value"] selector: selects all elements with the specified attribute and value
[target="_blank"] {}
[attribute~="value"] selector: selects all elements whose attribute value contains the specified whole word.
[title~="flower"] {}
[attribute|="value"] selector: selects all elements whose attribute value starts with the specified value, the value being a whole word or the first part of a hyphenated word.
[class|="top"] {}
[attribute^="value"] selector: selects all elements whose attribute value begins with the specified value. (like in regex)
[class^="top"] {}
[attribute$="value"] selector: selects all elements whose attribute value ends with the specified value. (like in regex)
[class$="test"] {}
[attribute*="value"] selector: selects all elements whose attribute value contains the specified value.
[class*="te"] {}

Selector combination

Descendant selector (space): matches all elements that are descendants of a specified element
div p {}
Child selector (>): selects all elements that are the immediate children of a specified element
div > p {}
Adjacent sibling selector (+): selects all elements that are the adjacent siblings of a specified element
div + p {}
General sibling selector (~): selects all elements that are siblings of a specified element
div ~ p {}

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:

Monday, September 26, 2016

Mercurial Hg - frequently used commands

hg clone
copy a locally non-existent repository from remote repository
hg pull --rebase
pull changes from remote to local, rebase local commits on new head
hg pull -u
pull changes from remote to local, update working dir to new head
hg update [optionally: where]
updates working dir to head or specified revision
hg st
hg status
list status of the working directory
hg commit
commit changes
hg commit --amend
amend last commit
hg push
push to remote repository
hg rebase -s [what] -d [where]
rebase one commit and its children to another commit -- commits specified by [commit number]
hg strip --keep [what and its children]
remove a commit and its children, and keep the changes in the working directory
hg strip [what and its children]
delete a commit and its children (will not keep changes!)
hg purge
cleans the working directory
hg shelve
hg unshelve
shelve or unshelve changes in the working directory

Tuesday, September 20, 2016

Docker: frequently used commands

list all images:
docker images
list all containers:
docker ps -a
stop all running containers:
docker stop $(docker ps -a -q)
remove all containers:
docker rm $(docker ps -a -q)
force (-f) remove all running or non-running containers:
docker rm -f $(docker ps -a -q)
remove all images:
docker rmi $(docker images -q)
build docker image with the tag tutorial/webapp:latest from the path .:
docker build -t tutorial/webapp:latest .
download a docker image from the docker hub:
docker pull tutorial/webapp:latest
run the image tutorial/webapp with the specified --name, in the background (-d), exposing inner port 8080 on 80 (-p) and setting an environmental variable (-e):
docker run --name tutorial -d -p 80:8080 -e "ENV_VAR=env-var" tutorial/webapp
run bash console inside the container:
docker exec -it nameofthecontainer /bin/bash
build a docker image from a Dockerfile in the current directory:
docker build --tag my_image .