PHP Correctly Get Last 12 Months (Month per Month)

PHP snippet to get the last 12 months, month per month: $dt = new DateTime(‘first day of this month’);   for ($i = 1; $i <= 12; $i++) { echo $dt->format(‘M Y’), "\n";   $dt->modify(‘-1 month’); }$dt = new DateTime(‘first day of this month’); for ($i = 1; $i <= 12; $i++) { echo $dt->format(‘M […]

PHP StrToTime() Returns Incorrect Timestamp ‘-1 MONTH’

If you use date() with strtotime() to get the last 12 months (or the last 1 month, the last 2 months, etc) you may have noticed that when you are on the last day of the current month, i.e 31 of May, you will get repeated months, for examples: echo date("M Y"); echo date("M Y", […]

Nginx Redirect From a Website to Another Website

This Nginx config can redirect your website to another website: server { listen 80; server_name website.com www.website.com; access_log /var/www/website.com/logs/access.log main; error_log /var/www/website.com/logs/error.log warn; root /var/www/website.com/htpdocs; index index.html index.htm index.php;   return 301 http://www.newsite.com$request_uri; }server { listen 80; server_name website.com www.website.com; access_log /var/www/website.com/logs/access.log main; error_log /var/www/website.com/logs/error.log warn; root /var/www/website.com/htpdocs; index index.html index.htm index.php; return 301 http://www.newsite.com$request_uri; […]

PHP Multi-cURL to Run Parallel cURL Requests (Example)

Simple PHP function to run multiple cURL requests in parallel: function multicurl_urls($nodes) { $node_count = count($nodes);   $curl_arr = array(); $master = curl_multi_init();   for($i = 0; $i < $node_count; $i++) { $url =$nodes[$i]; $curl_arr[$i] = curl_init($url); curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true); curl_multi_add_handle($master, $curl_arr[$i]); }   do { curl_multi_exec($master,$running); } while($running > 0);   $results = array(); […]

Vertically align Facebook and Twitter share buttons

HTML code to vertically align Facebook and Twitter share buttons: <div class="d-inline"> <style>.fb_iframe_widget span { vertical-align: baseline !important; }</style> <div class="fb-like" data-href="http://www.yourwebsite.com/" data-layout="button_count" data-action="like" data-size="small" data-show-faces="false" data-share="true"></div> <a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-show-count="false">Tweet</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> </div><div class="d-inline"> <style>.fb_iframe_widget span { vertical-align: baseline !important; }</style> <div class="fb-like" data-href="http://www.yourwebsite.com/" data-layout="button_count" data-action="like" data-size="small" data-show-faces="false" data-share="true"></div> <a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-show-count="false">Tweet</a><script […]

Download Windows 10 ISO without Media Creation Tool

You can download the official Windows 10 ISO file without Media Creation Tool from the Microsoft.com website. Just follow these simple steps: 1) On your browser install an add-on to change the user agent Download User Agent Switcher for Mozilla Firefox Download User Agent Switcher for Google Chrome 2) Change the user agent to Apple […]

Firefox add-ons cannot be verified and have been disabled

On May 4 2019 the web browser Mozilla Firefox started to show a warning message “One or more installed add-ons cannot be verified and have been disabled” and all installed browser extensions were all disabled. This created some panic within Firefox users and myself too, as I found all my Firefox extensions disabled without an […]

Python Socket IPv6 (AF_INET6) Listen

Listen on an IPv6 address and port in Python with socket(): ADDR = (HOST, PORT) serversock = socket.socket(family=socket.AF_INET6) serversock.bind(ADDR) serversock.listen(0)ADDR = (HOST, PORT) serversock = socket.socket(family=socket.AF_INET6) serversock.bind(ADDR) serversock.listen(0) Change HOST and PORT as needed.

Allow User to Run Sudo Command without Password

You can edit /etc/sudoers file and add a line like this: carlo ALL=(ALL) NOPASSWD: /usr/bin/programcarlo ALL=(ALL) NOPASSWD: /usr/bin/program So when user carlo runs “sudo /usr/bin/program” he’ll not need to enter the password. Useful to allow an user to run specific programs with sudo without password.

Fix Nginx 400 Bad Request: The SSL certificate error

I have a website where I am using Nginx + SSL by Lets Encrypt and some users reported continuous “400 Bad Request” errors. I digged the event and looks like this trick fixed the issue: Add this to your Nginx vhost config file inside server {} section: error_page 497 https://$host$request_uri;error_page 497 https://$host$request_uri; Reference: https://stackoverflow.com/a/55029648 https://stackoverflow.com/a/14241127