Categories
Programming

Serving Flask app with Nginx

So you have build a Flask application and now you want to server the application in the web. In this tutorial, I’m going to teach how you can do that with Nginx on an Ubuntu platform.

Categories
Programming

Updating Rails app gems

Past few weeks, we have been focusing on updating Gems of our Rails application.

Categories
Programming

DynamoForms : a library to validate forms only with HTML

This article about my recent work I have done in creating a JavaScript based HTML form validation library.

Categories
Programming

Debugging CkEditor for tests

This week has been an interesting week as it was mostly debugging and fixing tests.

Categories
Programming

Control Philips Hue with Google Assistant SDK on Ubuntu

In this article, I’m going to teach how I manage to integrate Philips Hue bridge with Google Assistant SDK to control my smart lights.

Categories
Programming

Sometimes you have to look back when debugging

Last week has been a firefighting week at work (i.e. debugging and troubleshooting). I’m writing this article to share my experience with debugging a system configuration at work. In the end of article, I have placed some lessons learned points so hopefully someone can learn from it to improve their career.

Categories
Programming

Opening Right-click Menu / Context menu with Selenium WebDriver

Selenium WebDriver providesActionBuilder to perform complex user interactions with a web page. It allows chaining multiple actions together to perform a complex action.

You can create a complex action and execute the action (perform) it in the following manner. (Ruby)

driver.action.key_down(:shift).
              click(element).
              click(second_element).
              key_up(:shift).
              drag_and_drop(element, third_element).
              perform

 

The action to open the context menu is context_click() .

driver.action.context_click(webdriver_element).perform

By default, it will click on the middle of the element if you provide one.  Otherwise, it will click where the mouse pointer is at.

If you want to move the pointer to a specific location of the page before clicking, use methodmove_to.

 

If you want to select an item from the context menu use arrow keys and enter then perform the action. You can also further pinpoint the cursor position by using  custom position from your element reference

page.driver.browser.action.move_to(webdriver_element, 5, 10)
 .context_click
  .send_key(:arrow_down)
 .send_keys(:enter)
 .perform

 

Ref: http://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/ActionBuilder

Categories
Programming

How to ignore PostgreSQL tables when restoring a database

At my current workplace, we use a copy of the backup database which is created by pg_dump to restore in our development machines. Since the database has a lot of audit tables which adds up a lot of space, I needed an easier way to ignore these tables when restoring the database.

Apparently pg_restore can generate a list of tables in the dump file archive. The advantage is that we can use the same list to specify what content we need to restore.

pg_restore options

Here are the pg_restore options we are going to use for this.

-l --list
List the contents of the archive. The output of this operation can be used as input to the -L option. Note that if filtering switches such as -n or -t are used with -l, they will restrict the items listed.

-L list-file --use-list=list-file
Restore only those archive elements that are listed in list-file, and restore them in the order they appear in the file. Note that if filtering switches such as -n or -t are used with -L, they will further restrict the items restored.

list-file is normally created by editing the output of a previous -l operation. Lines can be moved or removed, and can also be commented out by placing a semicolon (;) at the start of the line. See below for examples.

Steps

Let’s generate the list while ignoreing the content for the tables we don’t need. Note that I use an inverse grep statement to ignore the content of the tables where the table names that ending with _audits and create the output in restore.list file.

pg_restore -l <dump_file.data> | grep -v 'TABLE DATA public .*_audits' > restore.list

Then simply use -L to tell pg_restore to use the restore.list file.

pg_restore -U #{USERNAME} -O -L restore.list -v -c -d atlas_development PostgreSQL.sql

Ref
pg restore options: https://www.postgresql.org/docs/10/static/app-pgrestore.html

Categories
Programming

Vagrant – Running Rails server in the background

Let’s say when you boot up or restart your virtual machine, you want to run the Rails server in the background for your Rails application.

It is pretty easy. First, let’s create a function for the script block. Put following code on the top of the Vagrant file.

def start_rails_server
<<-SHELL
cd /vagrant
# start rails server as a daemon
# to kill: sudo kill `cat tmp/pids/server.pid`
rails s -d
SHELL
end

Now in the Vagrantfile configuration block, use the script function and set it to run always. 

Vagrant.configure("2") do |config|
...
config.vm.provision "shell", inline: start_rails_server, run: 'always'
...
end
Categories
Programming

Setting up Ruby SDK for RubyMine with Vagrant

This article is about how you can configure to use the Ruby SDK in your Vagrant image with RubyMine.

For this, I have used the  joshfng/railsbox Vagrant image because I was using that image for a Rails project. 

First you have to find where is your Ruby interpreter located for your project. Let’s assume your project lies in the same folder where you have Vagrantfile. In this case, by default the /vagrant folder in the vagrant image will contain your code.

To find the ruby path, here type `which ruby`. Then it will spit out the location. You have to remember this location. In my it was ‘/home/vagrant/.rbenv/shims/ruby’.

Now, to link to the vagrant ruby interpreter, you have to open the preferences dialogue and then select  Languages & Frameworks > Ruby SDK and Gems.

Then click on + and select remote location as the location and select vagrant.

For the Vagrant path, give the folder where your Vagrantfile is located. For the Ruby interpreter path, give the path you found before.

Click Ok.

Now Rubymine should load up the necessary gems to itself which will take some time. But after that, you should be good to go!