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 { Octokit } = require("@octokit/rest"); | |
const fastCsv = require("fast-csv"); | |
const fs = require("fs"); | |
const consola = require("consola"); | |
process.on("unhandledRejection", (error, promise) => { | |
consola.fatal(`Unhandled rejection! ${error.name}: ${error.message}`, { | |
error, | |
promise, | |
}); |
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 { map, iteratee } from 'lodash'; | |
/** | |
* Replaces elements from collection that matches predicate with replacement. | |
* | |
* @param {Array} collection The collection to replace in | |
* @param {*} predicate The condition to determine which elements of collection | |
* should be replaced | |
* @param {*} replacement The value to use as a replacement of elements of | |
* collection that matches the predicate |
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
// It may have a lot of possible use case but the one I did it for initially was | |
// to find which keys were missing between two JSON translations files | |
function getKeys(obj) { | |
const keys = []; | |
const walk = (o, parent = null) => { | |
for (const k in o) { | |
const current = parent ? parent + '.' + k : k; | |
keys.push(current); |
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
// Originally tweeted at https://twitter.com/ClementParis016/status/1065000952749539329 | |
// Fetch raw binary PDF data | |
const response = await fetch('https://some.pdf'); | |
// Extract response body as Blob | |
const blob = await response.blob(); | |
// Create an URL pointing to the object | |
const url = URL.createObjectURL(blob); | |
// Render a PDF viewer! |
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 REGEX = /https:\/\/.*\.googleusercontent\.com\/.*#(https?:\/\/.*)/i; | |
// Rewrite img source on <img> tags | |
Array.from( | |
document.querySelectorAll('img') | |
).forEach(img => { | |
const match = img.src.match(REGEX); | |
if (!match) { | |
return; |
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 fs = require('fs'); | |
const rawBase64 = ''; // typically 'data:image/png;base64,.......' | |
const [, ext, data] = rawBase64.match(/^data:image\/([a-z]+);base64,(.*)$/); | |
fs.writeFileSync(`image.${ext}`, data, 'base64'); |
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 p1 = new Promise(resolve => resolve({ data: 1, status: 'OK' })); | |
const p2 = new Promise((resolve, reject) => reject({ data: 2, status: 'OK' })); | |
const p3 = new Promise(resolve => resolve({ data: 3, status: 'OK' })); | |
const promisesCatcher = promises => promises.map(promise => promise.catch(err => ({ data: err, status: 'ERROR' }))); | |
Promise.all( | |
promisesCatcher([p1, p2, p3]) | |
).then(values => { | |
for (let result of values) { |
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 weekDays = { | |
monday: "Monday", | |
tuesday: "Tuesday", | |
wednesday: "Wednesday", | |
thursday: "Thursday", | |
friday: "Friday" | |
}; | |
const mappedWeekDays = Object.keys(weekDays).reduce((mapper, day) => { | |
mapper[day] = { |
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
<div class="container"> | |
<img class="floatted-image" src="http://placehold.it/350x150" alt="Dummy image"> | |
<p class="no-wrapping-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dapibus magna elit, a posuere lacus malesuada sed. Fusce ante metus, congue vel odio vitae, eleifend placerat metus. Suspendisse tempus dapibus mauris id faucibus. Curabitur augue erat, aliquet facilisis sem non, ultrices sollicitudin nulla. Etiam condimentum a nisl ut bibendum. Aliquam tellus nisi, ultrices at ligula eget, euismod tempus leo. Donec pellentesque, tortor et fringilla tincidunt, ex neque ullamcorper risus, quis sollicitudin elit nulla a nulla.</p> | |
</div> |
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
# From https://stevegrunwell.github.io/wordpress-git/#/13 | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
# Attempt to load files from production if | |
# they're not in our local version | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule wp-content/uploads/(.*) \ |
NewerOlder