linicks.dev

linicks.dev logo

Hello, my name is Nicholas Wilcox (he/him). You can call me Nick.

I am a software engineer based in Austin, TX. My hobbies and interests include tennis, baking, media/tech criticism, mathematics, and “creative coding”. This website is simply another blog/portfolio.

I am primarily a TypeScript developer who specializes in full-stack web applications. You can find me and most of my work on GitHub @nicholas-wilcox, and you can read my blog here. I also maintain the Stella's Stunners website at mathstunners.org.

On the left, you can see my recent top albums on my Last.fm account as well as my RSS feed.

TypeScript Helper Functions for Sorting

2 days ago

I'm not a huge fan of the Array.sort() method in JavaScript. When I want to sort an array of some random data type based on non-trivial criteria, I find it tedious to write the body of the compareFn argument to derive a comparable value from each of two arguments, compare those values myself, and then return -1, 1, or 0 as appropriate.

Below are some helper functions I like to use when sorting complicated data in TypeScript. The first is a compare() function that takes care of returning -1, 1, or 0 based on the two input values, and the second is a generic sortBy() function that accepts an array and a function to derive a comparable value from each item in the array.

export function compare(a: number, b: number): number;
export function compare(a: string, b: string): number;
export function compare(a: any, b: any) {
if (a < b) {
return -1;
} else if (a > b) {
return 1;
} else {
return 0;
}
}

export function sortBy<T>(array: T[], compareBy: ((arg: T) => number)): T[];
export function sortBy<T>(array: T[], compareBy: ((arg: T) => string)): T[];
export function sortBy<T>(array: T[], compareBy: ((arg: T) => any)) {
return array.sort((a, b) => compare(compareBy(a), compareBy(b)));
}

Some notes:

  • I've added function overloads so that the compare() function can only be used to compare either a pair of numbers or a pair of strings. Likewise, the sortBy() function has overloads that only accept compareBy arguments which return either numbers or strings.

  • The sortBy() function passes the return value of array.sort(). This means that sortBy() sorts arrays in place and returns a reference to the input array. You may wish to implement a toSortedBy() function that uses Array.toSorted().

Date Format Selector

13 days ago

Some time ago, I created a small application with interactive form controls that fed into the Date.toLocaleString() function. I generally prefer standardized functions over third party dependencies, but I found it hard to experiment with the Date.toLocaleString() function and build an intuition for using it.

The result of my effort is the Date Format Selector, which you can find hosted on GitHub Pages at https://nicholas-wilcox.github.io/date-format-selector/. You can also find the source code here.

Read More

Site Update

16 days ago

I finally got around to refining my website's layout. I still like the overall structure, but it was terrible on medium sized viewports.

I put too many styles in the root layout, and I needed to pull that out into a separate component that could be configured differently depending on whether there was any content in the sidebar portion. (There's a lot about how Next.js renders layouts that affected my development here.)

Anyway, I've also worked on including code snippets into my blog posts. I don't see myself writing full-fledged tutorials anytime soon, but I'd certainly like to show some code I've written and talk about it. 😊

Christmas Cookies

1 month ago

I find it difficult to buy gifts for people, especially for the holidays, so this year I decided to bake a bunch of cookies and give out cookie boxes along with some copies of the new Puzzmo book. This worked out well, because in addition to two cookie boxes I gave to coworkers, I had four more boxes worth of cookies to go with four books to be gifted to four couples in my girlfriend's family (including us 😉).

Four different kinds of cookies are piled on top of two white plates. The left plate has cookies with peanut butter and chocolate, and the right plate has cookies with spices like cinnamon and gochujang.

Pictured above are more of the same cookies I made for a party with our D&D group to celebrate my girlfriend coming back home from Switzerland. The recipes used are:

  1. King Arthur Baking Company's peanut butter cookies (recipe link), to half of which I added some Hershey's kisses.

  2. Eric Kim's gochujang caramel cookies (recipe link). I've made these cookies around ten times by now, and they are a crowd favorite every time. I've become very methodical in how I distribute the gochujang mixture into the cookie dough, rolling the dough out, spreading the gochujang, and folding it a few times before chopping and rearranging chunks of layered dough.

  3. Jesse Szewczyk's chocolate and vanilla swirl cookies, which you can find in his book Cookies: The New Classics. My girlfriend's sister actually got this for me for Christmas, and it immediately became my favorite cookbook.

  4. Finally there are some snickerdoodle shortbread cookies, also from Jesse Szewczyk's book, which were also a favorite among my taste testers.

Here we go again

1 month ago

Trump is re-elected, cohost is set to finally disappear at the end of the year, and my attempts to "do everything myself" with respect to personal web development blew up in my face. I'm no longer an idiot who tries to self-host an open-source CMS to store blog posts.

On the bright side, my long-distance relationship is soon to no longer be long-distance. My girlfriend and I are both very excited to hibernate over the holidays together and get married next year. My parents still don't approve of our relationship, but at least they're sorry they weren't upfront about that. 🤷

Not sure what the future holds, but overall I want to take my personal projects less seriously and take some time to reassemble my portfolio in a way that blends into an RSS feed.