Skip to content

Instantly share code, notes, and snippets.

commands:
01_swapmem_step:
command: sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
ignoreErrors: true
test: test ! -f .swapmem
02_swapmem_step:
command: sudo /sbin/mkswap /var/swap.1
ignoreErrors: true
test: test ! -f .swapmem
03_swapmem_step:
doTheDishes();
watchNetflix();
vacuumTheFloor();
function doTheDishes() {
log('Dishes are done!');
}
function watchNetflix() {
log('Season 99 of <Netflix Show> finished!');
doTheDishes();
vacuumTheFloor();
watchNetflix();
function doTheDishes() {
log('Dishwasher ON!')
setTimeout(() => log('Dishes are done!'), 3000);
}
function vacuumTheFloor() {
// setTimeout receives a callback function, in this example the callback is "logger"
// setTimeout will call the function we gave, after the specified amount of time (3000 ms)
let logger = () => log('Dishes are done!');
setTimeout(logger, 3000);
watchNetflix(() => gotoSleep());
function watchNetflix(callbackFn) {
log('Netflix ON!')
setTimeout(() => {
log('Season 99 of <Netflix Show> finished!');
callbackFn();
}, 1000);
}
watchNetflix(
() => gotoSleep(
() => {
drinkCoffee();
goToWork(
() => goHome()
);
}
)
);
watchNetflix(
error => {
if (error) {
callInternetProvider();
} else {
gotoSleep((result, error) => {
if (error) {
tryToSleepAgain();
} else if (!result.rested) {
drinkCoffee();
// This is how you create a promise
new Promise((resolve, reject) => {
// Here you should do your work, involving some asynchronous operation
// Once it finishes, you either call resolve (fulfilled)
// or reject (rejected) to transition the promise state
});
new Promise(...)
.then(result => { /* promise was fulfilled, do something with result */ })
.catch(error => { /* promise was rejected, do something with error */ })
log('Waiting one second');
wait(1000)
.then(() => log('I waited for one second'))
.catch((err) => log('Something went wrong' + err));
log('Meanwhile checking twitter');
function wait(ms) {
return new Promise((resolve, reject) => {
log('Inside Promise ---> Started waiting')
setTimeout(() => resolve(), ms);