Skip to content

Instantly share code, notes, and snippets.

View samanthaming's full-sized avatar

Samantha Ming samanthaming

View GitHub Profile
@samanthaming
samanthaming / 23-improvement-with-guard-pattern.js
Last active July 9, 2018 04:37
Code Tidbits: #23 No Else Return (Medium Post)
function calcPercentage(number) {
// Guard #1: Stop execution if it's not a valie number
if(typeof number !== 'number') {
return 'Please enter valid whole number';
}
// By this point, you know if will be a valid number
// Guard #2: Stop execution if number is greater than 1
if (number > 1) {
@samanthaming
samanthaming / 23-example-with-nested-if-else-statements.js
Last active July 9, 2018 17:39
Code Tidbits: #23 No Else Return (Medium Post)
// ❌ You can skip the else block
function calcPercentage(number) {
// Check if valid number
if(typeof number === 'number') {
// Another check: only do calculation number is less than 1
if (number > 1) {
return 'Number must be less than 1';
} else {
@samanthaming
samanthaming / 23-no-else-return.js
Last active July 9, 2018 17:39
Code Tidbits: #23 No Else Return
// ❌ You can skip the else block
function hello(name) {
if(name) {
return '👋'
}
else {
return '👻'
}
}
@samanthaming
samanthaming / rails_cheetsheet.md
Last active April 7, 2018 21:16
New Rails Project Cheat Sheet

New Rails Project Cheat Sheet

Author : Samantha Ming
Date : February 03, 2016

Note : In Atom, click on 'Packages' --> 'Markdown Preview'.
This allows you to see these notes with markdown formatting ​

New Rails Project

  1. rails new __<project name>__ -d postgresql -T
  • Generates a new rails project folder in the current folder