Join Codeheat Coding Contest 2017

Codeheat is a coding contest for developers interested in contributing to Open Source software and hardware projects at FOSSASIA.  Join development of real world software applications, build up your developer profile, learn new new coding skills, collaborate with the community and make new friends from around the world! Sign up for #CodeHeat here now and follow Codeheat on Twitter.

The contest runs until 1st February 2018. All FOSSASIA projects take part in Codeheat including:

Grand prize winners will be invited to present their work at the FOSSASIA OpenTechSummit in Singapore from March 23rd -25th 2018 and will get 600 SGD in travel funding to attend, plus a free speaker ticket and beautiful Swag.

Our jury will choose three winners from the top 10 contributors according to code quality and relevance of commits for the project. The jury also takes other contributions like submitted weekly scrum reports and monthly technical blog posts into account, but of course awesome code is the most important item on the list.

Other participants will have the chance to win Tshirts, Swag and vouchers to attend Open Tech events in the region and will get certificates of participation.

codeheat-logo

Team mentors and jury members from 10 different countries support participants of the contest.

Participants should take the time to read through the contest FAQ and familiarize themselves with the introductory information and Readme.md of each project before starting to work on an issue.

Developers interested in the contest can also contact mentors through project channels on the FOSSASIA gitter.

Additional Links

Website: codeheat.org

Codeheat Twitter: twitter.com/codeheat_

Codeheat Facebook: facebook.com/codeheat.org

Participating Projects: All FOSSASIA Repositories on GitHub at github.com/fossasia

Adding Static Code Analyzers in Open Event Orga Android App

This week, in Open Event Orga App project (Github Repo), we wanted to add some static code analysers that run on each build to ensure that the app code is free of potential bugs and follows a certain style. Codacy handles a few of these things, but it is quirky and sometimes produces false positives. Furthermore, it is not a required check for builds so errors can creep in gradually. We chose checkstyle, PMD and Findbugs for static analysis as they are most popular for Java. The area they work on kind of overlaps but gives security regarding code quality. Findbugs actually analyses the bytecode instead of source code to find possible JVM bugs.

Adding dependencies

The first step was to add the required dependencies. We chose the library android-check as it contained all 3 libraries and was focused on Android and easily configurable. First, we add classpath in project level build.gradle

dependencies {
   classpath 'com.noveogroup.android:check:1.2.4'
}

 

Then, we apply the plugin in app level build.gradle

apply plugin: 'com.noveogroup.android.check'

 

This much is enough to get you started, but by default, the build will not fail if any violations are found. To change this behaviour, we add this block in app level build.gradle

check {
   abortOnError true
}

 

There are many configuration options available for the library. Do check out the project github repo using the link provided above

Configuration

The default configuration is of easy level, and will be enough for most projects, but it is of course configurable. So we took the default hard configs for 3 analysers and disabled properties which we did not need. The place you need to store the config files is the config folder in either root project directory or the app directory. The name of the config file should be checkstyle.xml, pmd.xml and findbugs.xml

These are the default settings and you can obviously configure them by following the instructions on the project repo

Checkstyle

For checkstyle, you can find the easy and hard configuration here

The basic principle is that if you need to add a check, you include a module like this:

<module name="NewlineAtEndOfFile" />

 

If you want to modify the default value of some property, you do it like this:

<module name="RegexpSingleline">
   <property name="format" value="\s+$" />
   <property name="minimum" value="0" />
   <property name="maximum" value="0" />
   <property name="message" value="Line has trailing spaces." />
   <property name="severity" value="info" />
</module>

 

And if you want to remove a check, you can ignore it like this:

<module name="EqualsHashCode">
   <property name="severity" value="ignore" />
</module>

 

It’s pretty straightforward and easy to configure.

Findbugs

For findbugs, you can find the easy and hard configuration here

Findbugs configuration exists in the form of filters where we list resources it should skip analyzing, like:

<Match>
   <Class name="~.*\.BuildConfig" />
</Match>

 

If we want to ignore a particular pattern, we can do so like this:

<!-- No need to force hashCode for simple models -->
<Match>
   <Bug pattern="HE_EQUALS_USE_HASHCODE " />
</Match>

 

