I recently started using Next.js instead of create-react-app (CRA) for building React apps. The main reason is for server-side rendering. I found it a bit tricky to modify the webpack configuration, so I'm sharing how I managed to match some behaviour from CRA. By default, recent versions of CRA let you import foo.module.css in your … Continue reading Next.js with and without CSS modules
Category: code
Dependency Injection Design Pattern in Java: Example
Dependency Injection Design Pattern Program to an 'interface', not an 'implementation'. This is the premise of dependency injection. It goes one step further to allow libraries that use the interface library to not 'depend' on the implementation library even though they depend on the interface library. That is, the implementation can be 'injected' at run … Continue reading Dependency Injection Design Pattern in Java: Example
javascript every language (and country) in every other language
Thank you java for supplying this information:Full lookup:codetonames.jsSome duplicates removed:codetonames.js
retry function for bash
Example:
logging stdout and stderr from within a shell script while still outputting to the console
If you want to send the output of a shell script to files, it's pretty easy: ./script.sh 1> out.txt 2> err.txt If you want to do it within a script, also easy: exec 1> out.txt exec 2> err.txt If you want to send it to the console and files, it's a bit more tricky: { … Continue reading logging stdout and stderr from within a shell script while still outputting to the console
Karger’s [min cut] algorithm in Python
The minimum cut problem is to cut a graph into two disjoint subgraphs by removing a minimum number of edges. For coursera's Algorithms: Part I class, the week 3 assignment was to implement Karger's algorithm. There are many implementations that can be found on the internet, so I'll add mine to the mix: EDIT: code … Continue reading Karger’s [min cut] algorithm in Python
Efficient encrypted backups
Got a place to backup stuff to, but don't trust the backup location with your data? No worries, the script below encrypts your files and directories, making them easy to sync to your backup location. It uses encfs's reverse mode to encrypt your file system. (encfs is normally used to mount a decrypted version of … Continue reading Efficient encrypted backups
Prim’s Algorithm in V^2
Recently, I had a need for the weight of a minimum spanning tree of a graph. Because of the way my graph was represented, I opted for Prim's algorithm to find the weight. The wikipedia article said I could do this in O(V^2) time if I had an adjacency matrix. Since I had a complete … Continue reading Prim’s Algorithm in V^2
Java PriorityQueue with efficient removal
I had a need for a PriorityQueue in Java with an efficient remove(Object) method, but the implementation in the JDK "provides O(log(n)) time for the enqueing and dequeing methods (offer, poll, remove() and add); linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods (peek, element, and size)." The patch … Continue reading Java PriorityQueue with efficient removal