This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sortWith, path, split, ascend, descend } from "ramda"; | |
const theList = [ | |
{ | |
name: "C", | |
purchase: { | |
period: { | |
start: "2020-01-26T21: 00: 00Z", | |
end: "3070-10-27T21: 00: 00Z", | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import React from "react"; | |
import { ThemeProvider } from '@material-ui/styles'; | |
import CssBaseline from '@material-ui/core/CssBaseline'; | |
import theme from 'theme.js'; | |
export default class App extends React.Component { | |
render() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// https://stackoverflow.com/questions/50353676/how-to-change-the-style-of-the-dropdown-element-of-the-material-ui-select-compon | |
import React from "react"; | |
import { makeStyles } from '@material-ui/core/styles'; | |
import Select from "@material-ui/core/Select"; | |
const useStyles = makeStyles({ | |
select: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function highlightText(text, search) { | |
RegExp.escape = function(string) { | |
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); | |
} | |
console.log(new RegExp(RegExp.escape(search), "gi")); | |
const html = text.replace( | |
new RegExp(RegExp.escape(search), "gi"), | |
(match) => `<span class=${styles.highlight}>${match}</span>`, | |
); | |
return html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://rubular.com/r/twBPG8HQgP | |
regex = /\S+[a-z0-9]@[a-z0-9\.]+/img | |
"hello sean@example.com how are you? do you know bob@example.com?".match(regex) | |
// ["sean@example.com", "bob@example.com"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findEmailAddresses(StrObj) { | |
var separateEmailsBy = ", "; | |
var email = "<none>"; // if no match, use this | |
var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+)/gi); | |
if (emailsArray) { | |
email = ""; | |
for (var i = 0; i < emailsArray.length; i++) { | |
if (i != 0) email += separateEmailsBy; | |
email += emailsArray[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Schema.methods.saveAsync = function () { | |
return new Promise((resolve, reject) => { | |
this.save((err) => { | |
if (err) return reject(err) | |
resolve(this) | |
}) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useState, useEffect} from "react"; | |
import axios, {AxiosResponse} from "axios"; | |
const useAxiosFetch = (url: string, timeout?: number) => { | |
const [data, setData] = useState<AxiosResponse | null>(null); | |
const [error, setError] = useState(false); | |
const [errorMessage, setErrorMessage] = useState(null); | |
const [loading, setLoading] = useState(true); | |
useEffect(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Handling Errors using async/await | |
* Has to be used inside an async function | |
*/ | |
try { | |
const response = await axios.get('https://your.site/api/v1/bla/ble/bli'); | |
// Success 🎉 | |
console.log(response); | |
} catch (error) { | |
// Error 😨 |