100 Days of Code – second edition

In 2016/04/10 I start 100 days of code challenge. It was not easy and I almost have done it. Almost it means that one day stays without commit. But happy information is that 99 days was with at least one commit. I was a very busy time for me. I learn a lot, especially how to code in Python. But this one-day caused that this whole challenge it does not count. So from today I start again nex, the second edition 100 days of code challenge. Rules are the same.

zrzut-ekranu-2016-11-23-o-01-26-32

As we can see in above picture there is the screenshot from my GitHub account from today.

String interpolation in Ruby

Today I have struggled with one exercise from exercism.io. In the first look exercise was very simple: ‘Write a function that greets the user by name, or by saying “Hello, World!” if no name is given. For an input of “Alice”, the response should be “Hello, Alice!”. If a name is not given, the response should be “Hello, World!”‘.
On the first look, this task was very simple. To create some function that takes some argument instance variable. Below I passed the first resolution:

class HelloWorld
  def self.hello(name = "World")
    @name = name
    "Hello, #{@name}!"
  end
end

This solution is ok, but this is one little thing that can be changed to a proper more elegant solution. But first let thing what for is this line:

@name = name

This line is instance variable and becomes class variable. Is this particular line is needed? I was thinking that yes, this line is needed, for me, this notation was more readable. But I was in mistake. This piece of code is useless. I can remove this line and execution this simple program will not change. Why?
Variable:

name

that is in:

""Hello, #{name}!""

is interpolated inside the string, to get their value and not just referenced by their name to print on the screen. To wrap variable we can use:

#{name}

So there is no need to create additional value and the final program code looks as follows:

class HelloWorld
  def self.hello(name = "World")
    "Hello, #{name}!"
  end
end

Above code looks nicer that before. But why as a developer I should use string interpolation and what for? This code is very simple and short and probably someone can say why to use this type of construction? Let’s imagine some longer string that contains more than 5 or 6, maybe 122, or more variables. What then? Probably is more convenient to use this kind of string structure to make life easier. And the second thing: for me, the syntax is more readable and of a first look, it’s easier to figure out what’s going on in the code.


Reference:

Continuous integration services – review

For few day I was looking for some continuous integration services that will allow me to build and deploy my open source projects now and near feature. I spend several hours searching, reading, trying to use and build some code. Some CI services are for free and works very good with for example GitHub. It’s a big plus, especially when you trying to run open source.

Below I add a small table that contains some essential information for devs that are interested in that kind of services.