Sometimes, you’d want to only ignore a pattern only for certain files or fields. Findbugs supports regex to match such items:

<!-- Don't complain about rules in tests. -->
<Match>
   <Field name="~.*mockitoRule"/>
   <Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>

 

You can also annotate your code to suppress warning in the particular class, mehod or field rather than disabling it for the whole project. For that, you need to add findbugs annotations dependency in the project

compile 'com.google.code.findbugs:findbugs-annotations:3.0.1'

 

And then use it like this:

@SuppressFBWarnings(
   value = "ICAST_IDIV_CAST_TO_DOUBLE",
   justification = "We want granularity to be integer")
public void showChart(LineChart lineChart) {
   ...
}

 

It also allows setting the justification of suppressing the rule for clarity

PMD

For findbugs, you can find the easy and hard configuration here

Like checkstyle, you have to first add a rule set to tell PMD which checks to perform:

<rule ref="rulesets/java/android.xml" />

 

If you want to modify the default value of the rule, you can do it like this:

<rule ref="rulesets/java/codesize.xml/TooManyMethods">
   <properties>
       <property name="maxmethods" value="15" />
   </properties>
</rule>

 

Or if you want to entirely exclude a rule, you can do it like this:

<rule ref="rulesets/java/basic.xml">
   <exclude name="OverrideBothEqualsAndHashcode" />
</rule>

 

PMD also supports suppressing warnings in the code itself using annotations. You don’t require any external libraries for it as it supports the in built java.lang.SuppessWarnings annotations. You can use it like this:

@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") // Entries cannot be created outside loop
private LineDataSet setData(Map<String, Long> map, String label) throws ParseException {
   ...
}

 

As you can see, we need to prepend “PMD.” to the rule name so that there are no clashes while annotation processing. Remember to comment the reason for suppressing the warning so that your co-developers know and can remove it in future if criteria does not meet anymore.

There is a lot more to learn about these static analyzers, which you can read upon in their official documentation:

Announcing the FOSSASIA 2017 #CodeHeat Winners

Drum roll please! We are very proud to announce the 2017 FOSSASIA #CodeHeat Grand Prize Winners and Finalists. 442 participants from 13 countries and 5 continents committed over 1000 pull requests to our repositories over the course of the contest. Congratulations to everyone to this fantastic achievement! The winners were now chosen by our jury. Thank you for reviewing the contributions.

Our three Grand Prize winners will travel to the FOSSASIA Summit in Singapore from March 17-19 and present their work to developers from around the world. The winners are (in alphabetical order):

Mayank Tripathi (mayank408)

Medozonuo Suohu (magdalenesuo)

Shubham Padia (shubham-padia)

Our other finalists will receive a voucher to support trips to Open Tech conferences in the region to connect with developers and the community.

Achint Sharma (Achint08)

Deepjyoti Mondal (djmgit)

Hemant Jadon (hemantjadon)

Pranjal Paliwal (betterclever)

Rishi Raj (rishiraj824)

Saurabh (gogeta95)

Utkarsh Gupta (uttu357)

 

Certificate of Participation

Many developers made outstanding contributions in the last months and we all learned a lot during the contest. Thank you so much! We hope you stay on board and continue to participate in the community to develop Open Tech that improves peoples lives and to seize the opportunity to develop your code profile with FOSSASIA. To receive your certificate of participation now, please claim it here.

Supporting Partners

We would also like to extend a special Thank you to our jury and to our supporting partners at the UNESCO and the Open Tech Society.

Thanks FOSSASIA mentors!

And we really love the work of our mentors! Thanks for your patient guidance, helping everyone with learning about best practices, reviewing the huge number of pull requests and discussing questions on the chat channels. Many of our mentors have been students in coding programs before and we are very very proud to see how you help newcomers to join. Keep up the fantastic work!

Python code examples

I’ve met many weird examples of  behaviour in python language while working on Open Event project. Today I’d like to share some examples with you. I think this knowledge is necessary, if you’d like to increase a  bit your knowledge in python area.

Simple adding one element to python list:

def foo(value, x=[]):
  x.append(value)
  return x

>>> print(foo(1))
>>> print(foo(2))
>>> print(foo(3, []))
>>> print(foo(4))

OUTPUT

