Value | Color |
---|---|
\e[0;30m | Black |
\e[0;31m | Red |
\e[0;32m | Green |
\e[0;33m | Yellow |
\e[0;34m | Blue |
\e[0;35m | Purple |
This file contains hidden or 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
// Returns a random integer between min (include) and max (include) | |
Math.floor(Math.random() * (max - min + 1)) + min; | |
///////////////////////////// | |
// Useful examples: | |
///////////////////////////// | |
// 0 -> 10 | |
Math.floor(Math.random() * 11); |
This file contains hidden or 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
curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}' | |
# Remember replace USER with your username and REPO with your repository/application name! | |
git remote add origin [email protected]:USER/REPO.git | |
git push origin master |
This file contains hidden or 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 _ from 'lodash'; | |
componentWillReceiveProps (nextProps) { | |
const changedProps = _.reduce(this.props, function (result, value, key) { | |
return _.isEqual(value, nextProps[key]) | |
? result | |
: result.concat(key) | |
}, []) | |
console.log('changedProps: ', changedProps) | |
} |
This file contains hidden or 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 str = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in risus elementum quam gravida faucibus. Vestibulum blandit sollicitudin enim nec tempus. Nunc eu mattis massa. Nulla facilisi. Proin vel lobortis mauris, ut aliquet orci. Phasellus vel fermentum risus, at interdum sapien. Nullam ante velit, venenatis quis consectetur dapibus, dictum sed urna. Vestibulum quis mi molestie est iaculis ullamcorper. Phasellus felis lorem, vehicula eu venenatis id, auctor nec eros. Nullam purus justo, efficitur ac finibus vitae, sodales vel tellus. Nunc accumsan massa ut diam ullamcorper ultricies. Integer odio ex, laoreet malesuada felis vel, vehicula malesuada leo. Nullam accumsan ullamcorper orci, nec vestibulum nulla eleifend ac. Duis leo odio, viverra eget laoreet vitae, molestie ut eros. Morbi vitae dui interdum ipsum hendrerit facilisis a ut dolor.` | |
str.split(' ').slice(0, 12).join(' '); | |
//-> returns "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in risus elementum" |
This file contains hidden or 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 is an advanced example! It is not intended for use in application code. | |
// Libraries like Relay may make use of this technique to save some time on low-end mobile devices. | |
// Most components should just initiate async requests in componentDidMount. | |
class ExampleComponent extends React.Component { | |
_hasUnmounted = false; | |
state = { | |
externalData: null, | |
}; |
This file contains hidden or 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 tableBody = document.querySelector('.dataitems-table tbody'); | |
// can grab pseudo element styles by replacing null with selector | |
window.getComputedStyle(tableBody, null).getPropertyValue("padding-right"); |
This file contains hidden or 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 leadingZero = (num) => `0${num}`.slice(-2); | |
const formatTime = (date) => | |
[date.getHours(), date.getMinutes(), date.getSeconds()] | |
.map(leadingZero) | |
.join(':'); | |
formatTime(new Date(1514727120000)) | |
// -> "07:32:00" |
This file contains hidden or 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
var now = Date.now(); | |
var then = new Date(now); | |
var date1 = then.getFullYear(); | |
var date2 = then.getDate(); | |
var date3 = then.getMonth(); | |
var date4 = then.getHours(); | |
var date5 = then.getMinutes(); | |
var date6 = then.getSeconds(); | |
var date7 = then.getMilliseconds(); |
This file contains hidden or 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
fetch(path.join(__dirname, `/api/structures/overview`), { | |
method: `GET`, | |
credentials: 'include' | |
}) | |
.then(response => { | |
const json = response.json(); | |
if (response.status >= 200 && response.status < 300) { | |
return json; | |
} else { | |
return json.then(Promise.reject.bind(Promise)); |