NameDescriptionFeaturesSupported repositoriesDocumentationPrice
AppveyorAppVeyor automates building, testing and deployment of .NET applications.• GitHub
• BitBucket
documentationFree with limitations
AssertibleAutomated post-deployment testing and web service monitoring• GitHubdocumentationFree with limitations
BitriseiOS Continuous Integration and Delivery.• GitHub
• BitBucket
• Custom
documentationFree
BuildkiteA build automation platform which gives you complete control, without the pain of running your own CI system.Languages: Ruby, Python, Node.js, JavaScript, PHP, Go, Rust, Erlang, Elixir, Java, Clojure, Scala, C/C++, Objective-C, Swift, .NET/C#
Source code is available: Buildkite Agent
• GitHub
• BitBucket
• Custom
documentation• 14-day Trial
• Free for Education
• Open Source
Circle CIContinuous Integration and Deployment• GitHubdocumentationPricing
CodeshipOne more cloud based CI service: running tests and deployment.• GitHub
• BitBucket
documentationFree for opensource projects or 100 builds per month
Code ClimateHosted platform to continuously measure and monitor code quality Languages: Ruby, Javascript, PHP• GitHub
• Custom
documentation14-day Trial
Coveralls Coveralls works with your continuous integration server to give you test coverage history and statistics.Languages: Ruby, Javascript, Python, PHP, C, Objective-C, Scala, GO• GitHub
• BitBucket
documentationFree for opensource projects
CoverityCode analysis, test analysisLanguages: C/C++, Java, C#noneFree for opensource projects
CoviolationsTool for collecting and visualisation code violations works with Travis-CI, drone.io and JenkinsSource code is available: Web application, Applicationdocumentation
DroneContinuous Integration serviceSource code is available.• GitHub
• BitBucket
• Google Code
• Custom
documentationPublic projects for free
FactorService to automate developer workflows by defining them programmatically using the Factor.io syntax and running them using the Factor.io Server.documentation
GitLab CI• GitLabdocumentationPricing
GitHost• GitLabdocumentationPricing
Hound CIReview your JavaScript, CoffeeScript, and Ruby code for style guide violations with a trusty hound.• GitLabnonePublic repositories for free
Magnum CIHosted Continuous Integration and Delivery Platform• GitHub
• BitBucket
• GitLab
• Custom
documentationFree beta
PHP CIFree and open source continuous integration tool specifically designed for PHPLanguage: PHP, Source code is available• BitBucket
• GitLab
• Custom
nonePricing
SaucelabsAutomated testing in the cloud for CIdocumentation14-day Trial
ScrutinizerBuild quality software, betterSources are available• GitHub
• BitBucket
documentation14-day Trial
SemaphoreHosted continuous integration and delivery solution for open source and private projects.Ruby, Node.js, JavaScript, Go, Clojure, Elixir, Erlang, Java, PHP, Scala, C/C++• GitHub
• BitBucket
documentationFree for Open Source, 100 free builds for private projects
ShippableContinuous DeliveryLanguages: Ruby, Python, Java, Node.js, Scala, PHP, Go; Databases: MongoDB, MySQL, Redis, Postgres, CouchDB, RethinkDB, Neo4j, and SQLite• GitHub
• BitBucket
• GitLab
documentationFree with limitations
Snap• GitHubdocumentationFree
Solano CIHosted service that runs your test suite on a distributed infrastructure - fast• GitHub
• BitBucket
• GitLab
• Custom
documentation14-day Trial
StyleCIThe PHP Coding Style Service, used by Cachet.• GitHubdocumentationFree for opensource projects
TestlingHosted service that runs your test suite in many different browsers every time you push to GitHub. It can run any test suite so long as it writes TAP to the browser console.documentationFree for opensource projects and 3 min sessions
Travis CIHosted continuous integration service for open source and private projects.Languages: C, C++, Clojure, Erlang, Go, Groovy, Haskell, Java, Javascript (with Node.js), Objective-C, Perl, PHP, Python, Ruby, Rust, Scala. Source code is available.• GitHubdocumentationFree for opensource projects and 3 min sessions
Visual Studio Online Cloud-based collaboration services for version control, agile planning, continuous delivery, and analytics application for Visual Studio, Eclipse, Xcode.• Visual Studio
• Team Services
• GitHub
• Custom
documentationFree
WerkerContinuous delivery platform• Docker Hubdocumentation

Reading logs with ADB: the most useful commands

Reading logs during testing Android applications often force developer or tester to use appropriate tools. One of them is: Android Device Bridge. ADB comes as a part of the standard Android SDK, it provides a terminal-based interface for interacting with your devices with Android file system. Below I added some useful commands that every tester, programmer use during deal with applications every day.

 

Useful commands:

adb locat

– access to Android device logs, direct output to the console

adb logcat -d > [filename]

– this command allows to save logs in a file name you have specified, for example: abd logcat -d Users/user/storage

adb logcat -c - all

– logs on devices are erased, after that you are able to grab logs without unnecessary data

adb logcat -v time

– display logs with specified time

adb reboot

– reboot device

adb start-server

– ensure that there is a server running

adb kill-server

– kill the server if it is running

adb push app /system/sd/app

– push apps from comupter onto device

adb get-state

– prints: offline | bootloader | device

adb get-serialno

– prints: serial-number

