Posts
Context Refactor
Intro to React Context Intro to React Context, and how to do a quick refactor of an existing useState hook.
Niche? Not really - read on for a quick intro to how to use React Context to share and manipulate data across an app.
You might be designing an app from first principles, or being the lucky duck to architect something very neat and clean from scratch.
But, let’s say you’re doing something else - what if you’re dealing with a pretty big project, and you realize suddenly that you want to share some state across the whole project?
Posts
VS Code Extensions
This can get a bit personal, but maybe I can suggest to you some useful VS Code extensions that I’ve installed and found really helpful.
VS Code Extensions for Javascript and Web Development I’ve been using VS Code for web development for a year. Along the way, some extensions have been really useful, and I’d like to catalogue that.
Obviously, you might find some other extensions that you think are really useful, especially if you’re using other languages or other frameworks.
Posts
React Hooks - Loading Data with useEffect and useState
Using React Hooks for Fun and Profit Let’s say you realize that you want to get something from a database via the API. You know, like a useful website often does.
You want to display the results too, and you’re using React on your front end.
First, get a useState hook running to have a place to store the results of your API call:
import React, { useEffect, useState } from 'react'; const [content, setContent] = useState(''); Then get a useEffect hook running to load the data in asynchronously:
Posts
Javascript Sort
Comparators and Javascript Native Sort - An Introduction Javascript, like many languages, has a native sort function.
Array.prototype.sort() sorts the elements of an array in place, i.e. it mutates the array that it is called on.
The default behavior of how, exactly, the resulting array can be considered ‘sorted’ might not be what you think it is, and the results are so non-intuitive that you should always pass a callback function, specifically a comparator, to the native Javascript sort array method.
Posts
Scripting in Shell and Node
Scripting in Shell and Node I love what I usually call Bash shell scripting, although I think what I really like are POSIX standard shell scripts, Bash is just a specific version of shell with some extensions.
Here’s an example of script that might be useful:
#/parent/childOne/example.sh # Usage: sh example.sh echo "making directories..." DIR_NAME="Project Coolio" #note the space, this makes life hard mkdir -p ../"$DIR_NAME"/mycompany/{OSX,Windows}/debug echo 5221 > ../"$DIR_NAME"/mycompany/log.id Let’s say this script lives in /parent/childOne/, at ~/parent/childOne/example.
Posts
Alien Name Generator: Making a Featured Repl
Making a Featured REPL REPL.it makes it easy to set up programming environments and share them with other people.
I made a REPL for an Alien Name Generator, which you can see, or just visit the website here.
This REPL was created with the help of the community’s feedback. For example, multiple users suggested adding the ability to translate back from “alien” language to English. I added that feature in response to user feedback.
Posts
Kadane's Algorithm
A short history of Kadane’s Algorithm:
Ulf Grenander in 1977 proposed the problem of finding the maximum subarray of an array. Note that if all numbers allowed are positive, the question is trivial - just add them all up! It gets hard if the numbers can be negative. How can this question be solved?
Grenander improved on the brute force algorithm, which would have been cubic O^3, and found an algorithm that solves the maximum subarray sum question in quadradic time, an O^2 solution.
Posts
Tic Tac Toe Memoized
Intro to Part 2 - Memoization and Calculation Hello!
This is Part 2 of a series on building a Tic Tac Toe game in Vanilla Javascript. Part 1 is here
Refactor You can play Tic Tac Toe here.
Originally, my tic tac toe game had the winning board positions as a static value. Today I’ll walk you through the process of how I calculated those values on the fly, and memoized the results to prevent unnecessary work being done in my code.
Posts
Tic Tac Toe - Part One
Hello Tic Tac Toe, a game you may fondly remember playing with pen and paper, can also be played or simulated online with a web page. I have created a site that lets you play tic tac toe online, please check it out.
The REPL is here
Enter the Script In my script.js file, there is some state, and quite a few functions. Let’s go over how that is structured.
Posts
The Case for Reduce
Let’s talk about using the JavaScript Array method reduce instead of a for-loop.
Reduce is a standard Array method, Array.prototype.reduce, that takes several arguments, only the first being required, a function (also known as a callback) that serves as a reducer.
Reducers can be simple, and giving names to reducer functions can make the concise code even clearer and more human friendly.
Let’s do a quick example of using a simple for-loop to get something done.