NFS

Setup

Install
$ apt-get update
$ apt-get install nfs-common nfs-kernel-server
Configure exports
$ vi /etc/exports

Example: /data 172.16.16.209/255.255.255.0(rw,insecure,root_squash)

/mnt/backupvm is your directory
172.16.16.209/255.255.255.0 is your network
rw are the permissions
secure – This option requires that requests originate on an Internet port less than IPPORT_RESERVED (1024). This option is on by default. To turn it off, specify insecure

root_squash – Map requests from uid/gid 0 to the anonymous uid/gid. Note that this does not apply to any other uids or gids that might be equally sensitive, such as user bin or group staff.

no_root_squash – Turn off root squashing. This option is mainly useful for diskless clients.

Start services
$ systemctl enable nfs-common
$ systemctl start nfs-common
$ systemctl enable nfs-kernel-server
$ systemctl start nfs-kernel-server

Command Line

List the NFS shares exported by the server: showmount -a <nfsserver>


Components

Exports

man exportssubtree_check root_squash

Located at /etc/exports

exportfs -a – Update list of shared folders

insecure – Helpful when connecting from macOS (resolves Operation Not Permitted message)

Example: /data/documents 172.16.16.0/24(rw,insecure,root_squash)

nfs-common
nfs-kernel-server

fstab Entry

 


Mounting

From macOS client

Finder > Go > Connect to Server > nfs://<nfsservername>:/<sharename>

Terminal > sudo mount_nfs -o resvport <nfsservername>:/<sharename> <mountpoint>


Troubleshooting

Linux NFS-HOWTO Troubleshooting NFS

Error Messages Seen and Resolved (During SetUp of my NFS Server)

RPC: Program Not Registered

Algorithms and Data Structures

dynamic programming

The method of solving problems exhibiting the properties or overlapping subproblems.[1]  Real-world applications that have been solved using dynamic programming: the magnet selection tool in Photoshop uses dynamic programming.[2]

exponentiation by squaring

Also called left-to-right binary exponentiation or square-and-multiply[3].

  1. Right the exponent in binary.  Example 225.  The exponent is 25.  In binary it is 11001
  2. Remove the first binary digit leaving 1001 and then replace each remaining 1 with the pair of letters “sx” and each 0 with the letter “s” to get: sx s s sx (remember, using 1001)
  3. “s” means square, “x” means multiply.  So, we have square mutiply by x, square, square, square, multiply by x where “x” is the base

In general, binary exponentiation (or square-and-multiply as learned in class) will take less than 2log(n)/log(2) multiplications.

There is also a right-to-left binary exponentiation. It is easier to program but takes more storage.[3]

Primality Testing

Fermat, Pierre de

Fermat’s Little Theorem (non-deterministic)if p is prime, then 2p divides 2p-2.

Other Algorithms

Sieve of Eratosthenes (deterministic)

Better to use when you are dealing with a certain range of numbers.

Incrementally testing up to sqrt(n) (deterministic)

Fermat primality test and Miller-Rabin primality test (non-deterministic)

Miller-Rabin has a deterministic variant but you have to balance time complexity and accuracy.

Hashing

A mapping of keys to values in an efficient manner.  Data structure is referred to as a hash-map, hash-table, or dictionary.  Choosing the proper hash function depends on the scenario.

search algorithms

Binary Search: Efficient search on sorted data with time complexity of O(log2N). Continue to divide the portion of the list that could have it in half until it is narrowed down to one possible item.

Depth/Breadth First Search: tree/graph traversing and searching.

Sorting Algorithms

SO Reference

Noteworthy:

Merge sort: When you need a stable, O(N log N) sort, this is about your only option. The only downsides to it are that it uses O(N) auxiliary space and has a slightly larger constant than a quick sort. There are some in-place merge sorts, but AFAIK they are all either not stable or worse than O(N log N). Even the O(N log N) in place sorts have so much larger a constant than the plain old merge sort that they’re more theoretical curiosities than useful algorithms.

Quick sort: When you don’t need a stable sort and average case performance matters more than worst case performance. A quick sort is O(N log N) on average, O(N^2) in the worst case. A good implementation uses O(log N) auxiliary storage in the form of stack space for recursion.

Bucket sort: When you can guarantee that your input is approximately uniformly distributed.

Heap sort: When you don’t need a stable sort and you care more about worst case performance than average case performance. It’s guaranteed to be O(N log N), and uses O(1) auxiliary space, meaning that you won’t unexpectedly run out of heap or stack space on very large inputs.

Counting sort: When you are sorting integers with a limited range.

Others:

Bubble sort, selection sort: When you’re doing something quick and dirty and for some reason you can’t just use the standard library’s sorting algorithm. The only advantage these have over insertion sort is being slightly easier to implement.

Bogosort: In computer science, bogosort (also known as permutation sort, stupid sort, slowsort, shotgun sort, or monkey sort) is a highly inefficient sorting algorithm based on the generate and test paradigm. The function successively generates permutations of its input until it finds one that is sorted. It is not useful for sorting, but may be used for educational purposes, to contrast it with more efficient algorithms.


[1] https://en.wikiversity.org/wiki/Dynamic_programming
[2] https://www.quora.com/What-are-some-real-world-problems-that-have-been-solved-with-dynamic-programming
[3] https://primes.utm.edu/glossary/page.php?sort=BinaryExponentiation

 

Software Engineering

Makefiles

  • http://nuclear.mutantstargoat.com/articles/make/
  • https://www.hackerearth.com/practice/notes/the-make-command-and-makefiles/

Ruby on Rails