adb status-window

– continuously print device status for a specified device

adb remount

– remounts the /system partition on the device read-write

adb reboot [bootloader|recovery]

– reboots the device, optionally into the bootloader or recovery program

adb tcpip

– restarts the adbd daemon listening on TCP on the specified port

adb jdwp

– list PIDs of processes hosting a JDWP transport

adb ppp  [parameters]

– Run PPP over USB.
Note: you should not automatically start a PPP connection. refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1 [parameters] – Eg. defaultroute debug dump local notty usepeerdns

adb -s [yourdeviceserialnumberhere] shell

– above command will start an interactive shell from your machine, but running on your device

adb shell rm -r /system/sd/app
adb shell rm -r /system/sd/app-private

– deleting existing apps on SD

adb bugreport

– return all information from the device that should be included in a bug report

fastboot oem unlock

– unlock bootloader, making root access possible

fastboot flash recovery

– flash a custom recovery image to your phone

am start -n com.package.name/com.package.name.ActivityName

or:

adb shell am start -n com.package.name/.ActivityName

– starting application using adb tools


Reference:



100 Days of Code – challenge

About 100 days of code first time I read on this blog. Then I start to read more, and I find John Rasing blog and Richard Littauer post on Medium. I think it’s a great idea. Basically, I need some challenge, because I a lite bit lazy in recent times and my learning and coding progress is a bit pure.

I put below screen picture from my current GitHub account:

Zrzut ekranu 2016-04-10 o 23.36.36

As you can see, there is no great progress for a few days. Longest streak took 7 days, contributions in total : 99 repos.

Rules for 100 days of code are simple:

  1. writing  code every single day
  2. all code must be written before midnight
  3. code must be up on GitHub
  4. written code must be useful (comments, reformatting, refactoring does not count)
  5. written code can’t be related to work, must be created in spare time, after hours (probably during nights, a day has only 24 hours)

Personally, I think that with coding every day is like a writing every day for the professional writer, it’s a big part of his life. The same like for example skilled craftsman who sculpts something in wood, inch by inch,  minute by minute, day by day …

I know that will not be easy to find a balance between work/life and side projects. Probably I will find some tools/apps to better manage my time and be more productive.

Something that I afraid is to stick with some problem to solve for a long of time and don’t have an idea to write a solution.

What I hope to achieve ?  Programming becomes a daily habit and hopes to continue it as long as I can.

I start from today 😉



Starting a Feedbacker project in Android Studio

Starting a new project in Android Studio is a very simple task if we have an idea of course what we want to do. In this post, I will show step by step how to create a simple project using blank activity with fragment.

First, we should run AndroidStudio and then select from the main window: Start a new Android Studio project. After that, we will see a: Configure your new project window:

1

This window allows naming your project, select location of workspace and also set your company domain, for me company domain is: andrzejdubaj.com.

Next screen allows selecting form factors on which app will be running.

2

I select: Phone and Tablets, also: Minimum SDK – API 21: Android 5.0(Lollipop). Why has Android 5.0 Lollipop ? Because I have a smartphone on which I can test my app – physical device, not an emulator and second: I want to build from source Android 5.0 and run in on raspberry pi 2 or 3 version. We will see in the future.

7

On: Add an activity to Mobile allows selecting one from several activities with automatically add necessary file to project, for example, *.xml files. I select a blank activity. If I decided to create some localization app I will choose google maps application.

3

Next step takes us to: Customize the Activity. Way, I choose fragments ? Because fragments allow building an application with behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle. You can read more here.

4
 After pressing on: Finish button we will get build the layout of an application. Basic project structure with catalogs and base classes.
6
 
On this point,  we can start developing the application. Writing code and add necessary files.

Most useful Raspberry Pi shell commands

