Thursday, June 18, 2020

[SOLVED] initramfs unpacking failed: write error (VirtualBox)

I was trying to install Manjaro Linux in VirtualBox and I got that error. Solution is simple: grow the VM memory. I changed it from 512MB to 1024MB and it ran fine.

Sunday, May 31, 2020

Domain serving SSL certificate of a subdomain

Today one of my sites was serving a SSL certificate of a subdomain instead of the domain's one, after configuring the SSL certificate for the subdomain with certbot for Apache.

It took me some hours of investigating and tries.

The problem is that certbot changed the domain.conf file in /etc/apache2/sites-available folder to serve the subdomain's SSL certificate. Editing the file and reloading Apache solved it.

Wednesday, January 8, 2020

Time adjustment for DigitalOcean droplets

Hello!

I have some droplets on DigitalOcean, but I noted that the system time (in all of them) is not correctly synced with NTP servers.

The solution that worked for me is to include the following line at the end of /etc/crontab:

* * * * * root /sbin/hwclock -s

That command instructs the system to copy time from hardware (which is more precise) every minute. That solved my problem.

Friday, December 27, 2019

Troubleshooting Ruby 2.7 compiler errors

So Ruby 2.7 was released at Xmas'19 and I got some errors when compiling it in Linux Mint 19.1. Some libraries were not configured. The errors ocurred at the linking phase of make. Five libraries got errors, and I'll walk across their solutions:

  • openssl:
    sudo apt install libssl-dev
  • gdbm:
    sudo apt install libgdbm-dev
  • dbm:
    sudo apt install libqdbm-dev
  • readline:
    sudo apt install libedit-dev
  • zlib:
    sudo apt install libz-dev
    cd /lib/x86_64-linux-gnu/
    sudo ln -s libz.so.1 liblibz.so

Enjoy!

Monday, May 13, 2019

Detecting key press in Ruby

To check whether a key is pressed in linux (non-blocking, non-waiting).
def keypressed
  system('stty raw -echo') # => Raw mode, no echo
  char = (STDIN.read_nonblock(1).chr rescue nil)
  system('stty -raw echo') # => Reset terminal mode
  char
end
Inspired on https://stackoverflow.com/a/22659929.

Saturday, October 27, 2018

Net::HTTP error sending GET request with parameters

If you're getting trouble with Net::HTTP#send_request when sending a GET request with parameters, one possible cause is that parameters must be part of path as a query string, and not as data (3rd parameter of #send_request).

For example (assuming that parameters is not empty), instead of

http = Net::HTTP.new('server.com')
http.send_request('GET', path, parameters, headers)

try:

http = Net::HTTP.new('server.com')
http.send_request('GET', path + '?' + parameters, '', headers)

Net::HTTP error 400 (bad request) with HTTPS

Hello, friends!

Yesterday I got stuck when trying to connect to an HTTPS site using Net::HTTP:

      http = Net::HTTP.new('server.com', 443)
      response = http.send_request('GET', path, parameters, headers)

I was getting error 400 in response.code.

What is not well documented is that when accessing a server via HTTPS protocol it's not enough to set port to 443. You must also set use_ssl to true:

      http = Net::HTTP.new('server.com', 443)
      http.use_ssl = true
      response = http.send_request('GET', path, parameters, headers)