Skip to content

Instantly share code, notes, and snippets.

View puemos's full-sized avatar
♨️
Something is cooking

Shy Alter puemos

♨️
Something is cooking
View GitHub Profile
@puemos
puemos / google_translate.applescript
Last active October 13, 2022 09:12
Fast translation with Google Translator and MAC OSX
on run {input, parameters}
set output to "http://translate.google.com/#auto/en/" & urldecode(input as string)
return output
end run
on urldecode(x)
set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'"
do shell script "echo " & quoted form of x & " | ruby -e " & cmd
end urldecode
async function publishAll() {
// You get the posts
const posts = await getPosts();
const successes = [];
const failures = [];
for (const post of posts) {
// synchronous check for validtion
if (!validate(post)) {
failures.push({ post, status: "failed" });
} else {
async function publishPipeline(post){
if (!validate(post)){
return { post, status: "failed" };
}
try {
await publish(post)
return { post, status: "published" };
} catch (e) {
return { post, status: "failed", error: e };
}
async function publishAll() {
const payments = await getPayments();
const invoices = await getInvoices();
const receipts = await getReceipts();
// do stuff with that
}
async function publishAll() {
const [payments, invoices, receipts] = await Promise.all([
getPayments(),
getInvoices(),
getReceipts()
]);
// do stuff with that
}
import { buffers, channel } from "redux-saga";
import { all, call, fork, put, take } from "redux-saga/effects";
/**
* creates a queue
*
* @param {GeneratorFunction} [handler] request handler
* @param {number} [workersCount=1] number of workers
*/
function* createConcurrentTaskQueue(handler, workersCount = 1) {
function* handler({ uri, index, segmentsCount }) {
// get the data
const res = yield call(fetch, uri);
const blob = yield res.blob();
// report to the store
yield put({ type: "CHUNK_DONE", payload: { index, blob } })
// check if all the chunk are ready
const currentChunkCount = yield select(currentChunkCountSelector)
const QUEUE_CONCURRENT = 5
const { watcher, queueChannel } = yield createConcurrentTaskQueue(
handler,
QUEUE_CONCURRENT
);
const watcherTask = yield fork(watcher)
const segmentsCount = segments.length
// transform the segments list to an action list
const actions = segments.map((segment, index) =>
put(queueChannel, { payload: { uri: segment.uri, index, segmentsCount } })
)
// fire them all together
yield all(actions);
// the first to fire between "all done" and "cancel"
const { cancelDownload, allDone } = yield race({
allDone: take(allDoneChannel),
cancelDownload: take("CANCEL_DOWNLOAD")
});
// stop the queue manager
yield cancel(watcherTask);
// in case of cancellation just return;