Skip to content

Instantly share code, notes, and snippets.

View chnirt's full-sized avatar
🦦
On vacation

Chnirt chnirt

🦦
On vacation
View GitHub Profile
@chnirt
chnirt / README.md
Last active April 19, 2023 03:05
Setup from scratch your new MacBook for Develop
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

nano ~/.zshrc
PROMPT='%n~$'
export NVM_DIR="${HOME}/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
export PATH=${PATH}:$HOME/Library/Android/sdk/platform-tools/
    
brew doctor
@chnirt
chnirt / README.md
Created July 15, 2022 05:34
Git cheatsheet

When you commited your own code to remote then revert before commit:

git reset --hard HEAD~1

Push new code to override remote server:

git push --force origin
@chnirt
chnirt / README.md
Last active January 10, 2023 10:10
Encrypt and decrypt app

Hello world

Quick Overview

npx https://gist.github.com/chnirt/1445f38cb8df53c00fc15a84ef163cc2

if you've previously installed chnirt-build-app globally via npx https://gist.github.com/chnirt/1445f38cb8df53c00fc15a84ef163cc2, we recommend you uninstall the package using npm uninstall -g chnirt-build-app or yarn global remove chnirt-build-app to ensure that npx always uses the latest version. NOTE: remember to clear cache using npx clear-npx-cache

@chnirt
chnirt / index.js
Last active June 29, 2022 05:24
useFetch for firebase with fetch and load more
import { useCallback, useEffect, useState } from 'react'
import {
collection,
query,
orderBy,
limit,
startAfter,
onSnapshot,
} from 'firebase/firestore'
@chnirt
chnirt / README.md
Last active August 23, 2022 07:50
React native clear cache

For Android

npm cache clean --force 
cd android && ./gradlew clean
npm i
npm run android

For iOS

Desktop -> About this Mac -> Storage -> Manage -> Developer -> delete Project Build Data and Indexes
@chnirt
chnirt / run.java
Created May 21, 2022 08:57
Find the second most frequent letter with multiple conditions
// There is a string s, which consists of lowercase letters from twenty-six alphabet letters "a" through "z". You are asked to find the second most frequent letter in this string. For example, if s = “xddxdca”, then the second most frequent letter in this string is“x”.
// Even if there is more than one letter that are most frequent, none of them should count toward picking the second most frequent letter. For example, if s = “jpcpjppcyycyy”, then the most frequent letters in this string are “p” and “y”, as there are four of each in the string. In this case, the second most frequent letter in this string will be “c”, as there are three "c"s in this string.
// If there is more than one second most frequent letter in the given string, then arrange them in alphabetical order. For example, if s = “brbabrrara”, then the second most frequent letters here are “b” and “a”. Arrange them in alphabetical order, and you get “ab”.
// In the case where there is no second most frequent letter in the given string s, you mu
@chnirt
chnirt / run.swift
Created May 21, 2022 08:54
Balanced Brackets with multiple conditions
// There are strings that are made of brackets—[,], braces—{,}, and parentheses—(,). A string is regarded as a valid string of brackets when it meets the following conditions:
// In brackets, there can be brackets, braces, and parentheses.
// In braces, there can only be braces and parentheses.
// 2-1. "{[]()}" is invalid, because brackets are in braces.
// In parentheses, there can only be other parentheses.
// 3-1. "({()})" is invalid, because braces are in parentheses.
// All open brackets, braces, and parentheses must be closed by the corresponding number of brackets, braces, and parentheses.
@chnirt
chnirt / run.swift
Created May 21, 2022 08:51
Binary numbers with N digits and k 1s
// You are trying to figure out how many binary numbers there are that have N digits and k 1s, and are multiples of 3. Binary numbers that have N digits also include ones that start with 0.
// Suppose that N = 3 and K = 2. Binary numbers with three digits in this case include the following: 000, 001, 010, 011, 100, 101, 110, and 111--8 binary numbers in total. Among these numbers, the ones that have two 1s are 011, 101, and 110. Among these three numbers, two--011 and 110--are multiples of 3.
// Suppose parameters N and K are given, where N represents the number of digits of the given binary number(s) and K the number of 1s in these binary numbers. Please write a function solution that returns the number of binary numbers that have N digits and k 1s and are multiples of 3
// Constraints
// N is a natural number between 1 and 50.
// K is a natural number between 1 and N.
// Examples
@chnirt
chnirt / formatLargeNumber.js
Last active May 23, 2022 03:45
format large number 9.939515029213079e+40
import numeral from 'numeral';
export const formatCurrency = (number, symbol = '$') => {
const formatScientificNotationNumber = Number(number).toFixed(8); // format for case number = 9.322320693172514e-12
if (formatScientificNotationNumber.includes('e+')) {
var formatter = new Intl.NumberFormat('en-AU', {
style: 'currency',
currency: 'AUD',
minimumFractionDigits: 0,
@chnirt
chnirt / EnscriptDescriptByGPG.sh
Created May 9, 2022 06:38
Encrypt & Descrypt by GPG
echo "Encrypt & Decrypt with PGP by Chnirt"
# install gpg
# https://gpgtools.org/
# gpg --full-generate-key
choice="Encrypt Decrypt Exist"
select option in $choice
do
echo "$option"