Wednesday, October 10, 2018

Test DHCP Server

Testing dhcp server works as expected, like after configuring MAAS dhcp

sudo nmap --script broadcast-dhcp-discover -e cbr0

Tuesday, June 6, 2017

Trasnfer Docker Image Offline

Export docker image:
docker save -o export-docker-image.tar my_image:latest

Import docker image in destination:
docker load -i export-docker-image.tar

Friday, January 20, 2017

Local Insecure Docker Registry

Start the local registry:
docker run -d -p 5000:5000 --restart=always --name registry registry:2

Get image:
docker pull ubuntu && docker tag ubuntu localhost:5000/ubuntu

Push to the local registry:
docker push localhost:5000/ubuntu

Enable insecure docker registry for engine in /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry 10.0.1.11:5000

Pull image
docker pull localhost:5000/ubuntu


Thursday, December 15, 2016

Enabling jQuery to Lookup in Simple Page (in console)

Assuming the loaded page is simple page like the apache directory list as known as "index of /..."
No jquery is there, just the core javascript by browser

Loading jQuery:
var s = document.createElement('script');
s.setAttribute('src', 'http://code.jquery.com/jquery-latest.min.js');
document.body.appendChild(s)

Now using jquery to do your stuff like finding the links
var links = $('a[href*="1080"]')
for(var i = 0; i < links.length; i++) {
  if(links[i].href.indexOf('x265') > 0)
    console.log(links[i].href);
}

Tuesday, December 6, 2016

Handling One or Multiple Selection in Grails

Scenario:
We have a select in the form with id="book".
The user may choose none, 1 or multiple in select and submit the form.
There is an each loop in the controller/service to process each user.

What happen:
For each selected book in the select one book=N parameter is posted to the controller.

Grails controller which creates params automatically brings a little intelligence and convert the params to a list if there are multiple instances of that parameters, so in the case of multiple book selection the params will be something like this:

params.book = [ N, M, ...]
It is great and we can loop on it and do the operation on each of them.

But..., if just one user is selected, the there will be no list by default and the param contains just a simple string

params.book = "N"

The bad:

  • The loop is not failed, it is a string and loop iterate over each char of the string
  • In the development and simple test cases, it works perfectly. For example, if it is the id like 5, then it is just a char same as the original. But if the id grows and become something like "58", then your loop process object id 5 and 8.
Solution:
Use params.list method to create a list for that parameter, even if it is single.
def bookIds = params.list("book")

Friday, November 25, 2016

Add to Local Maven Repo, then use it Gradle

Install downloaded jar file (here sqlserver jdbc driver) in local maven repository

mvn install:install-file -Dfile=sqljdbc41.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.1 -Dpackaging=jar

In gradle file add mavenLocal() and use the lib as normal maven dependency.


Tuesday, November 8, 2016

Rails Regenerate Scaffolding Views

rails g erb:scaffold ModelName

The scaffolds can be customized by copying originals to lib/templates/erb/scaffold/templates


The original templates and generators can be found in railties gem directory like

lib\ruby\gems\2.2.0\gems\railties-5.0.0.1\lib\rails\generators