Google Cloud SQL and Public IP Address Security

When you create a SQL cloud instance and you use a public IP address (external IP) on the SQL instance, make sure that your Compute Engine instances that will connect to the public IP of the SQL instance will have a static IP address and not temporary, else if the IP address is temporary it […]

How to use Highlight.js to highlight code

Using Highlight.js to highlight code is simple: First include this inside the HEAD tag of the HTML page: <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/darcula.min.css" /> <script>hljs.initHighlightingOnLoad();</script><script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/darcula.min.css" /> <script>hljs.initHighlightingOnLoad();</script> Then you can use it like this: <code class="json"> {name: "John", age: 31, city: "New York"} </code><code class="json"> {name: "John", age: 31, city: "New […]

Nginx HTTP to HTTPS and non-www to www behind Google Load Balancer

First create two forwarding rules on Google Load Balancer (frontend): – One for HTTPS (port 443) traffic – One for HTTP (port 80) traffic Then make sure both rules use the same static IP address. Now on the Compute Engine backend, edit the Nginx config file: server { listen 80; server_name localhost; access_log /var/www/nginx/logs/access.log main; […]

Quota ‘IN_USE_ADDRESSES’ exceeded. Limit: 8.0 in region

If you get this error message when you try to create a new Compute Engine instance: Quota ‘IN_USE_ADDRESSES’ exceeded. Limit: 8.0 in region…Quota ‘IN_USE_ADDRESSES’ exceeded. Limit: 8.0 in region… Then it looks like you reached the quota of IP addresses in use. To solve this, you need to ask to modify the quota of: This […]

Only allow Google Load Balancer traffic (Firewall Rules)

For security reasons you should only allow incoming traffic from Google Load Balancer on your backend instances. To do so, when making a GCE firewall rule, just set the Source IP ranges to these GCE IPv4 ranges: 130.211.0.0/22 35.191.0.0/16130.211.0.0/22 35.191.0.0/16 Read more here: Google Cloud Load Balancer Firewall Rules Tuning NGINX behind Google Cloud Platform […]

Lost connection during Debian apt-get upgrade

If you lost the SSH connection on Debian while apt-get upgrade: 1) Re-login to your SSH server 2) Find the running instance of apt-get upgrade: ps aux | grep -E ‘release|upgrade|apt’ps aux | grep -E ‘release|upgrade|apt’ 3) Then kill it with kill PID 4) Type “dpkg –configure -a” to recover the apt-get upgrade 5) Done!

Bootstrap 3 Navbar with Logo Image

The correct way to use a logo image on the Navbar on Bootstrap 3 is: <a href="#" class="navbar-left"><img src="/path/to/image.png"></a><a href="#" class="navbar-left"><img src="/path/to/image.png"></a> Do not use class=”navbar-brand” in A HREF because it adds text-like styles. Reference: https://stackoverflow.com/a/26333342 If the logo image is too on top, just add this code in the .CSS file: .navbar-default .navbar-left img […]

Redis HMGET, HGETALL, HSET, HGET Benchmark

Today I tested HMGET, HGETALL, HSET, HGET performance. Here are my tests, see the “requests per second” value for comparisons: TESTING GET COMMAND     root@server:~# redis-benchmark -h 127.0.0.1 -p 6379 –dbnum 1 get MYKEY ====== get MYKEY ====== 100000 requests completed in 3.27 seconds 50 parallel clients 3 bytes payload keep alive: 1   […]

PHP GetHostByName() Slow? Make it Faster

Sometimes gethostbyname() can take up to 5 seconds and more to complete. Here are two smart tricks to make it faster: // Set timeout and retries to 1 to have a max execution time of 1 second for the DNS lookup putenv(‘RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1’);   // Make sure the domain ends in a dot […]

Use Timestamp with new DateTime() in PHP

You can use a unix timestamp within DateTime() like this: $today = new DateTime("@".time()); $tomorrow = new DateTime("@".strtotime("+13 months"));$today = new DateTime("@".time()); $tomorrow = new DateTime("@".strtotime("+13 months")); See that we prepend “@” char before the timestamp.