Skip to content

Instantly share code, notes, and snippets.

View johhansantana's full-sized avatar

Johhan Santana johhansantana

View GitHub Profile
@johhansantana
johhansantana / useDetectScrollEnd.tsx
Created June 24, 2024 18:32
This custom react native hook detects when a ScrollView reaches the end of its scroll so you can do stuff like infinite scroll and what not
import { useCallback, useState } from "react";
import { NativeScrollEvent, NativeSyntheticEvent } from "react-native";
interface UseDetectScrollEndProps {
onEndReached: () => void;
offset?: number;
}
const useDetectScrollEnd = ({
onEndReached,

To help you create a JavaScript program that calculates mortgage payments and total interest paid, we'll follow the formulas given in the image:

  1. Monthly payment formula: [ \text{payment} = p \times r / \left(1 - (1 + r)^{-n}\right) ] where:
    • ( p ) is the amount of the loan
    • ( r ) is the monthly interest rate (annual rate divided by 12)
    • ( n ) is the duration of the loan in months
@johhansantana
johhansantana / gist:943b568949d2d70e756d40ca8ce1d73d
Created December 5, 2023 14:59
build expo without eas cli
# To generate all the Android and IOS files
npx expo prebuild
# Make sure to connect your device or to run your Emulator
npx react-native run-android --mode="release"
# If you want to sign the APK and publish to Google Play Store.
npx react-native build-android --mode=release
# to build local apk
@johhansantana
johhansantana / config.json
Created December 4, 2023 16:53
add alias to webstorm using jsconfig.json for example, react-native-web
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"react-native": ["node_modules/react-native-web"]
}
}
}
@johhansantana
johhansantana / pushnotification.js
Last active March 4, 2019 21:02
push notification with working headsup display on android
const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "your database url (optional)"
});
module.exports = (req, res) => {
const payload = {
@johhansantana
johhansantana / nextjs.config.js
Created December 7, 2017 18:45
disable uglify in nextjs webpack config
config.plugins = config.plugins.filter(plugin => {
return plugin.constructor.name !== 'UglifyJsPlugin';
})
@johhansantana
johhansantana / input.jsx
Created October 17, 2017 18:30
react-select multiple select input with redux-form example
const renderSelect = field => (
<Select
id={field.id}
name={field.input.name}
multi={true}
joinValues={true}
value={field.input.value}
options={field.options}
onChange={(val) => field.input.onChange(val)}
/>
@johhansantana
johhansantana / redux-form-basic.jsx
Last active August 18, 2017 18:45
Get initial values from redux store with redux form with bootstrap
import React from 'react'
import { connect } from 'react-redux'
import { Field, reduxForm } from 'redux-form'
const required = value => (value ? undefined : 'Requerido')
let ConcursoForm = props => {
const { handleSubmit, submitting, invalid } = props
return (
<form onSubmit={ handleSubmit }>
<Field
@johhansantana
johhansantana / renderSelect.jsx
Last active July 18, 2017 20:39
render select field with redux form
const renderSelect = (field) => (
<div className="form-group">
<label htmlFor={field.input.name}>{field.label}</label>
<select
id={field.id}
name={field.input.name}
defaultValue=""
onChange={(event) => field.input.onChange(event.target.value)}
onBlur={(event) => field.input.onBlur(event.target.value)}
className={`form-control ${field.meta.touched && field.meta.error ? 'error' : ''}`}
@johhansantana
johhansantana / renderField.jsx
Created July 18, 2017 19:48
field for redux-form
const renderField = (field) => (
<div className="form-group">
<label htmlFor={field.input.name}>{field.label}</label>
<input
{...field.input}
id={field.input.name}
name={field.input.name}
className={`form-control ${field.meta.touched && field.meta.error ? 'error' : ''}`}
type={field.type}
/>