Skip to content

Instantly share code, notes, and snippets.

View naifen's full-sized avatar

Jerry G naifen

View GitHub Profile

React.js learning notes

React functional componenets and hooks

Use React memo API to prevent re-renders

In this example, every time you type something in the input field, the App component updates its state and triggers re-renders of the Count component. Use React memo in React Function Components to prevent a rerender when the incoming props of this component haven't changed:

import React, { useState, memo } from 'react';
@naifen
naifen / flatten_array.rb
Created June 17, 2019 23:17
a ruby method that flatten an array with associated test
def flatten_array(ary, result = [])
raise 'Please pass an array as argument' unless ary.kind_of? Array
# if an element in the given array is an array, recursively call flatten_array
# on the element, otherwise push it into the result array
ary.each do |ele|
if ele.class == Array
flatten_array(ele, result)
else
result << ele
@naifen
naifen / powershell-tricks.md
Last active January 22, 2019 13:59
Some useful powershell tricks

Check current driver version for a device, eg radeon

Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like "radeon"}

@naifen
naifen / .rubocop.yml
Created October 7, 2018 06:07
Rubocop config for Ruby 2.5 Rails 5+
##
# .rubocop.yml
AllCops:
TargetRubyVersion: 2.5
Include:
- 'config.ru'
- 'Gemfile'
- 'Guardfile'
- 'Rakefile'
@naifen
naifen / gist:1b2b670a90fdb1114bfcd4b11bf2cf6a
Created April 29, 2018 02:25 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install [email protected]
brew unlink [email protected]
brew link postgresql
@naifen
naifen / docker-cheatsheet.md
Last active August 24, 2016 03:08
docker and docker-compose command cheatsheet
# list docker volumes
docker volume ls -f dangling=true

# rm all docker volumes
docker volume rm $(docker volume ls -qf dangling=true)

# stop all docker containers
docker stop $(docker ps -a -q)