Raspberry pi offers to install many Linux distributions. On Linux you can use commands to save your time and become more powerful in you work environment. Below I put some useful command:

  • apt-get update: update raspberry pi system version
  • apt-get upgrade: upgrade all packages installed on raspberry pi
  • clear: clear all logs in console
  • startx: command allows to start graphics user interface
  • reboot: allows to reboot system immediately
  • shutdown -h now: shutdown immediately
  • power off: allows to shutdown machine
  • data: prints current data
  • shutdown -h 03:33 : shutdown at 3:33
  • apt-get install nano: install nano editor – nano online documentation

Network commands:

  • ifconfig: allows you to check: IP address, wireless connection
  • iwconfig:
  • nmap: software that allows to scan:
    • network and list connected devices
    • port number
    • protocol
    • state: open or closed operating system
    • MAC address
  • ping: allows to send ICMP echo request packet to network host
  • wget: allows to download file from Web and saves to current directory

System information commands:

  • df: displays statistics about the amount of the free space on the specified filesystem
  • free: display how much free memory is available
  • hostname: display name of the current host

Search commands:

  • grep: allows to search inside files certain search patterns. Support regular expressions which allows special letter combinations to be included in the search
  • awk: programming language useful for search and manipulating text files
  • find:  allows to search a directory and subdirectory for file matching certain patterns
  • whereis: allows for location or a command
  • history: allows to display list of commands typed in console

Feedbacker – list of learning resources for app development, IoT, testing …

I always have a feeling to put down my own list of learning resources for development/ IoT / testing. It not easy 😉 But for now I publish first version of list and I will expanded this list as more interesting materials.

ALC:

Android:

TDD / Unit Testing :

Development resources:

Development Tools:

Testing Tools:

Performance:

Security:

Internet Of Things:

Recommended talks:

aapt on OS X

During launching my tests written in JUnit I notice problem with performing one of them. I received:

java.io.IOException: Cannot run program "aapt": error=20, Not a directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

In Stack Overflow I found a lot of solutions but non of them didn’t solve my problem. There’s a bug in IntelliJ IDE that points to platform-tools for executable that are in build-tools. I found my own solutions of this problem:

ln -s 23.0.2 build-tools/current
ln -s ../build-tools/current/aapt platform-tools/aapt
ln -s ../build-tools/current/lib platform-tools/lib

This solution works for me. Similar problem appears in Windows and Linux.

Pet project for: “Daj się poznać” second edition.

Potted Plant-50During a past few days I wondered over my pet project to: Daj się poznać competition. It was a very hard period of time because of number ideas coming into my mind. Some might ask why it was so hard    with choose appropriate idea. The answer is simple, everything is connected with time I have and I can devote to self-development.

I figured that I create simple applications on android that allows user to control device in the form of a small greenhouse for plants. Getting data from the box of the container itself. Irrigation control and opening the upper flaps. This small greenhouse is available in many shops networks for allotment, only part with glass and frames. I can easily buy online. If I can’t buy one,  which is highly unlikely, especially since it is getting closer to spring, it will build one myself. Definitely it will require few modifications, but this is to be done.

List of things to do:

  • rework / construction of mini greenhouses
  • adding sensors with microcontroller
  • design of irrigation systems
  • write applications for android
  • writing service for monitoring data online
  • invent an elegant solution to the communication of a whole greenhouse
  • write code which works
  • perform tests
  • a little penetration testing and evil hacks – this can be fun 🙂

For sure the first part will not be made quickly, because of a several issues about whom I will try to write later, more technically.

Idea for this project it’s really related t IoT – Internet of things. I will use agile methodology to describe all steps, or steps that will appear during develop my idea project.

Link to my project on GitHub.

What I would like to achieve ? – And this is very good question 😉 First of all I want to learn new technology:

  • android
  • WebServices
  • IoT
  • communication protocol
  • test frameworks that allows to perform automation in IoT field
  • some basic stuff about security – it’s more then fun
  • do something useful

Secondly:

  • document my progress
  • use git
  • have more fun