String interpolation

Tags

Javascript

const job = 'Software engineer';
console.log(`I'm a ${job}!!!`);

Ruby

job = 'Software engineer';
puts "I'm a #{job}!!!"

Ruby: How to access instance variables inside a Ruby block?

Tags

## Sample module
module MyMod
  class Foo
    def initialize()
      @id = SecureRandom.uuid
      yield self if block_given?
    end
  
    attr_accessor :id
  end
end

## This is a block
t = MyMod.foo 'hello world' do
 puts t.id    <== doesn't work
 puts self.id <== Dios ko dai dili gihapon mo work
end

## Here's the solution:
t = MyMod.foo 'hello world { |data|
  puts data.id  <== it works! sample return c326401b-4320-448b-a7ba-7a0f2a49e702
}
...
...

sqlite3 – Gem::LoadError

Tags

,

Problem:
If you’ve encountered an error like this:

/home/armano/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/connection_specification.rb:176:in `rescue in spec’: Specified ‘sqlite3’ for database adapter, but the gem is not loaded. Add `gem ‘sqlite3’` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

Solution:
gem ‘sqlite3’, ‘~> 1.3.6’, ‘< 1.4'

Ubuntu 16: Can connect to WIFI but no internet

Tags

The steps are :
1. add a line nameserver 8.8.8.8 in /etc/resolv.conf
2. install unbound with sudo apt-get install unbound
3. disable the troublesome daemon with:
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
4. add dns=unbound in the [main] section of /etc/NetworkManager/NetworkManager.conf

5. enable unbound with:

sudo systemctl enable unbound-resolvconf

sudo systemctl enable unbound
6. Reboot the computer

Reference:
https://askubuntu.com/questions/965527/dns-problems-after-upgrading-from-16-04-to-17-10-how-to-reset-the-dns-settings