Skip to content

Instantly share code, notes, and snippets.

View taingmeng's full-sized avatar

Meng Taing taingmeng

  • Zendesk
  • Singapore
View GitHub Profile
@taingmeng
taingmeng / Pluralize.kt
Last active October 15, 2017 03:29
Pluralize String with Kotlin Extension
fun String.pluralize(count: Int): String? {
return this.pluralize(count, null)
}
fun String.pluralize(count: Int, plural: String?): String? {
return if (count > 1) {
plural ?: this + 's'
} else {
this
}
@taingmeng
taingmeng / App.js
Last active November 13, 2017 14:14
Badminton Score Tutorial
import React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor() {
super();
this.state = {
players: [
{
name: 'Player 1',
@taingmeng
taingmeng / App.css
Last active November 25, 2017 13:41
Badminton Score Tutorial
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.score-container {
display: flex;
align-items: center;
text-align: center;
@taingmeng
taingmeng / Annyang.js
Last active November 19, 2017 02:40
Badminton Score Tutorial - Part 2
import annyang from 'annyang'
class Annyang {
// 1
isSupported() {
return annyang !== null
}
// 2
start() {
@taingmeng
taingmeng / App.js
Created November 25, 2017 13:55
Badminton Score Tutorial - Part 2 - Final
import React, { Component } from 'react';
import './App.css';
import annyang from './Annyang'
class App extends Component {
constructor() {
super();
this.state = {
players: [
{
@taingmeng
taingmeng / PULL_REQUEST_TEMPLATE.md
Created November 16, 2019 23:15
Create Github default pull request description template for your project

Description

Context

Checklist:

  • Updated tests for this change.
  • Tested the changes locally.
@taingmeng
taingmeng / hasAccessToPhoto.js
Last active November 17, 2019 03:00
Example of bad nested condition
const hasAccessToPhoto = (user, photo) => {
if (photo.privacy !== 'public') {
if (user.role !== 'admin') {
if (photo.userId !== user.id) {
return photo.user.friends.includes(user.id) || photo.taggedUsers.includes(user.Id);
}
}
}
return true;
};
@taingmeng
taingmeng / totalPrice.js
Last active November 17, 2019 03:03
Bad example of magic number
const totalPrice = (value, discount) => {
return ((value * 1.07) - discount) * 1.1;
}
@taingmeng
taingmeng / convertCurrency.js
Last active November 17, 2019 13:04
Example of ambiguous naming
const cc = async (v, b, q) => {
const rate = await currency.fetchRate(b, q);
return v * rate;
};
@taingmeng
taingmeng / whoLikeThis.js
Last active November 17, 2019 07:12
Bad example of not enough test
// whoLikeThis.js
const whoLikeThis = (names) => {
return `${names[0]} and ${names.length - 1} others liked this`;
};
// whoLikeThis.test.js
it('should return the first person name and count of the rest`, () => {