DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

David Hwang
David Hwang

Posted on

5/26 TIL: Dockerfile, apt, C++ Generics, ADT in C

--Docker--
Dockerfile for a Go project


FROM golang:1.15 AS builder

RUN apt update && apt upgrade -y && \

apt install -y git \

WORKDIR /app

# Get install script, run, and make binary

RUN curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh \

&& chmod +x install.sh && sh install.sh && cp ./bin/air /bin/air

Enter fullscreen mode Exit fullscreen mode
  • Always combine RUN apt-get update with apt-get install in the same RUN statement as suggested in the Dockerfile best practices under the 'apt-get' section here: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
  • TheΒ WORKDIRΒ commandΒ is used to define theΒ working directoryΒ of a Docker container. AnyΒ RUN,Β CMD,Β ADD,Β COPY, orΒ ENTRYPOINTΒ command will be executed in the specified working directory.

apt vs. apt-get

  • apt is a subset of apt-get and apt is usually preferred
  • apt provides all the necessary commands for package management so just go with that

apt update vs. apt upgrade

--C++ basics--

Generics in C++


#include <iostream>

using namespace std;

template <class T>

T GetMax (T a, T b) {

T result;

result = (a>b)? a : b;

return (result);

}

int main () {

int i=5, j=6, k;

long l=10, m=5, n;

k=GetMax<int>(i,j);

n=GetMax<long>(l,m);

cout << k << endl;

cout << n << endl;

return 0;

}

Enter fullscreen mode Exit fullscreen mode

Logical data structuresβ€”implemented using physical data structures: arrays or linked lists

  • Stack (linear, LIFO)
  • Queues (linear, FIFO)
  • Trees (non-linear)
  • Graph (non-linear)
  • Hash Table (tabular)

Abstract Data Type (ADT)

  • ADT is a type (or class) for objects whose behavior is defined by a set of value and a set of operations
  • The definition of ADT only describes what operations are to be performed but not how these operations will be implemented, making it abstract
  • List, Stack, & Queue ADTs: https://www.geeksforgeeks.org/abstract-data-types/

--Discrete Math--

Math Theorem Example: an even integer plus an odd integer is another odd integer

Proof:

  • Suppose m is even and n is odd (1. State the assumptions)
  • βˆƒk1 ∈ Z and βˆƒk2 ∈ Z so that m = 2k1 and n=2k2 + 1 (2. Formally define the assumptions)
  • Then, m + n = (2k1) + (2k2+1) = 2(k1+k2) + 1. Let k3 = k1 + k2, and note it is an integer. (3. Manipulation)
  • Hence βˆƒk3 ∈ Z so that m + n = 2k3 + 1 (4. Arrive at definition of conclusion)
  • Thus m + n is odd (5. Conclusion)

Divisibility

  • For n and d integers, d β‰  0, d | n ↔ if βˆƒk ∈ Z such that n = dk
  • When we say d | n, it means n is divisible by d

βˆ€x ∈ D, P(x) β†’ Q(x) where we quantify with specific x values, it uses a single arrow to show implication between two statements

P(x) β‡’ Q(x) with a double arrow is an implication between two predicates; it means the same thing as above

Other Proof Methods:

  • Disproving with Counterexamples
  • Proof by division into cases
  • Proof by contradiction
  • Proof by contrapositive

Top comments (0)

Thank you.

Β 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.