Exclude Packages from Apt-Get Upgrade on Debian Linux

To exclude/hold a package from apt-get upgrade type: apt-mark hold package_nameapt-mark hold package_name For example, to exclude MariaDB mysql packages type: apt-mark hold libmariadbclient18 mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server mariadb-server-10.3 mariadb-server-core-10.3 mysql-commonapt-mark hold libmariadbclient18 mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server mariadb-server-10.3 mariadb-server-core-10.3 mysql-common Here is an example output: libmariadbclient18 set on hold. mariadb-client-10.3 set on hold. mariadb-client-core-10.3 set […]

What is the Correct JSON Content-Type for HTTP Headers?

Many web services uses different content-type for JSON data, i.e: application/json application/x-javascript text/javascript text/x-javascript text/x-jsonapplication/json application/x-javascript text/javascript text/x-javascript text/x-json But what is the correct content type to use for JSON data? For JSON text you should use application/json (read more on RFC 4627). For JSONP (runnable javascript) with callback, use application/javascript. You should read also […]

What to Select on GRUB-PC Configuration “Install Devices”

Today when I did an “apt-get dist-upgrade” I received this: Looks like GRUB-PC was updated and now it asks: What do you want to do about modified configuration file grub?What do you want to do about modified configuration file grub? I selected “Keep the local version currently installed”. Then it happeared another window asking this: […]

How to Permanently Run NodeJs Script in Background

You can use the Node package named Forever to run continuously a NodeJs script. The advantage of using “forever” package is that it can make a NodeJs script execute forever even after the node script process is killed, because it gets respawned! 1) Install Node “forever” package npm install forever -gnpm install forever -g 2) […]

How to Stop NodeJs Puppeteer Follow Redirects

Coupling setRequestInterception() with request.isNavigationRequest() and request.redirectChain() you can now abort navigation redirects in Puppeteer like this: await page.setRequestInterception(true); page.on(‘request’, request => { if (request.isNavigationRequest() && request.redirectChain().length) request.abort(); else request.continue(); }); await page.goto(‘https://example.com’);await page.setRequestInterception(true); page.on(‘request’, request => { if (request.isNavigationRequest() && request.redirectChain().length) request.abort(); else request.continue(); }); await page.goto(‘https://example.com’); References: https://github.com/GoogleChrome/puppeteer/issues/1132#issuecomment-393724933

NodeJs How to Get GET Query String in Express.js

With Express.js you can use req.query like this: var express = require(‘express’); var app = express();   app.get(‘/’, function(req, res){ res.send(‘id: ‘ + req.query.id); });   app.listen(8088);var express = require(‘express’); var app = express(); app.get(‘/’, function(req, res){ res.send(‘id: ‘ + req.query.id); }); app.listen(8088); It handles the $_GET[‘id’] GET query, i.e: http://127.0.0.1:8088/?id=123http://127.0.0.1:8088/?id=123

NodeJs How to Split/Splice Array in Chunks

To split an array in chunks in NodeJs you can use splice(): var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; var b = a.splice(0,10);   //a is now [11,12,13,14,15]; //b is now [1,2,3,4,5,6,7,8,9,10];var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; var b = a.splice(0,10); //a is now [11,12,13,14,15]; //b is now [1,2,3,4,5,6,7,8,9,10]; You can also loop the array and do something with the […]

NodeJS Error: Socket Hang Up (ECONNRESET)

Users have reported this ECONNRESET error with request.get(): Error: { Error: socket hang up at TLSSocket.onHangUp (_tls_wrap.js:1137:19) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:111:20) at TLSSocket.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) code: ‘ECONNRESET’, path: null, host: ‘google.com’, port: 443 }Error: { Error: socket hang up at TLSSocket.onHangUp (_tls_wrap.js:1137:19) at Object.onceWrapper (events.js:313:30) […]

PHP Notice: Undefined offset: 1 (Array)

How to fix PHP Notice: Undefined offset: 1? This PHP snippet will generate a “Undefined Offset” notice: $parts = explode(".", "aaaa");   $data = $parts[1];   print_r($data);$parts = explode(".", "aaaa"); $data = $parts[1]; print_r($data); This happens because $parts[1] is undefined. To fix this “Undefined Offset” notice just check if isset($parts[1]): $parts = explode(".", "aaaa");   […]

How to Sleep/Wait/Pause on a NodeJs Function

I found this example code that shows how to sleep in NodeJs: function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }   async function demo() { console.log(‘Taking a break…’); await sleep(2000); console.log(‘Two seconds later, showing sleep in a loop…’);   // Sleep in loop for (let i = 0; i < 5; i++) { […]