Replace characters on filenames of all files in a folder (Windows)

First run PowerShell and set the current directoy to the folder where are the files: cd C:\path\to\foldercd C:\path\to\folder To replace a certain character on filenames of all files in a folder, type: Get-ChildItem -name | ForEach-Object { Move-Item $_ $_.replace(" ", "_") }Get-ChildItem -name | ForEach-Object { Move-Item $_ $_.replace(" ", "_") } The above […]

Rotate Nginx vHosts Log Files Every 1 Year

Set logrotate to keep 1 year (365 days) of log files: sed -i ‘s/rotate 52/rotate 365/’ /etc/logrotate.d/nginxsed -i ‘s/rotate 52/rotate 365/’ /etc/logrotate.d/nginx

PHP Check if a File is an Office 2007 Document by MIME Content Type

Simple PHP function to check if a file is an Office 2007 document by filtering the content type: function isOfficeDocumentByMIMEContentType($str) { //https://blogs.msdn.microsoft.com/vsofficedeveloper/2008/05/08/office-2007-file-format-mime-types-for-http-content-streaming-2/   $array = array( "application/msword", //doc "application/msword", //dot "application/vnd.openxmlformats-officedocument.wordprocessingml.document", //docx "application/vnd.openxmlformats-officedocument.wordprocessingml.template", //dotx "application/vnd.ms-word.document.macroEnabled.12", //docm "application/vnd.ms-word.template.macroEnabled.12", //dotm "application/vnd.ms-excel", //xls "application/vnd.ms-excel", //xlt "application/vnd.ms-excel", //xla "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", //xlsx "application/vnd.openxmlformats-officedocument.spreadsheetml.template", //xltx "application/vnd.ms-excel.sheet.macroEnabled.12", //xlsm "application/vnd.ms-excel.template.macroEnabled.12", //xltm "application/vnd.ms-excel.addin.macroEnabled.12", //xlam "application/vnd.ms-excel.sheet.binary.macroEnabled.12", […]

Determine if user is on mobile device with Javascript

Easiest way to determine if user is on mobile device with javascript: if (/Mobi/i.test(navigator.userAgent) == true || /Android/i.test(navigator.userAgent) == true ) { // Mobile device detected }if (/Mobi/i.test(navigator.userAgent) == true || /Android/i.test(navigator.userAgent) == true ) { // Mobile device detected }

Show Google AdSense based on User’s Device

Let’s say I want to show Google AdSense after the .header class for non-mobile devices (desktops, laptops, etc), and show Google AdSense before a form on mobile devices only. Here is the jQuery code example: // Show Google AdSense after the .header if device is not mobile if (/Mobi/i.test(navigator.userAgent) == false && /Android/i.test(navigator.userAgent) == false […]

1 Dedicated Server (Xeon) vs 5 C2S Scaleway (Avoton)

Today I wanted to test how many concurrent connections can handle a single dedicated server (Dedibox Classic 2016 with Xeon D-1531 @ 2,20 GHz, 32GB DDR4, 250GB SSD) vs how many concurrent connections can handle 5 small servers (C2S Baremetal Server with Avoton C2550 @ 2,40 Ghz, 8GB DDR3, 50GB SSD) that balance traffic with […]

OptinMonster and jQuery 3.2.1 Slim (Issue)

Looks like that OptinMonster does not load the campaign if you use jQuery 3.2.1 Slim version. To fix this, I have used the normal jQuery (minified) .js file like this: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> And then I made sure OptinMonster does not load jQuery 1.12.2: <script>var om_load_jquery = false;</script><script>var om_load_jquery = false;</script> After the above trick […]

PHP Google reCAPTCHA v2

First you need to create the Google reCAPTCHA v2 key for your website. This is the HTML form example that shows the reCAPTCHA: * Replace YOUR_SITE_KEY_HERE with your site key * <form action="" method="post"> <div class="form-group" style="max-width: 303px;"> <input type="email" name="email" placeholder="Enter email here…" class="form-control" required email> </div> <div class="form-group"> <div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY_HERE"></div> </div> <button […]