Why .dev domains automatically redirect to HTTPS?

If you’re a web developer developing in local environment you most probably use .dev for projects you are working on. If you’re using Valet on Mac development is quite simple since every folder from your projects folder is instantly accessible in browser if you just enter folder name and add .dev. It works like magic without messing with any hosts files. It just works!

But then Google decided to complicate things a bit. First they have forced all .dev domains to use SSL. Since December 2017 Google Chrome version 63 started redirecting to all .dev domains to secure protocol replacing http:// with https:// in your urls without even asking you. The reason for that is maybe somehow related to fact that Google bought the .dev making it a legit gTLD. They don’t sell these (yet) and the use for this, and for more than 100 other gTLD Google now owns (including .app, .foo), is unknown but for sure it’s going to complicate lives of web developers.

Back to Chrome: this force-SSL feature can’t be turned off in Chrome settings (at least I was unable to find it) so you’ll have to install a self signed SSL so you can continue your work without these annoying SSL warnings. Installing SSL is super simple if you’re using Valet. All you need to do is just execute:

valet secure myproject

and it will automatically install SSL for that project and you can use it instantly in browser loading https://myproject.dev. Again Valet works like magic!

Also now with .dev being an official gTLD, it’s probably smart to change your preferred local development domain from .dev to something else like .test. Why .test? Well it’s much shorter than .localhost, it’s not owned by Google like (.dev or .app) and it’s reserved name by IETF for testing or development purposes to “reduce the likelihood of conflict and confusion”. Other reserved by IETF are .example, .invalid or .localhost and these are way too long for my taste and for often typing.

Replacing .dev with .test in Valet is also very simple. Valet to the rescue!

valet domain test

Now you can load https://myproject.test in your browser.

But what if you (for some reason) don’t want to use SSL. One of the projects I’m I am working on has many of the statics (images, css etc) loaded on CDN that doesn’t support SSL and when I work in local environment I get mixed content errors or simply these don’t load and site looks like mess. I have tried many different gTLDs including .dddd but for every one of them I guess that Chrome somehow figured that these are loaded from localhost and have instantly switched to secure channel. The only solution was to use a different browser like Safari (since Firefox also did pretty much the same thing). Since I got used to Chrome’s debugger I’d like to use a Chrome for this project without SSL. If someone knows how to disable this forcing of SSL on localhost please leave your solution in comments. Thank you!

 


How to DNS cache on Windows or macOS?

Almost all operating systems cache DNS records to improve the performance of applications and speed up internet access. Browsers do cache DNS records too and to flush these the easiest way is just to close the browser and start ti again. But sometimes there is a need to flush operating system DNS cache. Here’s how you can do that easily.

How to flush DNS cache on Windows XP / Windows Vista?

  • Step 1: Open the Command Prompt
    • Click on the Start Menu and click Run. Type in cmd and hit Enter.
  • Step 2: Flush DNS
    • Type ipconfig /flushdns and hit Enter.

 

How to flush DNS cache on Windows Vista or Windows 7?

  • Step 1: Open the Command Prompt
    • Click on the Start Menu and type cmd in the search bar and hit Enter.
  • Step 2: Flush DNS
    • Type ipconfig /flushdns and hit Enter.

 

How to flush DNS cache on Windows 8 or Windows 8.1?

  • Step 1: Open the Command Prompt
    • Hold Win key (windows logo key) and press letter X on your keyboard. Click on Command Prompt.
  • Step 2: Flush DNS
    • Type ipconfig /flushdns and hit Enter.

 

How to flush DNS cache on Windows 10?

  • Step 1: Open the Command Prompt
    • Hold Win key (windows logo key) and press letter X on your keyboard. Click on Command Prompt.
  • Step 2: Flush DNS
    • Type ipconfig /flushdns and hit Enter.

 

Starting Command Prompt in Windows 8 and Windows 10

Flushing the DNS cache in Command Prompt

 

How to flush DNS cache on Mac OS X 10.6 Snow Leopard

  • Step 1: Open the Terminal
    • Navigate to Applications -> Utilities -> Terminal
  • Step 2: Flush DNS
    • Type sudo dscacheutil -flushcache and hit Return.

 

How to flush DNS cache on Mac OS X 10.7 Lion and Mac OS X 10.8 Mountain Lion

  • Step 1: Open the Terminal
    • Navigate to Applications -> Utilities -> Terminal
  • Step 2: Flush DNS
    • Type sudo killall -HUP mDNSResponder and hit Return.

 

How to flush DNS cache on Mac OS X 10.9 Mavericks

  • Step 1: Open the Terminal
    • Navigate to Applications -> Utilities -> Terminal
  • Step 2: Flush DNS
    • Type sudo killall -HUP mDNSResponder and hit Return.

 

How to flush DNS cache on Mac OS X 10.10 Yosemite

  • Step 1: Open the Terminal
    • Navigate to Applications -> Utilities -> Terminal
  • Step 2: Flush DNS
    • Type sudo killall -HUP mDNSResponder and hit Return.

 

