Imagine we have a reducer to control a list of items:
function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
switch(action.type) {
case 'SHOW_ALL_ITEMS':
return action.data.items
default:
/** | |
* @desc function to convert ms to time format hh:ii:ss.ms | |
* @param {Number} duration, time ini miliseconds | |
* @return {String} sample 00:01:01:99 | |
*/ | |
export function msToTime(duration = 0) { | |
let milliseconds = parseInt((duration % 1000) / 100), | |
seconds = Math.floor((duration / 1000) % 60), | |
minutes = Math.floor((duration / (1000 * 60)) % 60), | |
hours = Math.floor((duration / (1000 * 60 * 60)) % 24); |
.block-ellipsis { | |
display: block; | |
display: -webkit-box; | |
max-width: 100%; | |
height: 43px; | |
margin: 0 auto; | |
font-size: 14px; | |
line-height: 1; | |
-webkit-line-clamp: 3; | |
-webkit-box-orient: vertical; |
.block-ellipsis { | |
display: block; | |
display: -webkit-box; | |
max-width: 100%; | |
height: 43px; | |
margin: 0 auto; | |
font-size: 14px; | |
line-height: 1; | |
-webkit-line-clamp: 3; | |
-webkit-box-orient: vertical; |
const iso2FlagEmoji = iso => String.fromCodePoint(...[...iso.toUpperCase()].map(char => char.charCodeAt(0) + 127397)); | |
iso2FlagEmoji("US"); // "🇺🇸" |
/* | |
* 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 😨 |
/* | |
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674 | |
*/ | |
var fs = require('fs'); | |
// string generated by canvas.toDataURL() | |
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0" | |
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO" | |
+ "3gAAAABJRU5ErkJggg=="; | |
// strip off the data: url prefix to get just the base64-encoded bytes |
// Reload (or initialize) addThis social share buttons. | |
// IMPORTANT: make sure you put in a correct pubid on line 7. | |
window.addthis_reload = function () { | |
if (!window.addthis) { | |
// Load addThis, if it hasn't already been loaded. | |
window['addthis_config'] = { 'data_track_addressbar' : false }; | |
$('body').append('<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={YOUR PUBID HERE}"></script>'); | |
} else { | |
// Already loaded? Then re-attach it to the newly rendered set of social icons. | |
// And reset share url/title, so they don't carry-over from the previous page. |
CREATE TABLE newTableName | |
LIKE oldTableName |