Called a Model-View-Controller software design pattern (architecture).  “Traditionally used for GUIs and web apps. Languages like JavaScript, Python, Ruby, PHP, Java, C#, and Swift have MVC frameworks available to them out of the box.”

Computer Architecture Concepts

Task Execution

Concurrency: “The composition of independently executing processes.  Dealing with alot of things at once.  It’s about structure.”

Parallelism: “Simultaneously execution of multiple things, possibly related, possible not.  Doing alot of things at once.  It’s about execution.”

Concurrency vs Parallelism

 

Java

I’ve only ever heard bad things about Java so I have steered clear of it. But, I will tell you one thing, Java’s BigInteger is nice and easy and very powerful for calculations with very large numbers.

Now that I’m spending more time with Java, I wanted to jot down a few things that I’ve learned along the way.

What I like About Java

It’s an Object-Oriented Programming

While I can handle and adapt to a flat structure consisting primarily of variables passed around and functions that have to be created to extend functionality and called to process a selection of data, being object-oriented seems to keep things more modular, cleaner, and extensible.  If given an opportunity to interact with OOP I won’t shy away from it.

Low Effort Requirement to Get a Program Up and Running

If I need to whip something up, I’ll use either Python, Bash, or Java.  If I want to perform simple admin tasks, Bash works just fine.  If I need to perform somewhat more complex HTTP/S requests, Python works well.  If I need more complex structures and decent performance, Java can let you put things together rather quickly.

Command Line Arguments

Still parsing this information myself.  Looks like I ought to try JCommander

Importing Packages

You may run into this when you’re working on a Java project:

SmallProjectThree.java:8: error: package org.bouncycastle.math.ec does not exist

This means your environment is not familiar with a package called bouncycastle.math.ec.  The reason this error is thrown is because I am attempting to do some Elliptic-curve calculations and am using a snippet from im-infamou5 on GitHub.com

In general, to use a non-standard library, you need to find the *.jar file yourself, download it, and drop it in your CLASSPATH (if this doesn’t exist or you want to redefine it, you can do so; see -cp below)

Specific to Bouncy Castle, these are the steps I took.

  1. Download the .jar file from the org’s download page directly.  Now, there are a ton of options available to you on that page.
    1. Trust but verify.  I recommend using signed jar files so you can digitally trust the source.  Once the package has been downloaded check the sha hash.
    2. What JDK is installed on your system?  Your system probably has Java installed (java -version) but the JDK is separate.  Only one Java can exist but several JDKs can exist (in a given environment at a time).  I am currently running Java build 13.0.2+8 and have 13.0.3 and 1.8.0_241 JDK present on my system.  I am downloading JDK 14 and dropping it into the same directory.
      1. $ java -version
        java version "13.0.2" 2020-01-14
        Java(TM) SE Runtime Environment (build 13.0.2+8)
        Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
      2. $ pwd
        /System/Volumes/Data/Library/Java/JavaVirtualMachines
        $ ls
        jdk-13.0.2.jdk jdk-14.jdk jdk1.8.0_241.jdk
    3. Which .jar file do you need?  I looked through the documentation and found that the “provider” had the math.ec library so I need the “provider” .jar
  2. Add the *.jar file to my project’s directory tree.
    1. Download it to the same directory that contains my SmallProject3.java program.
  3. Compile my program using -cp or --classpath
  4. $ javac -cp ./org/bouncycastle/bcprov-jdk14-164.jar SmallProjectThree.java

     

MAKEFILE

An expert in neither Java nor Make dropped this off.

JAVAC=javac
JAVA=java
sources = $(wildcard *.java)
classes = $(sources:.java=.class)

all : $(classes)

run : all
    $(JAVA) PrimitiveRoots

clean :
    rm -f *.class

%.class : %.java
    $(JAVAC) $<

 

Go (as in GoLang)

Environment

GOPATH

Attempting to limit the scope of your Go env, you can define the follow to help you maintain tight control over your app.

GOPATH="$(pwd)/vendor:$(pwd)"
GOBIN="$(pwd/bin"

Modules

Command: go mod download

Requirement: go-1.13+ (Note to self: I’ll have to double-check this)

Purpose: download go module dependencies

Command: go mod vendor

Requirement: go-1.13+ (Note to self: I’ll have to double-check this)

Purpose: create a vendor folder in the main module’s root folder and copy all dependencies into it. After this you may pass -mod=vendor param to the go tool.  Dependencies from the vendor folder will be used to build your app.

*  Despite what others may agree or disagree with, I’m calling it golang because I feel that it really helps search engines and human know they’re looking at the programming language, Go, and not trying to find search results for just “go”.

Groovy & Jenkins

 

Groovy Scripts

How to List Git Branches Dynamically in Jenkins Pipeline Job

I am growing weary of always having to update the list of branches in the choice parameter every time I wish to build a branch that isn’t listed.  I like using the Choice Parameter because it cuts down on a.) typo errors; and, b.) having to type something in each time like you’d have to if you used a String Parameter.  But, an even better option would be to query GitHub for a list of branches and populate the choices dynamically, further removing the user from being required to type anything…ever!

It appears as though I have two general options: 1.) use a plugin that speaks to GitHub directly, like the Git Parameter List plugin; or, 2.) use a groovy script that gives me full control over what is being queried and what is being displayed.

 

Resources

Jenkins is the hub of activity for my day-to-day.  As is Foreman, Proxmox, GitHub Enterprise, and good ol’ physical machines.  We’re not doing anything too complicated with Jenkins, aside from webhook triggers and Groovy libraries.

Here are some helpful resources, to start.

Jenkins Groovy Cheat Sheet