How to flush DNS cache on Mac OS X 10.11 El Capetain

  • Step 1: Open the Terminal
    • Navigate to Applications -> Utilities -> Terminal
  • Step 2: Flush DNS
    • Type sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder; and hit Return.

 

How to flush DNS cache on macOS X 10.12 Sierra and macOS X 10.13 High Sierra

  • Step 1: Open the Terminal
    • Navigate to Applications -> Utilities -> Terminal
  • Step 2: Flush DNS
    • Type sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderHelper; and hit Return.

 

 

How to flush DNS cache on Linux

Most current Linux distributions do not use a DNS resolver cache in the same way that Windows and Mac OS X use. However, as a common DNS caching application sometimes used is the Name Service Caching Daemon (nscd) or . It’s most likely not installed by default so there is no need to flush the cache. But, if you’ve already installed it you can flush the cache by running the following command in a terminal:

  • Step 1: Open the Terminal
    • Depends on the Linux system you have
  • Step 2: Flush DNS
    • Type /etc/init.d/named restart and hit Enter or
    • Type /etc/init.d/nscd restart and hit Enter (depending on the Linux distribution you have)

 

What’s DNS resolver cache?

Every time you visit a website or use any software that has access to the Internet (like Skype or WhatsApp) your browser, or that software, finds out on what actual IP address is the website (or server) that you are trying to access. It then stores this information for future use  by creating a record consisting of one IP address and that domain name that points to that IP address is created within operating system. If you want to visit that same website again, the system already knows on what IP address it’s wastes no time trying to find that out saving you time. These records are cached for certain period of time and are called DNS Resolver Cache.

 

Why would anyone want to flush this cache?

Well sometimes IP addresses of some websites or servers may change and your DNS resolver cache might still keep the old IP address. This can result in your computer not being able to reach the website or it reaches an older copy of it. In some circumstances the data may become corrupt and accessing some websites might fail. So, cleaning your DNS cache is something you can try doing when you can’t access some site or in case you know that the website’s IP has changed. It’s also very helpful for web developers or web admins when migrating websites to a new server or IP (other way around is by modifying hosts file).

 

How can DNS Resolver Cache data be viewed?

Windows: from a command prompt type ipconfig /displaydns and hit enter. If there is too much data you can save that in a text file using this command: ipconfig /displaydns > dnscache.txt and that will create the dnscache.txt file in the current folder and fill it with the output.

Mac and Linux: I don’t know how to do it. If you do please leave a comment. Thank you!


After upgrading mac from Sierra to High Sierra git no longer works

Recently I have upgraded your macOS on my MacBook Air from Sierra to High Sierra. After the update (that took some time to complete) everything seemed to be working fine… until I was about to do some more coding and have I tried to execute git. I’ve got this error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

To solve this bug, I had to execute this command:

xcode-select --install

 

This command downloads and installs xcode developer tools. After clicking on blue “Install” button and then clicking at another blue “Agree” button on xcode license agreement (that I haven’t read and I believe nobody ever did) and waiting for couple of minutes for it to download and install, everything was back to normal and I could git again. Hooray!


Easiest way to start CPU mining on DigitalOcean, AWS, Google Cloud in under one minute

So, you have probably read a dozen articles or seen a handful of clips on Youtube about  how to use DigitalOcean / Amazon AWS / Google Cloud / Azure / PaperSpace or some other cloud server to mine bitcoins (or some other cryptocurrency coins) and you probably already know it’s not profitable. I know that too but still I wanted to experiment with that a bit 🙂

Many cloud providers do not allow mining on their computers since these are mostly distributed systems so they aren’t happy when some user is using a resource at full power all the time. So, once they find out that someone is mining on their hardware they usually shut these servers down or even close accounts (rarely, but it can happen!) Finding that someone is using their hardware for mining is also quite easy since the CPU will be running at 100% all the time. So it will stand out from normal usage that’s probably nowhere close to that.

Also, mining Bitcoins with CPU today is not even theoretically possible now so don’t waste your time with that. On the other side there are some alternative crypto currencies that are made to be mined only with CPU and most of these use cryptonote algorithm. If you’re going to be mining with the CPU – then simply mine these. Currently, Bytecoin, Monero and Dashcoin are the most popular. For the purpose of this post I’ll use Bytecoin (BCN).

This experiment has two goals: first one is to install everything and start mining with just one command and second is to try and limit the CPU usage so and try and stay under the radar…

To install all required software and start with the mining process all you need to do is to just copy/paste and execute this single command in Ubuntu Linux shell:

apt-get update && apt-get install libcurl4-openssl-dev git -y && apt-get install build-essential -y && apt-get install autotools-dev autoconf -y && apt-get install libcurl3 libcurl4-gnutls-dev -y && cd ~ && git clone https://github.com/OhGodAPet/cpuminer-multi.git && cd cpuminer-multi && ./autogen.sh && CFLAGS=”-march=native” ./configure && make && make install && minerd -a cryptonight -o stratum+tcp://bcn.pool.minergate.com:45550 -u “geek@geektnt.com”

