Skip to content

Instantly share code, notes, and snippets.

View nixjs's full-sized avatar
:octocat:
Thanks for visiting

Nghi Nguyen nixjs

:octocat:
Thanks for visiting
View GitHub Profile

14

That's what worked for me:

Generate ssh key github

  1. The Remotes

$ git remote rm origin $ git remote add origin git@github.com:/.git If your SSH key is already in use on another github rep, you can generate a new one.

class Queue<T = any> {
items: T[] = []
// Implementing various methods of javascript queue:
// 1. adding element to the queue
enqueue(item: T) {
this.items.push(item)
}
// 2. removing element from the queue
@nixjs
nixjs / doc.md
Created April 19, 2024 14:32
How to publish package on npmjs
  1. Create .npmrc.
  2. Add //registry.npmjs.org/:_authToken=${NPM_TOKEN} in .npmrc file.
  3. Generate access token from npmjs and put in zshrc, bashrc.
  4. Login npmjs by terminal npm adduser 5.1. pnpm --filter=package_name publish --no-git-checks // use pnpm and workspace 5.2. yarn npm publish // use yarn 5.3. npm publish // use npm
@nixjs
nixjs / toNotationObject.js
Created November 2, 2023 06:54
Convert javascript dot notation object to nested object
const obj = {
"start.headline": "1 headline",
"start.subHeadline": "subHeadline",
"start.accordion.headline": "2 headline",
"start.accordion.sections.0.content": "content 0",
"start.accordion.sections.0.iconName": "icon 0",
"start.accordion.sections.1.headline": "headline 1",
"start.accordion.sections.1.content": "content 1",
"start.accordion.sections.1.iconName": "icon 1",
"start.accordion.sections.2.headline": "headline 2",

How to fix node-gyp rebuild failed on MacOS

│ In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/string.h:141:
│ In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_rsize_t.h:30:
│ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/machine/types.h:37:2: error: architecture not supported
│ #error architecture not supported
│  ^
│ fatal error: too many errors emitted, stopping now [-ferror-limit=]
│ 20 errors generated.
│ make: *** [Release/obj.target/validation/src/validation.o] Error 1
@nixjs
nixjs / swiper.ts
Created July 13, 2023 06:42
Resize slide per view in swiper
import React from 'react'
import { Randomize } from '@huula/utils'
import useSwiperRef from 'hooks/useSwiperRef'
import { Swiper, SwiperSlide, SwiperProps, SwiperRef } from 'swiper/react'
import SwiperCore, { Autoplay, Pagination, Navigation } from 'swiper'
import { Event } from './Event'
SwiperCore.use([Autoplay, Pagination, Navigation])
const slidesPerView = {
import BigNumber from 'bignumber.js'
export const accelerateNumber = (
target: number, // Input number
delay: number, // Delay timeout
duration: number, // Duration corresponding to each acceleration in s
decimals: number, // Decimals
onGetValue: (value: number) => void
) => {
let number = 0
@nixjs
nixjs / grpc-client-stream-reconnecting.ts
Created June 1, 2023 04:57
gRPC Streaming that will automatically reconnect if the connection is closed.
import * as grpcWeb from 'grpc-web'
import * as pbjs from 'google-protobuf/google/protobuf/empty_pb'
import { BaseBackOff } from '@nixjs23n6/backoff-typescript'
import { Types } from '@nixjs23n6/types'
enum StreamEvents {
data = 'data', // A message was received
metadata = 'metadata', // A meta data of the connection
error = 'error', // An error occurred
end = 'end', // Connection is closed
@nixjs
nixjs / enumify.ts
Created April 26, 2023 14:13
Convert array of strings into enum
type ValuesOfArray<T extends ReadonlyArray<any>> = T[number]
type ToObj<K extends string> = {
[P in K]: P
}
export const generate = <T extends readonly any[], K extends ValuesOfArray<T>>(
arr: T,
start?: number,
convention?: number
@nixjs
nixjs / pre-commit.sh
Created April 18, 2023 10:50
Pre-commit detection to test each web app for Turborepo (web-app1, web-app2, web-app3)
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# folder
BASE_ROOT="apps"
PACKAGE_JSON="package.json"
PACKAGES="packages"
WEB_APP_1="web-app-1"
WEB_APP_2="web-app-2"
WEB_APP_3="web-app-3"