Skip to content

Instantly share code, notes, and snippets.

function hashStringToInt(s, tableSize) {
let hash = 17;
for (let i = 0; i < s.length; i++) {
hash = (13 * hash * s.charCodeAt(i)) % tableSize;
}
return hash;
}
@brunokiafuka
brunokiafuka / navigationStore.ts
Last active November 29, 2021 18:34
Mobx+React-router navigation
import { createBrowserHistory } from "history";
import { injectable } from "inversify";
import { makeAutoObservable } from "mobx";
import { useClassStore } from "../util/useClassStore";
import container from "./ioc";
@injectable()
class NavigationStore {
history = createBrowserHistory();

How to disable page caching with create-react-app

If you currently not using a service worker resulting in old production caches being used and users not getting new versions of the app.

src/index.js

Use:

import { unregister as unregisterServiceWorker } from './registerServiceWorker'
@brunokiafuka
brunokiafuka / nvm-and-node-with-apple-m1-chip.md
Created September 10, 2021 14:52 — forked from mcalthrop/nvm-and-node-with-apple-m1-chip.md
Using Node with Apple's new M1 chip

Using NVM and node with Apple's new M1 chip

20 January 2021

Rationale

At the time of writing, there are no pre-compiled NodeJS binaries for versions prior to 15.x for Apple's new M1 chip (arm64 architecture).

Additional issues encountered:

Project root:

yarn add -D --save-exact eslint-config-airbnb eslint-config-airbnb-typescript eslint-config-prettier eslint-config-react-app eslint-import-resolver-typescript eslint-webpack-plugin eslint-plugin-flowtype eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks babel-eslint eslint-plugin-jest @typescript-eslint/parser @typescript-eslint/eslint-plugin prettier prettier-eslint prettier-eslint-cli eslint-plugin-prettier

$ vim .eslintrc

{
  "plugins": ["prettier", "@typescript-eslint"],
@brunokiafuka
brunokiafuka / isPasswordStrong.js
Created May 24, 2021 17:53
Check Password Strength.
const strongPassword = new RegExp(
'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})'
);
const mediumPassword = new RegExp(
'^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})'
);
export const isPasswordStrong = (value = ''): boolean => {
if (strongPassword.test(value)) {
@brunokiafuka
brunokiafuka / reduce.js
Created May 29, 2020 20:38
reduce json obj arr
const array1 = [{num: 1}, {num: 1}, {num: 1}, {num: 1}];
console.log(array1.reduce((count, item) => {
return count += item.num;
},0))
export const facebookLogin = async () => {
try {
const { type, token } = await Facebook.logInWithReadPermissionsAsync('<YOUR APP ID>', {
permissions: ['public_profile', 'email', 'user_birthday'],
behavior: 'native',
});
if (type === 'success') {
// Get the user's name using Facebook's Graph API
const credential = firebase.auth.FacebookAuthProvider.credential(token)
@brunokiafuka
brunokiafuka / Basic_Sum.c
Last active May 24, 2019 17:46
C Basic programs
//Basic sum
#include <stdio.h>
int
main ()
{
/* variable definition: */
int num1, num2;
@brunokiafuka
brunokiafuka / heroku-react
Created March 29, 2019 15:06
deploy create-react-app buildpack
heroku create <AppName> --buildpack https://github.com/mars/create-react-app-buildpack.git