Skip to content

Instantly share code, notes, and snippets.

View louicoder's full-sized avatar
🏠
Working remotely

Musanje Louis Michael louicoder

🏠
Working remotely
View GitHub Profile
@louicoder
louicoder / nvmCommands.js
Created December 6, 2023 12:29 — forked from chranderson/nvmCommands.js
Useful NVM commands
// check version
node -v || node --version
// list locally installed versions of node
nvm ls
// list remove available versions of node
nvm ls-remote
// install specific version of node
@louicoder
louicoder / getDifferenceBetweenDays.js
Created October 17, 2023 15:22
Get difference between two dates
function formatDateDifference(isoDateString) {
const inputDate = new Date(isoDateString);
const currentDate = new Date();
const timeDifference = currentDate - inputDate;
// Calculate the number of years
const years = Math.floor(timeDifference / (365.25 * 24 * 60 * 60 * 1000));
// Calculate the number of months
@louicoder
louicoder / working-with-iso-dates.js
Created April 17, 2023 11:13
Validate and also work with iso dates
// ==============================================
// Function validates whether passed string is valid iso format
function isIsoDate(str) {
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false;
const d = new Date(str);
return d instanceof Date && !isNaN(d) && d.toISOString()===str; // valid date
}
console.log(isIsoDate('2011-10-05T14:48:00.000Z'))
@louicoder
louicoder / ReactNativeFirebaseErrors.js
Created February 23, 2023 16:09
React native Firebase Error for push notifications ios
// ================================================
<< Error >>
APNS device token not set before retrieving FCM Token for Sender ID
<< Fix >>
Add a firebase.json file at the root and add the following
{
"react-native": {
"analytics_auto_collection_enabled": false,
"messaging_ios_auto_register_for_remote_messages": false
@louicoder
louicoder / jsconfig.js
Created February 14, 2023 12:32
This is a file that helps you with shortening file imports in Javascript projects
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"src/*": [
"./src/*"
]
}
},
"include": [
@louicoder
louicoder / adbCommands.txt
Created January 18, 2023 12:20 — forked from giacomocerquone/adbCommands.txt
Useful adb logcat commands when working with react native
// useful to debug js code errors
adb logcat "*:S" ReactNative:V ReactNativeJS:V
// useful to debug native errors (when the app won't even start)
adb logcat "*:E"
@louicoder
louicoder / randomString.js
Created December 15, 2022 13:10
generate random with of specified length
export const generateString = (length = 10) => {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
// const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
@louicoder
louicoder / groupArray.js
Created December 14, 2022 09:33
Group array of objects into object
const grouped = array.reduce((obj, item) => {
const key = item.age;
if (!obj[key]) {
obj[key] = [];
}
obj[key].push(item);
return obj;
@louicoder
louicoder / fullWidthAndHeightImage.js
Last active July 28, 2022 11:38
Create Full Width image and Auto Height in React Native
// Get screen dimensions
const { WIDTH, HEIGHT } = Dimensions.get();
// style={{ aspectRatio: image.width / image.height }}
const getImageStyles = (imageWidth, imageHeight) => {
// WIDTH - Screen Width.
// HEIGHT - Screen Height.
return { width: WIDTH, height: imageHeight / imageWidth * WIDTH };
};
@louicoder
louicoder / HOC.js
Created May 25, 2022 07:14
Conditionally rendering the Header and Footer components in react-Router v6
// HOC component
import {Header, Footer} from '/path/to/Components';
export default ({header , footer, component: Component}) => {
return (
<div>
{header ? <Header /> : null} // check for true or false prop for rendering header
<Component /> // render component passed.
{footer ? <Footer /> : null} // check for true or false prop for rendering footer
</div>