Skip to content

Instantly share code, notes, and snippets.

@ynwd
ynwd / settings.json
Created March 25, 2022 02:54
vscode formatOnSave
{
"editor.formatOnSave": false,
"[javascript, python]": {
"editor.formatOnSave": true
}
}
@ynwd
ynwd / main.js
Created February 13, 2022 04:43
Very Simple Bull Queue without Redis
const Queue = require('bull')
const q = new Queue('my-first-queue')
setTimeout(async () => {
const data = { message: "my task" }
await q.add(data)
}, 5000)
q.process((job, done) => {
@ynwd
ynwd / docker-compose.yml
Created February 13, 2022 04:34
Very Simple Bull Queue
version: "3.9"
services:
redis:
image: redis:6-alpine
ports:
- 6379:6379
@ynwd
ynwd / consumer.js
Created February 13, 2022 00:01
Bull Queue Hello World
const Queue = require('bull')
const q = new Queue('my-first-queue', {
redis: { port: 6379, host: "localhost" }
})
q.process((job, done) => {
done(null, 'succes')
})
q.on('completed', (job) => {
@ynwd
ynwd / sebelum_refactor.go
Created January 31, 2022 15:15
SOLID: prinsip liskov
package main
import "fmt"
type A struct{}
func (a A) Test() {
fmt.Println("Printing A")
}
@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>
})}