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
/* Theme change */ | |
let getTheme = localStorage.getItem("theme"); | |
let link = document.createElement("link"); | |
link.style = "text/css"; | |
link.rel = "stylesheet"; | |
if (getTheme == "red") { | |
link.href = './styles/red.css'; | |
document.head.append(link); | |
} else { | |
link.href = './styles/blue.css'; |
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 formatBytes(bytes,decimals) { | |
if(bytes == 0) return '0 Bytes'; | |
var k = 1024, | |
dm = decimals || 2, | |
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | |
i = Math.floor(Math.log(bytes) / Math.log(k)); | |
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; | |
} | |
// Usage: |
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
const data = [1, 2, 2, 3, 3, 4]; | |
const removeArrayDuplicates = data.reduce( | |
(unique, item) => (unique.includes(item) ? unique : [...unique, item]), | |
[] | |
); | |
console.log(removeArrayDuplicates); |
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
/** | |
* Order function by key. | |
* @default "asc" | |
* data => field to order (Object, List, Array). | |
* key => the data to be order by this key. | |
*/ | |
function orderListByKey(data, key, order) { | |
const compareValues = (key, order = "asc") => (elemA, elemB) => { | |
if (!elemA.hasOwnProperty(key) || !elemB.hasOwnProperty(key)) return 0; | |
const comparison = elemA[key].localeCompare(elemB[key]); |
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
this.state.data != undefined ? this.state.data.map(item => { | |
Object.assign({}, this.state.dataObject, { [item[0]]: item[1] }); | |
console.log("dataObject", this.state.dataObject) | |
}) : undefined |
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
axios.defaults.xsrfCookieName = 'csrftoken'; | |
axios.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
axios.defaults.headers.common['Cookie'] = document.cookie; |
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
const object = { | |
a: 'somestring', | |
b: 42 | |
}; | |
if(object){ | |
for (const [key, value] of Object.entries(object)) { | |
console.log(`${key}: ${value}`); | |
} | |
} else { |
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
axios({ | |
url: `/api/download/${id}/`, | |
method: 'GET', | |
responseType: 'blob', // important | |
}).then((response) => { | |
const url = window.URL.createObjectURL(new Blob([response], { type: response.type })); | |
const link = document.createElement('a'); | |
link.href = url; | |
link.setAttribute('download', fileName); | |
link.target = '_blank' |
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 React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import styles from './mystyle.module.css'; | |
class Car extends React.Component { | |
render() { | |
return <h1 className={styles.bigblue}>Hello Car!</h1>; | |
} | |
} |
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
class Car extends React.Component { | |
render() { | |
return <h2>I am a {this.props.brand}!</h2>; | |
} | |
} | |
class Garage extends React.Component { | |
render() { | |
return ( | |
<div> |