Monday, December 18, 2017

Ubuntu remove error repository from apt update

When you add a repository URL that doesn't work and later when you do 'sudo apt-get update' and it starts throwing errors; use the below command to remove it.

sudo add-apt-repository --remove <url>

Replace the <url> with error repo URL.

Ex: sudo add-apt-repository --remove http://ppa.launchpad.net/ondrej/mysql-5.6/ubuntu

Happy Coding!

Wednesday, December 13, 2017

Github clone only a sub-directory of a repository

If there is a need to download only a sub-directory of the full Github repo, you can do the following steps to clone the required directory.

  • git clone <repo root url> <name of the sub-directory>
  • cd <name of sub-directory>
  • git filter-branch --prune-empty --subdirectory-filter <path to sub-directory> HEAD 
Ex: Let's say you need to clone the apim-is-as-keymanager-sso directory from https://github.com/wso2/presales-demos GitHub repo. Execute the following commands.
  • git clone https://github.com/wso2/presales-demos apim-is-as-keymanager-sso
  • cd apim-is-as-keymanager-sso
  • git filter-branch --prune-empty --subdirectory-filter apim-is-as-keymanager-sso HEAD 
Happy Coding!

Thursday, November 2, 2017

How to run MSF4J service in Docker

In order to create your microservice project you need to have Maven and JDK installed on your developer machine. Then once you get the executable jar of the MSF4J project you can run this in any of the Docker hosting machines. For the hosting environment, you only need to have Docker installed on the hosting machine. 

  • Enter the following lines into your Dockerfile.
    • This will grab an existing docker image which will create the JDK runtime environment to run the jar file. 
    • Then the script copies the jar file into /tmp directory.
    • Next, it exposes port 8080 to run the service.
    • Finally, it runs the jar file
  • Execute the following commands in terminal to run the Dockerfile.
Happy coding!! 

Wednesday, October 25, 2017

Arduino - upload the hex file through command line terminal

Below is an example command I use to load the hex file to Arduino Uno development board by executing the command in Linux terminal.

arduino-1.6.12/hardware/tools/avr/bin/avrdude -Carduino-1.6.12/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:grbl_v0_9a_edge_328p_16mhz_9600_build20121210.hex:i

However, the command might differ depending on your development board type. To find the exact command that needs to be executed, we can use a basic sample.ino file and upload it via Arduino IDE. Then in order to see what the commands that get executed in the background we can enable logs and see them through the console.

How to enable console logs:

  • Go to File -> Preferences
  • Enable show verbose output during upload

Now check for the console output and find the appropriate command.

Cheers!!

Sunday, August 20, 2017

WSO2 IoT Server 3.1.0 Released!

Awesome news buddies!! We have released the latest WSO2 Iot 3.1.0 version!! Many new features are incorporated into this release.
  • A complete API-driven device type definition eliminating the necessity to create deployable plugins
  • Support for location based services, such as Geofencing and alerting
  • A redesigned device overview page for better user experience
  • Improved product profiles for scalable deployment
  • Performance enhancements
  • Enhancements to pre built agents
Visit our product page[1] and try it out!! You will be amazed!! 


Happy Coding!

Thursday, May 25, 2017

Moving Jira tickets to Github automation

When you need to move your existing issue list from Jira to Github the following project will come in handy.

https://github.com/amalhub/github-automation

The project has been made to automate the process of moving Jira tickets to Github issues. In this approach I've used the Jira issue list export functionality to export the issue list into an XML file and then using the Github API, I have automated the process of pushing the issue list into Github.

If you want to perform a bulk operation on the moved Jira issues refer Editing multiple Jira issues at the same time. Using this functionality you can add a comment in the Jira directing the user to the Github issue list (Since the Git issue header contains the Jira issue id user can easily search for it).

Example comment: "Moved to Github issues: ${link}. Search with Jira issue ID to find it in Git."

Follow the ReadMe file in the project and you will be done with the process in no time!

Happy Coding!!

Friday, May 19, 2017

Maven build, how to replace only a part of regexp match

The following configuration will be useful when you need to replace a subsection of a regular expression match in a file at maven build.

Usecase scenario:

Let's say you have a configuration file (conf.properties) with set of properties and you need to update the properties only related to ios.

Sample data:
carbon.device.mgt.input.adapter=false
carbon.device.mgt.ios.api=flase
carbon.device.mgt.ios.apns=false
carbon.device.mgt.ios.core=false
carbon.device.mgt.mobile.android=false
Expected outcome:
carbon.device.mgt.input.adapter=false
carbon.device.mgt.ios.api=true
carbon.device.mgt.ios.apns=true
carbon.device.mgt.ios.core=true
carbon.device.mgt.mobile.android=false
This is achievable by the maven-antrun-plugin.

Sample configuration:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>default-feature-install</id>
            <phase>package</phase>
            <configuration>
                <target>
                    <replaceregexp file="conf.properties" match="(ios.*)false" replace="\1true" byline="true"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Regular expression justification:

  • match="(ios.*)false"
    • The following regular expression will select the string that contains "ios" and "false".
    • But we only need to replace the "false" value to "true" in the regular expression selection.
    • Therefore I have grouped the selection using brackets so that it can be referenced in the substitution expression.
  • replace="\1true"
    • In the following substituion string I have used the "\1" to define that I need to include the 1st group selection as part of the replacement string. 
    • The rest of the selection will get replaced by the new value.
Happy coding !!!