Skip to content

Instantly share code, notes, and snippets.

View rpn3319's full-sized avatar

Raymond Phu Nguyen rpn3319

  • Ho Chi Minh City, Vietnam
  • 20:40 (UTC +07:00)
  • LinkedIn in/rpn19
View GitHub Profile
@rpn3319
rpn3319 / nodejs-example-next-tick.js
Created December 10, 2022 07:13
NodeJS example about next tick
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {
constructor() {
super();
// use nextTick to emit the event once a handler is assigned
process.nextTick(() => {
this.emit('event');
});
@rpn3319
rpn3319 / react-nested-context-provider.js
Last active December 9, 2022 14:22
react-nested-context-provider
import { useContext, createContext } from 'react';
const BorderContext = createContext(1);
function Button({ children }) {
const borderWidth = useContext(BorderContext);
const style = {
border: `${borderWidth}px solid black`,
background: 'transparent',
};
@rpn3319
rpn3319 / go-tour-concurrency-exercise.go
Last active October 5, 2022 16:38
My solution for Go Tour Concurrency exercise about crawler
package main
import (
"fmt"
"sync"
)
type Store struct {
mu sync.Mutex
urls map[string]bool
@rpn3319
rpn3319 / parse-string-to-number.js
Created June 20, 2022 09:56
js parse string to number
function parseStrNumber(input) {
if (typeof input === 'number') return input;
if (typeof input !== 'string' || !input) return NaN;
let out = 0;
const l = input.length;
let pointIndex = input.length - 1;
let isNegative = false;
@rpn3319
rpn3319 / main.tf
Last active June 10, 2022 15:29
devops openvpn on aws
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
# Configure the AWS Provider
@rpn3319
rpn3319 / computer-science-resources-collection.md
Last active June 10, 2022 15:15
computer science resources collection
@rpn3319
rpn3319 / codding-career-resources-collection.md
Last active June 10, 2022 14:58
coding career resources collection
@rpn3319
rpn3319 / public-s3-bucket.tf
Last active June 10, 2022 14:42
terraform public s3 bucket
resource "aws_s3_bucket" "b" {
bucket = "my-app-test"
}
resource "aws_s3_bucket_policy" "b" {
bucket = aws_s3_bucket.b.id
# Terraform's "jsonencode" function converts a
# Terraform expression's result to valid JSON syntax.
policy = jsonencode({
@rpn3319
rpn3319 / commands.sh
Created June 10, 2022 14:40
terraform useful commands
# Init the project after create main.tf
terrform init
# To validate the syntax
terrform validate
# Run without effect the real world
# Use to see how the configs effect the world
terrform plan
@rpn3319
rpn3319 / postgres-query-table-list.sql
Created June 10, 2022 14:35
sql postgres table list
select
table_name,
table_type,
table_schema
from
information_schema.tables
where
table_type = 'BASE TABLE'
and table_schema = 'public'