[1] 
[1, 2] 
[3]
[1, 2, 4]

First output is obvious, but second not exactly. Let me explain it, It happens because x(empty list) argument is only evaluated once, So on every call foo(), we modify that list, appending a value to it. Finally we have [1,2, 4] output. I recommend to avoid mutable params as default.

Another example:

Do you know which type it is?

>>> print(type([ el for el in range(10)]))
>>> print(type({ el for el in range(10)}))
>>> print(type(( el for el in range(10))))

Again first and second type are obvious <class ‘list’>, <class ‘set’>. You may  think that last one should return type tuple but it returns a generator <class ‘generator’>.

Example:

Do you think that below code returns an exception?

list= [1,2,3,4,5]
>>> print(list [8:])

If you think that above expression returns index error you’re wrong. It returns empty list [].

Example funny boolean operators

>>> 'c' == ('c' or 'b')
True
>>> 'd' == ('a' or 'd')
False
>>> 'c' == ('c' and 'b')
False 
>>> 'd' == ('a' and 'd')
True

You can think that that OR and AND operators are broken.

You have to know how python interpreter behaves while looking for OR and AND operators.

So OR Expression takes the first statement and checks if it is true. If the first statement is true, then Python returns object’s value without checking second value. If first statement is false interpreter checks second value and returns that value.

AND operator checks if first statement is false, the whole statement has to be false. So it returns first value, but if first statement is true it checks second statement and returns second value.

Below i will show you how it works

>>> 'c' == ('c' or 'b')
>>> 'c' == 'c'
True
>>> 'd' == ('a' or 'd')
>>> 'd' == 'a'
False
>>> 'c' == ('c' and 'b')
>>> 'c' == 'b'
False 
>>> 'd' == ('a' and 'd')
>>> 'd' == 'd'
True

I hope that i have explained you how the python interpreter checks OR and AND operators. So know above examples should be more understandable.

Google Code-In Success: FOSSASIA Top-Ranked Organization

FOSSASIA‘s first participation of Google Code-in contest as a mentoring organizations was a great success with 587 tasks completed, most by any organization this year, out of a total of 725 published tasks. The twelve participating organizations included projects like Wikimedia, Sugarlabs, Sahana, Drupal, KDE and OpenMRS.

Students from all around the world aged 13-17 years old worked with mentors of FOSSASIA on improving open source software during the 7 weeks the contest is run. They coded programs, designed artworks, tested software and more than anything else had fun.

174 students managed to complete at least one task with FOSSASIA and 43 out of them claimed a cool t-shirt from Google by completing 3 or more tasks.

Out of the 10 students who completed most number of tasks finalists and grand prize winners were picked collectively by FOSSASIA’s 24 mentors. Namanyay Goel and Samarjeet Singh won the grand prize, which is an all expense paid trip to Google HQ in Mountain View, California. Alvis Wong, Amr Ramadan and Tymon Radzik emerged as finalists. Congratulations finalists! Safe travels grand prize winners! We are thankful for your precious contributions and will be delighted see you continue to contribute even after the program.

Open source projects ExpEYES, sup, TiddlySpace, p5.js among few others, benefitted from FOSSASIA students’ work. More than 150 open source/ open tech projects and communities around asia were connected to FOSSASIA with the help of students. Students also worked together to build a nice website portraying students and mentors.

We would like to thank all participated students for the amazing interest they showed in our tasks. Its great to see some of them still hang around to help us. 24 mentors of FOSSASIA worked hard and stood up to the challenge of finding time to work with and help out students while having other obligations. Thank you mentors! Lastly we are grateful to Stephanie Taylor and Co. at the Google OSPO, for organizing the wonderful contest.

Google Code-In FOSSASIA Mentor Package Wonderful Surprise: Mentors received a Thank You Package from Google

Sleeping peacefully - Nephew of Michael Cheng: Mentor's Family Enjoying "Open Source" Thank you package Sleeping peacefully – Nephew of Michael Cheng: Mentor’s Family Enjoying “Open Source” Thank you package

Links

FOSSASIA GCI: http://www.google-melange.com/gci/org/google/gci2014/fossasia

Google Blog about GCI: http://google-opensource.blogspot.de/2015/02/google-code-in-2014-magic-in-numbers.html