This will download all required software and start with the CPU mining process. The pool used is MinerGate so if you want to take credit for the mining just register your account there and replace your email with mine in the code above.

In case you reboot a server or simply stop the mining, all you need to restart it is to execute this command:

minerd -a cryptonight -o stratum+tcp://bcn.pool.minergate.com:45550 -u “geek@geektnt.com”

CPU mining without any limitations with the basic $5/month DigitalOcean droplet gives about 40 H/s

Mining without any cpu limits at ~40 H/s

CPU running on 100% all the time

Now as you can see in screenshots above your CPU usage will be around 100% all the time. Cloud providers can easily spot this kind of behavior and terminate your cloud/vps or even your account (you have been warned for the second time!) So, one possible solution to this problem is to lower the percentage of which the CPU will be used. This will lower the hash power and the returns (we’re not profitable anyways so who cares) but it may allow you to mine longer like this. (This is just an assumption. I haven’t tested this in practice! If you’re doing a such thing it’s your own responsibility for everything that can happen!)

This can be done by installing and using cpulimit, a tool that can limit the amount of CPU usage that some process can use. For the purpose of this experiment we’ll just limit the miner to use 50% of the CPU and to try and stay under the radar. Here’s the command that will automatically install everything needed and start mining with 50% of the CPU power:

apt-get update && apt-get install libcurl4-openssl-dev git -y && apt-get install build-essential -y && apt-get install autotools-dev autoconf -y && apt-get install libcurl3 libcurl4-gnutls-dev -y && apt-get install cpulimit && cd ~ && git clone https://github.com/OhGodAPet/cpuminer-multi.git && cd cpuminer-multi && ./autogen.sh && CFLAGS=”-march=native” ./configure && make && make install && cpulimit -l 50 — minerd -a cryptonight -o stratum+tcp://bcn.pool.minergate.com:45550 -u “geek@geektnt.com”

In case you need to restart the miner or you want the change the CPU usage limit (-l 50 translates to limit to 50% so you can just change that number) just use the code below:

cpulimit -l 50 — minerd -a cryptonight -o stratum+tcp://bcn.pool.minergate.com:45550 -u “geek@geektnt.com”

Once with the cpulimit in place to 50% of the available cpu power, our has rate has also lowered in half:

Mining with 50% limit at ~20 H/s

CPU usage with cpulimit set to 50%

 

Who can benefit from this: probably no one but it was fun.

Disclamer: Again, use this information at your own risk. I haven’t used this longer than one or two hours just for testing and for writing this article.

Advice: If you want to mine in cloud simply buy a mining contract from a reputable company such as Genesis Mining or HashFlare.


How to disable excessive resource usage alert emails?

If you have CSF firewall installed in cPanel you might noticed that you’re getting an email every time some process (usually a php script) uses more than 250MB of memory (default value) or more than 1800 secoonds (also default value).

These emails are being sent by LFD service that sends excessive resource usage alerts to the email address which is assigned to it, normally to root user account. This notification points out a particular process or service using excessive server resources and helps in identifying the resource eating process/service. We can either kill/stop the process/service to free the resource or allocate more resource to it, if necessary, increase the limits or simply do nothing and wait for it to finish it’s work.

Sample LFD email message when memory is exceeded:

—Time: Mon Nov 14 09:41:10 2016 +0530
—Account: xxxxxx
—Resource: Virtual Memory Size
—Exceeded: 205 > 200 (MB)
—Executable: /usr/bin/php
—Command Line: /usr/bin/php /home/xxxxxx/public_html/index.php
—PID: 26953 (Parent PID:24974)
—Killed: No

Sample LDF email message when execution time is exceeded:

—Time: Mon Nov 14 09:41:10 2016 +0530
—Account: xxxxxx
—Resource: Virtual Memory Size
—Exceeded: 125389 > 1800 (seconds)
—Executable: /usr/bin/php
—Command Line: /usr/bin/php /home/xxxxxx/public_html/index.php
—PID: 28429 (Parent PID:26561)
—Killed: No

Getting Started
1) Login to your WHM
2) Go to Home >> select Plugins
3) Click “ConfigServer Security & Firewall”
4) Locate and click at “Firewall Configuration” button

Method 1
This method will permanently disable the LFD excessive resource usage alert and you won’t receive any more emails. Performing this method could pose a a potential security/stability issue (you have been warned! 🙂 ).

5) Modify the value of directives PT_USERMEM and PT_USERTIME to 0.

PT_USERMEM = 0
PT_USERTIME = 0

Method 2
We will increase the values of both memory and time to stop or minimize the LFD alerts. If any process/service uses more resources than defined, you will still continue to receive the LFD alerts, but hopefully less.

5) Modify the value of directives PT_USERMEM and PT_USERTIME to desired.

PT_USERMEM = 500
PT_USERTIME = 150000

Finish
Save the changes you have made and restart CSF+LFD. By doing any of these two methods above should result in getting less or no email alerts from LFD.