Skip to content

Instantly share code, notes, and snippets.

slikts /
Last active Jul 24, 2021
Advanced memoization and effects in React

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
losalamosal /
Last active Jun 24, 2021
Deploy a GitHub-based static site to Dreamhost

Before begining, make sure your SSH keys are set so you can ssh to your Dreamhost account.

$ ssh-copy-id -i ~/.ssh/
(you'll need xxxxxx's password here)
$ ssh

On the Dreamhost server you should have a directory for your site (e.g. or (if not, you'll need to make one). You now need to make a git repository for that site (at the same level in the tree) and initialize a bare repo:

eastenluis / map-item.js
Created Dec 6, 2017
Mongoose GeoJSON schema example
View map-item.js
const mapItemSchema = new mongoose.Schema({
name: String,
location: {
// It's important to define type within type field, because
// mongoose use "type" to identify field's object type.
type: {type: String, default: 'Point'},
// Default value is needed. Mongoose pass an empty array to
// array type by default, but it will fail MongoDB's pre-save
// validation.
coordinates: {type: [Number], default: [0, 0]}
View Dokku On Digital Ocean
## Bare Bones
1. Create your droplet, adding the 1-click install dokku app and giving it at least 1GB memory which Dokku will need for deployment, then navigate to your server's IP and complete the process in the dokku form that will exist there. Also be sure you've followed the guide [here]( to set up the various accounts youll need on your ubuntu server correctly before proceeding.
2. SSH into your droplet: `ssh root@droplet-ip`
3. Create your dokku app: `dokku apps:create app-name`
4. By default your app is located at If you want your app to be accessible via the root domain, then just add the root domain as one of your app's domains. `dokku domains:add app-name`.
5. On your local machine, in your project’s Git repository, add your droplet as a remote: `git remote add dokku dokku@droplet-ip:app-name`
6. Dokku will start your node app itself by calling `nmp start` but if you want to modify that create a `Procf
bradley /
Last active Feb 28, 2021
Digital Ocean SSH and Subdomains

Basic Getting Started Ubuntu 16.04

SSH into your server at root:


Crate a new user:

adduser my_username

Make the new user a sudo user:


Aligning images

left alignment

This is the code you need to align images to the left:

<img align="left" width="100" height="100" src="">
nrollr /
Last active Mar 25, 2021
Install MongoDB on Sierra using Homebrew

Install MongoDB on macOS Sierra

This procedure explains how to install MongoDB using Homebrew on macOS Sierra 10.12.
Official MongoDB install documentation: here

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL"
batchFindAll = (model,where,cback,size=10)->
.then (res)=>
total = res
[0..Math.floor(total/size)].reduce (curr,num)=>
count = num*10
curr.then => cback(where,count,size)

Redux Selector Pattern

Imagine we have a reducer to control a list of items:

function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
  switch(action.type) {
    case 'SHOW_ALL_ITEMS':
armw4 /
Last active Jun 19, 2021
Optimizing your react components via redux....shouldComponentUpdate for free and more...

The Beginning's true...redux is smart....smarter than you even know. It really does want to help you. It strives to be sane and easy to reason about. With that being said, redux gives you optimizations for free that you probably were completely unaware of.


connect is the most important thing in redux land IMO. This is where you tie the knot between redux and your underlying components. You usually take state and propogate it down your component hiearchy in the form of props. From there, presentational