Skip to content

Instantly share code, notes, and snippets.

View Felix-Seip's full-sized avatar

Felix Seip Felix-Seip

View GitHub Profile
public boolean isWithinRadius(Coordinates searchLocationCoordinates, int radius) {
final int earthRadius = 6371; // Radius of the earth
double latDistance = Math.toRadians(searchLocationCoordinates.latitude - latitude);
double lonDistance = Math.toRadians(searchLocationCoordinates.longitude - longitude);
double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
+ Math.cos(Math.toRadians(latitude)) * Math.cos(Math.toRadians(latitude))
* Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double distanceInKm = earthRadius * c;
public Coordinates geocodeLocation(String location) throws LocationNotFoundException {
JOpenCageGeocoder jOpenCageGeocoder = new JOpenCageGeocoder(apiKey);
JOpenCageResponse geocodeResult = jOpenCageGeocoder.forward(new JOpenCageForwardRequest(location));
JOpenCageLatLng openCageLatLng = geocodeResult.getFirstPosition();
if(null == openCageLatLng) {
throw new LocationNotFoundException("Could not find location " + location);
}
import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
i18n
.use(initReactI18next) // passes i18n down to react-i18next
.use(LanguageDetector)
.init({
resources: {
en: {
import React from "react";
import { Trans } from "react-i18next";
export default function MyComponent() {
return <Trans i18nKey="helloWorld" />;
}
import React from 'react';
import { Translation } from 'react-i18next';
export function MyComponent() {
return (
<Translation>
{
(t, { i18n }) => <p>{t('my translated text')}</p>
}
</Translation>
import React from 'react';
import { withTranslation } from 'react-i18next';
function MyComponent({ t, i18n }) {
return <p>{t('my translated text')}</p>
}
export default withTranslation()(MyComponent);
import React from 'react';
import { useTranslation } from 'react-i18next';
export function MyComponent() {
const [t, i18n] = useTranslation();
return <p>{t('helloWorld')}</p>
}
import React from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function App(){
const notify = () => toast("Wow so easy!");
return (
<div>
<button onClick={notify}>Notify!</button>
import React from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function App(){
const notify = () => toast("Wow so easy!");
return (
<div>
<button onClick={notify}>Notify!</button>
import React from "react";
import { LinkContainer } from "react-router-bootstrap";
import { Form, Input, Row, Col, FormGroup, Label, Button } from "reactstrap";
function MyForm(props) {
const [inputs, setInputs] = React.useState({});
const onHandleInput = (e) => {
setInputs({ ...inputs, [e.target.id]: e.target.value });