Skip to content

Instantly share code, notes, and snippets.

View scottashipp's full-sized avatar

Scott Shipp scottashipp

View GitHub Profile
@scottashipp
scottashipp / software-quotes
Created September 27, 2021 20:32
Run strfile on this file to make it usable with fortune. Then just run fortune software-quotes to retrieve a random quote.
Fools ignore complexity; pragmatists suffer it; experts avoid it;
geniuses remove it.
Alan Perlis
%
People think that computer science is the art of geniuses but the
actual reality is the opposite, just many people doing things
@scottashipp
scottashipp / effectivejava.md
Last active January 27, 2022 04:18
Summary of Effective Java by Section / Content Header

Summary of Effective Java, Third Edition (2018)

By Section / Content Header

Front Matter

Contents

Foreword

Preface

@scottashipp
scottashipp / cleancode.md
Last active June 1, 2019 22:25
Clean Code Outline

Summary of Clean Code

By Section Headers

The following are the chapter and section headers of the book Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin, et. al..

Chapter 1: Clean Code

by Robert C. Martin

There will be code

@scottashipp
scottashipp / DataSourceOptions.java
Created January 3, 2019 16:01
Snippet from a popular open-source Java tool showing Optional.isPresent() checking in place of null-checking
Optional<String> pathsStr = get(PATHS_KEY);
if (pathsStr.isPresent()) {
ObjectMapper objectMapper = new ObjectMapper();
try {
String[] paths = objectMapper.readValue(pathsStr.get(), String[].class);
// ... the rest elided
@scottashipp
scottashipp / NullSafeExample.java
Last active January 3, 2019 15:42
Use of Mill's NullSafe class
String zipCode = NullSafe.of(user)
.call(User::addresses)
.call(UserAddresses::billingAddress)
.call(Address::zipCode)
.get();
@scottashipp
scottashipp / MotivatingExample.java
Last active January 3, 2019 15:43
A motivating example for a Java null-conditional
// standard java
String zipCode = null;
if(user != null) {
UserAddresses userAddresses = user.addresses();
if(userAddresses != null) {
Address billingAddress = userAddresses.billingAddress();
if (billingAddress != null) {
zipCode = billingAddress.zipCode();
}
}
@scottashipp
scottashipp / NullConditionalExample.cs
Created January 3, 2019 15:31
Use of Null-Conditional operator in C#
int? length = customers?.Length; // null if customers is null
Customer first = customers?[0]; // null if customers is null
int? count = customers?[0]?.Orders?.Count(); // null if customers, the first customer, or Orders is null
@scottashipp
scottashipp / ProcessTree.java
Created January 3, 2019 15:21
Use of Optional in place of a null-check
final Optional handle = (Optional)JAVA_9_PROCESSHANDLE_OF.invoke(null, pid);
if (handle.isPresent()) {
JAVA_9_PROCESSHANDLE_DESTROY.invoke(handle.get());
}
@scottashipp
scottashipp / WriteList.java
Last active January 3, 2019 14:53
Null variables are practically required in Java
public void writeList() {
PrintWriter out = null;
try {
System.out.println("Entering" + " try statement");
out = new PrintWriter(new FileWriter("OutFile.txt"));
for (int i = 0; i < SIZE; i++) {
out.println("Value at: " + i + " = " + list.get(i));
}
@scottashipp
scottashipp / Solution.java
Last active December 3, 2018 21:41
Leetcode 23. Merge K sorted lists
import java.util.PriorityQueue;
class Solution {
class ListNodeWrapper implements Comparable<ListNodeWrapper> {
int listNumber;
int val;
ListNodeWrapper(int listNumber, ListNode listNode) {
this.listNumber = listNumber;