Skip to content

Instantly share code, notes, and snippets.

@ynwd
ynwd / open_close.go
Created January 31, 2022 15:00
SOLID: prinsip open/closed di golang
package main
import (
"fmt"
"math"
)
type tanah interface {
luas(size float32) float32
}
@ynwd
ynwd / sebelum_refactor.go
Created January 31, 2022 14:34
SOLID: single responsibility principle di golang
package main
import (
"fmt"
"golang.org/x/text/currency"
"golang.org/x/text/language"
"golang.org/x/text/message"
"golang.org/x/text/number"
)
@ynwd
ynwd / App.js
Created January 27, 2022 09:23
node.js rest api and websocket server with react client
import React from 'react'
import useWebSocket, { ReadyState } from 'react-use-websocket'
function getStatus(readyState) {
const connectionStatus = {
[ReadyState.CONNECTING]: 'Connecting',
[ReadyState.OPEN]: 'Open',
[ReadyState.CLOSING]: 'Closing',
[ReadyState.CLOSED]: 'Closed',
[ReadyState.UNINSTANTIATED]: 'Uninstantiated',
@ynwd
ynwd / App.js
Last active January 27, 2022 01:33
server & react client websocket
import React from 'react'
import useWebSocket, { ReadyState } from 'react-use-websocket'
function getStatus(readyState) {
const connectionStatus = {
[ReadyState.CONNECTING]: 'Connecting',
[ReadyState.OPEN]: 'Open',
[ReadyState.CLOSING]: 'Closing',
[ReadyState.CLOSED]: 'Closed',
[ReadyState.UNINSTANTIATED]: 'Uninstantiated',
@ynwd
ynwd / App.js
Created January 24, 2022 02:40
react useCallback
import { useState, memo, useCallback } from "react"
function todos({ todos, addTodo }) {
console.log("child render")
return (
<>
<h2>My Todos</h2>
{todos.map((todo, index) => {
return <p key={index}>{todo}</p>
})}
@ynwd
ynwd / App.js
Created January 24, 2022 01:56
react memo
import { useState, memo } from "react"
function todos({ todos }) {
console.log("child render")
return (
<>
<h2>My Todos</h2>
{todos.map((todo, index) => {
return <p key={index}>{todo}</p>
})}
@ynwd
ynwd / App.js
Created January 23, 2022 04:12
react redux with initial state
import React from 'react'
import { Provider, useSelector, useDispatch } from 'react-redux'
import { createStore } from 'redux'
function Counter() {
const count = useSelector(state => state.count)
const dispatch = useDispatch()
const action = {
type: "ADD",
@ynwd
ynwd / App.js
Created January 23, 2022 04:07
react redux example
import React from 'react'
import { Provider, useSelector, useDispatch } from 'react-redux'
import { createStore } from 'redux'
function Counter() {
const count = useSelector(state => state.count)
const dispatch = useDispatch()
const action = {
type: "ADD",
@ynwd
ynwd / App.js
Created January 22, 2022 01:47
react useEffect & useContext example
import React, { useContext, useReducer, createContext, useEffect } from 'react'
function Counter() {
const { count, setCount } = useContext(CountContext)
useEffect(() => {
document.title = `You clicked ${count} times`
}, [count])
return (
@ynwd
ynwd / App.js
Created January 21, 2022 10:03
react createContext simple example
import React, { useContext, useReducer, createContext } from 'react'
function Counter() {
const { count, setCount } = useContext(CountContext)
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>