Redux

Once you start working with React in anger, there is a tipping point to be aware of where: the complexity of data flows piles up the same data is being rendered in multiple places the number of state changes blow out Being able to tackle these problems in a single place is where Redux fits in. Contents Contents The Problem Option 1 lift the state Option 2 react context Option 3 Redux A chat with redux Container vs Presentation Components The Redux Principles Actions The Store Immutability Reducers React-Redux React-Redux Provider React-Redux Connect mapStateToProps mapDispatchToProps Redux Setup Async and APIs Mock API API Client Wrappers Redux Middleware Redux Async Libraries Thunks Conditional mapStateToProps Polish (the finer things) Spinner component Status API and feedback Server side validation Client side validation Optimistic deletes Testing Redux Connected Components Action Creators Thunks Reducers Store The Problem Imagine a fairly deep component hierarchy, starting with your top level App component. Deep down the tree, there are two child components that need to access a common piece of data (e.g. customer data). How should these components access the data they require? ...

April 29, 2020 · 21 min

The Go Programming Lang

GOPATH Run, build and install Dependencies Formatting Documentation Structuring a source tree The lang Variables Control structures (if, switch and for) if switch for I/O fmt CLI Args Flags Basic Data Types Type conversion Strings Unicode String literals Numbers Integers Bitwise operations Floating point Constants Pointers Functions Grouped parameters types Variadic functions Multiple return values Named return values Recursion Deferred functional calls Functions as values Function literals (anonymous functions) Passing functions to functions Closures Error Handling Error handling strategies Propagate to caller Retry Log and continue Log and exit pkg/errors Panic and Recover Packages and Libraries Package aliases Imported unused packages for side effects Inspecting a package API Advanced Data Types Arrays Slices Extending slices Creating a slice with make Byte slices Maps Creating maps CRUD (create retrieve update delete) operations with maps Named types (user defined types) Function named type Type aliases Struct Struct embedding Field tags Struct methods Receiver Method Sets Interfaces Interface internals WARNING - dont assign nil variables to interfaces Type assertion Type switches Cool cool cool stdlib Tools Make Vim setup Libraries Data Middleware Web Effective Go is a howto on writing idiomatic Go. ...

October 5, 2019 · 30 min

React

React Development environment Boilerplate Webpack Babel NPM scripts ESLint Production dependencies Development dependencies JSX Components all teh things DOM control Styling Rendering Lists Handling Events State Management Option 1: Binding Option 2: Arrows Passing Parameters Component Composition Passing Data Passing Children (passing down JSX) Three Rules about State Raising and Handling Events between Components Passing Object props Controlled Components Synchronising Components Stateless Functional Components Destructuring Data (Arguments) Functional components Class components Life cycle Hooks Phase 1 the birth phase (mount) Phase 2 the update phase Phase 3 the death phase (unmount) Effects (hooks) Debugging React Router Testing Jest React Test Utils Enzyme Production Redux store config Webpack Setup npm scripts Troubleshooting React React is a JavaScript library for building dynamic and interactive user interfaces. ...

May 5, 2019 · 31 min

Go Web Apps

A quick tour of doing web with golang, all living off the land with Go’s built-in standard library. Packages Working example, where the web server and templating code in source file $GOPATH/src/github.com/bm4cs/gotime/web/server.go. It does lots of things, but exports function StartServer (upper case first character means publically exported). package web func StartServer() { ... } The main func in $GOPATH/src/github.com/bm4cs/gotime/myapp/app.go can import the web package: import ( "github.com/bm4cs/gotime/web" ) func main() { web.StartServer() } Handling Requests The http package from the standard library, provides a ton a out of the box functionality. Writing Web Applications on golang.org is a very pragmatic guide. ...

April 28, 2019 · 7 min

Packet Analysis Basics

An evolving list of resources around packet analysis tips and tricks. Terminology Cheat sheets Anatomy of a Packet OSI Model Layers Link Layer Ether Type Fields Network layer Transport layer Tools Wireshark (and tshark) tcpdump Useful switches Examples Real world use-cases netsniff-ng Analysis Terminology SOC, or Security Operations Center, is a central location composed of leading edge tools, technology and peeps (intel gatherers, analysts) that deals with security issues at an organisational and technical level. IDS, or Intrusion Detection System, is a device that monitors network traffic for threats to the environment, proactively alert the SOC analyst of potential problems. IPS, or an Intrusion Prevention System, is more sits inline, and can take active or passive mitigation actions. SIEM, or Security Information and Event Management, is all about the collection and aggregation of alerts and logs for event tracking, retention and correlation from multiple hosts. Cheat sheets SANS TCP/IP and tcpdump Pocket Reference Guide RFC 790 Assigned Internet Protocol Numbers RFC 791 Internet Protocol Anatomy of a Packet OSI Model Layers 7: application: HTTP, FTP, DNS 6: presentation: SSL, JPEG 5: session: SQL, SCP, NetBIOS, SOAP 4: transport: TCP, UDP 3: network: IPv4, IPv6, ICMP 2: data-link: PPP, ARP, CDP 1: physical: Ethernet, Bluetooth Layers 2-4 will be of primary interest. ...

