Skip to content

Instantly share code, notes, and snippets.

View devakone's full-sized avatar
💭
coding...

Abou Koné devakone

💭
coding...
View GitHub Profile
@devakone
devakone / localhost-ssl-certificate.md
Created February 19, 2021 20:52 — forked from ethicka/localhost-ssl-certificate.md
Localhost SSL Certificate on Mac OS

🚨 2020 Update: I recommend using mkcert to generate local certificates. You can do everything below by just running the commands brew install mkcert and mkcert -install. Keep it simple!


This gives you that beautiful green lock in Chrome. I'm assuming you're putting your SSL documents in /etc/ssl, but you can put them anywhere and replace the references in the following commands. Tested successfully on Mac OS Sierra and High Sierra.

Set up localhost.conf

sudo nano /etc/ssl/localhost/localhost.conf

### Keybase proof
I hereby claim:
* I am devakone on github.
* I am devakone (https://keybase.io/devakone) on keybase.
* I have a public key ASByeWTO9FcHZlpWp9J328OC_vGki2s2h97qmH9JJSKf_Qo
To claim this, I am signing this object:
@devakone
devakone / safe-html.js
Created June 12, 2019 19:34
How to translate partial HTML content with dangerouslySetInnerHTML and react-i18next
import dompurify from 'dompurify';
import useTranslateHtmlElement from './use-translate-html-element';
// Our safe HTML rendering component
// From https://dev.to/jam3/how-to-prevent-xss-attacks-when-using-dangerouslysetinnerhtml-in-react-1464
function SafeHTMLComponent() {
// title is dynamic HTML
const title = response.from.backend.title;
// sanitizer will sanitize the HTML
const sanitizer = dompurify.sanitize;
@devakone
devakone / use-translate-form-errors-with-formik-component-method.js
Created June 12, 2019 18:37
How to use the useTranslateFormErrors hook with Formik's component render method.
...
<Formik component={ContactForm} />;
...
import useTranslateFormErrors from '../../hooks/use-translate-form-errors';
const ContactForm = ({
handleSubmit,
handleChange,
@devakone
devakone / example-with-with-translate-form-error-hoc.js
Last active May 30, 2022 08:53
This HOC adds the ability to a Formik form to
<Formik
render={({ handleSubmit, handleChange, handleBlur, setFieldTouched, values, errors, touched }) => (
<WithTranslateFormErrors errors={errors} touched={touched} setFieldTouched={setFieldTouched}>
<form onSubmit={handleSubmit}>
<input
type="text"
onChange={handleChange}
onBlur={handleBlur}
value={values.name}
name="name"
@devakone
devakone / with-translate-form-errors-hoc-usage.js
Last active June 12, 2019 18:38
How to use the WithTranslateFormErrors HOC
<Formik
render={({ handleSubmit, handleChange, handleBlur, setFieldTouched, values, errors, touched }) => (
<WithTranslateFormErrors errors={errors} touched={touched} setFieldTouched={setFieldTouched}>
<form onSubmit={handleSubmit}>
<input
type="text"
onChange={handleChange}
onBlur={handleBlur}
value={values.name}
@devakone
devakone / use-translate-form-errors.js
Last active June 12, 2019 18:31
Reusable hook that takes in a Formik form object and ensures that error messages are translated when the i18next language is changed
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
// When change language is triggered, re-validate the form as to get all errors translated
// the parameters here are part of the FormikProps<Values> render props
// https://jaredpalmer.com/formik/docs/api/formik#formik-render-methods-and-props
const useTranslateFormErrors = (errors, touched, setFieldTouched) => {
const { i18n } = useTranslation();
useEffect(() => {
i18n.on('languageChanged', lng => {
@devakone
devakone / introrx.md
Created October 17, 2016 19:37 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing