• WSL (Windows Subsystem Linux) Folder in Windows

    From the Windows side

    Use standard Windows networking paths to view your Linux folders using Windows Explorer. In the search box, enter:

      \\wsl$
    

    That will bring you to the root directory of your Linux install. To get to your home directory, try something like this, with your version of Linux.

      \\wsl$\Ubuntu-18.04\home\
    

    From the Linux side

    From Windows terminal or your Linux distribution such as Ubuntu, enter:

      explorer.exe .
    

    This will open up Windows Explorer in the folder where you were in Linux.

    Use Visual Studio Code if you want an editor that works wonderfully with WSL. Within VSCode, click on the icon on the bottom left corner to connect to your Linux install.

    references

    https://docs.microsoft.com/en-us/windows/wsl/install-win10

    Windows Subsystem Linux runs under Insider Build for Windows 10.

    14 Mar 2020
  • Ruby Structs Example

    Structs are a built-in Ruby class that can act like a custom class. They are great for testing, debugging and playing.

    LunchOrder = Struct.new(:name, :drink, :food)
    event_order = []
    event_order << LunchOrder.new('hakeem', 'water', 'Mixed Veggie')
    event_order << LunchOrder.new('selena', 'mango lasse', 'Bangkok Dumplings')
    event_order << LunchOrder.new('jingyan', 'tea', 'Yellow Curry')
    drinks = event_order.map(&:drink)
    

    Structs are compared by value equality rather than referential equality. If two struct objects have the same value they are equal. Classes with the same values are not equal.

    references

    https://www.leighhalliday.com/ruby-struct

    https://blog.bigbinary.com/2018/01/16/ruby-2-5-allows-creating-structs-with-keyword-arguments.html

    Keyword parameters in structs were introduced in Ruby 2.5

    07 Mar 2020
  • How to Split Long Lines in Rspec

    It can be challenging to know where to break a long line in ruby. Especially when writing tests in rspec.

    RSpec.describe PostHelper, :type => :helper do
      describe '#markdown' do
        it 'returns code blocks' do
          blog_text = "```ruby\nHello, World!\n```"
          expect(helper.markdown(blog_text)).to eq("<pre><code class=\"ruby\">Hello, World!\n</code></pre>\n")
        end
      end
    end
    

    One technique is to find the method call, .to in the example above, and break it there.

    RSpec.describe PostHelper, :type => :helper do
      describe '#markdown' do
        it 'returns code blocks' do
          blog_text = "```ruby\nHello, World!\n```"
          expect(helper.markdown(blog_text)).
            to eq("<pre><code class=\"ruby\">Hello, World!\n</code></pre>\n")
        end
      end
    end
    

    Rubocop can help improve your ruby style. Rubocop is available as an extension in Visual Studio code.

    03 Mar 2020