January 15, 2019 · 11 min

Beyond Compare

Installation on Linux is well documented. wget https://www.scootersoftware.com/bcompare-4.2.4.22795.x86_64.rpm su rpm --import https://www.scootersoftware.com/RPM-GPG-KEY-scootersoftware yum install bcompare-4.2.4.22795.x86_64.rpm On my Fedora 27 box, I found the launcher bash /usr/bin/bcompare exits with a return code of 1, if the linker cannot resolve all dependencies. BC_LIB=/usr/lib64/beyondcompare export BC_LIB EXEC=$BC_LIB/BCompare #check to see if we have all of the shared libraries. CHECK=`ldd $EXEC | grep "not found" | wc -l` if [ "$CHECK" -ne "0" ]; then echo Some Shared Libraries were not found ldd $EXEC exit 1 fi Dumping out the shared libs BCompare depends on: ...

April 21, 2018 · 2 min

make

A small make orientation guide. make is a versatile task runner, its core competency is in creating files from other files Make essentials Equal signs Built-in variables Phony targets C specifics Custom variables Implicit variables Example Makefiles Make essentials make generates files from other files, using recipes, the syntax is as follows. Please note, thanks to POSIX standardisation the recipe MUST be indented with a tab (not spaces): target_file: prerequisite_file1 prerequisite_file2 shell command to build target_file (MUST be indented with tabs, not spaces) another shell command (these commands are called the "recipe") Unless you specify otherwise, Make assumes that the target (target_file above) and prerequisites (prerequisite_file1 and prerequisite_file2) are actual files or directories. You can ask Make to build a target from the command line like this: ...

October 9, 2016 · 7 min

Architecture

A collection of software concepts I plan to apply to some up coming projects. Some fundamental philosophies: Automation everywhere. A clean (agnostic) contract with the underlying operating system, promoting portability between execution environments. Can scale without major changes to tooling, architecture or development. Smallest possible delta between development and production, enabling continuous integration. Deployment Processes are first class citizens. Execute the application as one or more stateless processes. Model process types explicitly, e.g. HTTP requests might be handled by a web process, while long running backend tasks by a worker process. Always rely on the operating systems user-space process manager (e.g. systemd, Upstart) to manage output streams, respond to crashed processes and handle user initiated restarts and shutdowns. Concurrency; Physical distribution and clean contract with operating system, e.g. containers (e.g. docker). Versioning; the ability to deploy and hotswap versions side by side. Pluggable; ability to snap modules into architecture (punch through all layers), see attached resources under backing services. Store all runtime configuration as environmental variables. They are a language and OS agnostic standard, and unlike other config options such as Java System Properties, are not accidentially added into the source code repo. The array of process types and number of processes of each type is known as the process formation. ...

July 13, 2016 · 3 min

soapUI mock bug

Today I stumbled onto interesting soapUI quirk, involving a combination of mock services, SOAP 1.2 and multipart message definitions. In essence, the soapUI mock service will always return an HTTP 500, with the following response: {% highlight xml %} <soap:Envelope xmlns:soap=“http://www.w3.org/2003/05/soap-envelope"> soap:Body soap:Fault soap:Code soap:ValueServer</soap:Value> </soap:Code> soap:Reason <soap:Text xml:lang=“en”>Missing operation for soapAction [http://services.net.bencode/wsdl/2016/06/01/retrievecoolnesslevelrequest] and body element [{http://services.net.bencode/wsdl/2016/06/01}retrieveCoolnessLevelRequest] with SOAP Version [SOAP 1.2]</soap:Text> </soap:Reason> </soap:Fault> </soap:Body> </soap:Envelope> {% endhighlight %} Sigh. Thankfully some legend known as fyerf posted a solution on the smartbear community forums. ...

June 1, 2016 · 3 min

Classloaders

First some kudos and credits to the below. None of the material in this post is original, and I have documented it for my personal learning. Please refer to the below original (and superior) articles. ZeroTurnaround’s Jevgeni Kabanov awesome and most practical Do You Really Get Classloaders? Oracle’s A Sundararajan Understanding Java class loading All the way from 1996 by Chuck Mcmanis The basics of Java classloaders Hello java.lang.ClassLoader A Java class is loaded (i.e. born into the JVM) by a concrete implementation of java.lang.ClassLoader. If a class must be class loaded, what loads the java.lang.ClassLoader class itself (i.e. who loads the loader)? It turns out that there is a bootstrap classloader wired into the JVM. The bootstrap loader loads java.lang.ClassLoader in additional to many other Java platform classes (e.g. java.lang.*) into memory. The essential API: ...

April 20, 2016 · 11 min