Involving to the end-user

The Knit Editor software aims to be installable and usable by end-users. In the whole summer of code, we focused on development and code documentation from the perspective of a developer. In this blog post we will discuss how the Knit Editor is presented to the end user. So, you reading this blog: Please comment with your thoughts on the sketches.

Currently, a site is in the making that shall present the Knit Editor software as is state of the art. The inspiration came from the talk by Tracy Osborn at PyCon 2016: “Web Design for Non Designers”. The site is currently in the making at fossasia.github.io/kniteditor. If you click on the following images, you get redirected to the implementation of the concept.

The Main Page

First thing that comes into view is the download button. This leads to the download site. Then, wen can see three popular use-cases of the knit editor. At the bottom, new developers can see that they can contribute.

End users are knitters of all ages. As tested with my mom, they expect the language to be at the top-right of the page.Main Page

Both, the download and the start developing button are highlighted in a different color to make certain that they are an action the user is expected to perform.

When you access the site you get automatically redirected to your browsers configured language.

The Download Site

When you click the download button on the main page, you reach the download site. Depending on the operating system information the browser sends, your download starts automatically, below, this is  sketched for Windows.

P1040129

Next to the download page, you may want to find other versions of the software or not. This is to be evaluated. Maybe a slightly less visible button is right for that or it can be left out. Usually, no-one uses the old software.

At the bottom, you can see that there is a predecessor of the software which is called “AYAB-Apparat”. Some people may expect to find this software, too.

The Developer Site

If you clicked “Start Developing” on the main page, you will be confronted with the site for development.

There are two ways main flavors of contributing. Either you translate or you write program code. Therefore, we have two buttons that skip to the corresponding sections.

P1040130

At the bottom, you can see that there are tutorials on how to set up the environment for development. Videos for this can be found under this Youtube playlist.

Summary

At the end of GSoC we should document the code. Since we did documentation-driven development, there was already a focus on the developers from the start. End-user involvement fell short during the development phase. “Documentation is the way of informing people.” – this is something I learned from a talk. Thus, I create the new site for the knit editor as a documentation about the project fit for non-developers.

Continue ReadingInvolving to the end-user

Flavors in Gradle

Ever wondered how do people maintain different versions of the same app on play store with some customisations in each version. For example, Lite version and a pro version which signify free and paid versions with extra features in paid one.

With the arrival of gradle as a build tool, we got gradle flavors which is an excellent way to have some variations in your app versions.

It can also be leveraged to do hermetic testing with prod/mock flavors. Some other examples could be free/paid flavors and stable/experimental flavors etc.

Now let’s talk about on how to proceed :

The process is very simple

  1. Create the flavors in you build.gradle file
android {  
      productFlavors {  
           mock {   
                applicationIdSuffix = ".mock"  
           }  
           prod  
      }  
 }

Here prod and mock are two flavors and the customisations we add are that mock has a applicationIdSuffix. We can also add altogether different applicationIds as well as define a different version for different flavors and a lot of other different things

2. Now we sync the project

If you now open Build Variants tool window either using the quick access menu located in the status bar in the bottom left hand corner of the Android Studio main window or using the Build Variant tool window bar. Once loaded, clicking in the Build Variant cell for the app module should now list the four build variants: mockDebug, mockRelease and prodDebug, prodRelease

After this we get different folders corresponding to the different flavors. We go ahead and add the different folders where we want the changes to occur. For example if I want to show two different maps for two different versions, where one version is for fdroid and another one is for googleplay and hence we replace google maps with OpenStreet Maps in the fdroid version. Hence, We add res/values and res/layout folders for different resources and we also add different java folders and add the classes that would be different for both the flavors. Since both of these will require different set of permissions we can also add AndroidManifest.xml for these were we define the permissions etc. we want.

Not that we only add the changes for each file. All the other essential things can be added from the Main flavor of the android project.

Any variable available through your code

Another thing to know is that the you can have add variables like this so that you can use different variables for different flavors. For examle if you have different api’s and different options for each flavor like if you want to report crashes in one of the flavors and not in other. Here HOST variable is not the only one you can expose in your code. You can do it with whatever you want:

prod {  
    applicationId "zuul.com.android"
    buildConfigField 'String', 'HOST', '"http://api.zuul.com"'
    buildConfigField 'String', 'FLAVOR', '"prod"'
    buildConfigField "boolean", "REPORT_CRASHES", "true"
}

You can access them as follows:

BuildConfig.HOST  
BuildConfig.FLAVOR  
BuildConfig.REPORT_CRASHES

So I think this is a really useful thing to know and is used in almost every app. We all need some configuration differences in our apps and gradle flavors is the best way to go about it. Go nuts with your imagination on the usage of flavors 😛

Adios!

Continue ReadingFlavors in Gradle

Final submission post: Engelsystem

This summer has been really amazing, I learnt a lot and worked crazy hours it has been a crazy yet amazing ride. I am not going to stop working on open source projects and posting the blog post.

In this post, I would like to summarize all the work that I did during this summer. Working with FOSSASIA was an amazing experience for me. I got to learn a lot during this summer. Thanks to such amazing mentors.

My project Engelsystem is an online tool for helper and shift planning on major events. It lets the user organize their helper in teams, they share in layers or let them decide when and where they want to help themselves.

GithHub Commits
GithHub Commits

 

Codacy certifications

The Project was provided an A-Grade certificate from CODACY.

Here the link to view all my GitHub contributions to the project during this summer,
https://github.com/fossasia/engelsystem/commits/master?author=dishantk1807

commits new 2
My GitHub Contributions (DishantK1807)

The list of issues solved and features implemented by me is provided below.

  1.    Themes

Issue: https://github.com/fossasia/engelsystem/issues/4

Creating new themes for Engelsystem. Two themes have been added to the system, Engelsystem color scheme-1 and Engelsystem color scheme-2.

 

  1.    Languages for Localisation

Issue: https://github.com/fossasia/engelsystem/issues/5

Sub-issue:

  1.   https://github.com/fossasia/engelsystem/issues/52 [Language support-I]

Implement localization in different languages as it will make this system reach many people across the world. There 10+ International languages added to the system. The list of languages can be checked in the issue tracker

 

  1.    Added Travis-CI

Issue: https://github.com/fossasia/engelsystem/issues/31

Setup the Travis-CI for Engelsystem. Added a stable .travis.yml file to the system

 

  1.    Feature Request: User: Registration form

Issue: https://github.com/fossasia/engelsystem/issues/10

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/33 [Marking First Name and Last Name as required]
  2.   https://github.com/fossasia/engelsystem/issues/35 [Adding more item to the Registration form]

Adding more fields to the registration form(First name, Last Name, GitHub, Facbook, Twitter, Organization)

 

  1.    Feature Request: Admin: Export database of all Angels

Issue: https://github.com/fossasia/engelsystem/issues/12

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/114 [Use temporary files for exporting the database]
  2.   https://github.com/fossasia/engelsystem/issues/144 [Improve User export]
  3.   https://github.com/fossasia/engelsystem/issues/155 [remove password hashes from the export]
  4.   https://github.com/fossasia/engelsystem/issues/154 [Restore Frab import]

Exporting the database of the angels in the .csv format.

 

  1.    Feature Request: Admin: Shifts: Batch Deleting of Shifts

Issue: https://github.com/fossasia/engelsystem/issues/14

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/113 [Adding checkboxes and delete button]

Implementing batch deleting of Shifts in the shifts page allowing the admin to delete multiple shifts at once. Created checkbox for selecting the shifts to be deleted and a delete button in the Shifts page to delete the selected shifts.

 

  1.    Feature Request: User: Registration Form and Shifts [Captcha]

Issue: https://github.com/fossasia/engelsystem/issues/18

Sub-issues:

  1.    https://github.com/fossasia/engelsystem/issues/124 [Captcha in the Registration form]
  2.   https://github.com/fossasia/engelsystem/issues/128 [Captcha in Shifts       page]
  3.    https://github.com/fossasia/engelsystem/issues/132 [Documentation for captcha]
  4.   https://github.com/fossasia/engelsystem/issues/142 [Refining captcha code]
  5.   https://github.com/fossasia/engelsystem/issues/148 [Removing keys and added it via config.php]
  6.   https://github.com/fossasia/engelsystem/issues/148 [enable and disable re-Captcha]

Implementing Google re-Captcha in the Registration form and Shifts pages for enhancing the security

  1.    DB: Convert char(1) to Booleans

Issue: https://github.com/fossasia/engelsystem/issues/21

This issue was listed in the engelsystem/engelsystem issue tracker.

 

  1.    Bug: Disallow self-signup of shifts

Issue: https://github.com/fossasia/engelsystem/issues/22

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/199 [Create new Groups Page]
  2.   https://github.com/fossasia/engelsystem/issues/201 [Providing Privileges to the new Groups Created]

Disallowing self-signup of restricted shifts when an Engel is approved for certain groups. Created a page to create new groups and provide specific privileges to them so that they won’t get Admin privileges to automatically signup for the Shifts

  1.  Feature: User: Date/time picker for Shifts

Issue: https://github.com/fossasia/engelsystem/issues/23

Implementing a date/time picker in the Shifts view for selecting the shifts.

  1.  Documentation: Setting up the system

Issue: https://github.com/fossasia/engelsystem/issues/27

Added documentation for setting up the system on the local as well as online server.

 

  1.  Feature: User : Registration Form: Check if E-mail already exist

Issue: https://github.com/fossasia/engelsystem/issues/39

Implement a check in the registration form to check if an Email already exists in the system.

  1.  User : Registration Form : Update database for setting email as unique

Issue: https://github.com/fossasia/engelsystem/issues/46

Set constraint in the registration from to set email as unique.

  1.  Solving bug

Issue: https://github.com/fossasia/engelsystem/issues/49

  1.  Implement database migrations

Issue: https://github.com/fossasia/engelsystem/issues/137

Worked in implementing database migrations for the system.

  1.  Improving code quality and documentation.

Issue: https://github.com/fossasia/engelsystem/issues/56

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/57 [Code and branch cleanup]
  2.   https://github.com/fossasia/engelsystem/issues/59 [Updating documentation]
  3.   https://github.com/fossasia/engelsystem/issues/100 [Translate comments in install.sql]
  4.   https://github.com/fossasia/engelsystem/issues/118 [Translating comments of user_shift.php and sys_template.php]
  5.   https://github.com/fossasia/engelsystem/issues/135 [Cleanup Project: Delete Branches, set up development branch, deploy dev branch to heroku]
  6.   https://github.com/fossasia/engelsystem/issues/156 [Improving documentation]

 

  1.  Feature Request: Creating new Settings page for Admin

Issue: https://github.com/fossasia/engelsystem/issues/67

Created a separate settings page for Admin, which allows admin to change specific Admin settings

  1.  Updating settings page for User

Issue: https://github.com/fossasia/engelsystem/issues/89

Updating the settings page for both Admin and User to change the new fields that were added to the registration form.

  1.  Updating users_view.php

Issue: https://github.com/fossasia/engelsystem/issues/90

Updating the users_view.php for the changes made in the Users table.

  1.  Update user_model.php

Issue: https://github.com/fossasia/engelsystem/issues/88

Updating the users_model.php for the changes made in the Users table.

  1.  Adding more search options in user_model

Issue: https://github.com/fossasia/engelsystem/issues/94

Implementing function for search by Facebook link, GitHub link, Twitter link, Organization name.

  1.  Feature Request: Languages as profile attributes

Issue: https://github.com/fossasia/engelsystem/issues/102

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/103 [Updating the DB for `Users` table]
  2.   https://github.com/fossasia/engelsystem/issues/104 [Updating the registration form]
  3.   https://github.com/fossasia/engelsystem/issues/105 [Displaying native and other languages in the users view]
  1.  Adding forgot password link in the registration form

Issue: https://github.com/fossasia/engelsystem/issues/127

Adding forgot password link in the error message of the registration form, when “Email already exist” error message is displayed.

  1.  Integrate more automated testings to the system

Issue: https://github.com/fossasia/engelsystem/issues/141

Integrated Travis-CI, Codacy, Code climate, Circle-CI, Gemnasium to the system

  1.  Fixing errors Codacy and Circle-CI issues

Issue: https://github.com/fossasia/engelsystem/issues/158

  1.  Improving Code quality: Removing whitespaces, translating comments and soving CI issues

Issue: https://github.com/fossasia/engelsystem/issues/159

  1.  Implementing MVC model for the system

Issue: https://github.com/fossasia/engelsystem/issues/163

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/169 [ Implement MVC for admin free, groups and import pages]
  2.   https://github.com/fossasia/engelsystem/issues/171 [Implement MVC for admin rooms, settings, shifts pages]
  3.   https://github.com/fossasia/engelsystem/issues/173 [Implement MVC for guest start, stats and user atom pages]
  4.   https://github.com/fossasia/engelsystem/issues/174 [Implement MVC for user ical, messages, myshifts pages]
  5.   https://github.com/fossasia/engelsystem/issues/175 [Implement MVC for user news, questions, settings and shifts pages]
  6.   https://github.com/fossasia/engelsystem/issues/186 [Implement MVC for user_shifts]
  7.   https://github.com/fossasia/engelsystem/issues/190 [Implementing MVC for the existing controller files]

There were 26 pages. Create controller files for all of them. For the pages which accesses the SQL queries, needed to be separated them into model files. There were only model files for a few pages.

  1.  Managing different events on the same system

Issue: https://github.com/fossasia/engelsystem/issues/80

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/82 [Creating new table ‘Events’]
  2.   https://github.com/fossasia/engelsystem/issues/81 [Create new Events page]
  1.  Implement an upgrade process for Engelsystem similar to WordPress

Issue: https://github.com/fossasia/engelsystem/issues/162

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/219 [Add enable/disable for Auto-upgrade]
  1.  Writing tests for Travis-CI

Issue: https://github.com/fossasia/engelsystem/issues/191

Sub-issues:

  1.   https://github.com/fossasia/engelsystem/issues/215 [update .travis.yml for setting up the database]

Setting up the database in travis. Updated .travis.yml for setting up the database for testing.

  1.  Writing test codes for all the model files

Issue: https://github.com/fossasia/engelsystem/issues/193

Sub-issue:

  1.   https://github.com/fossasia/engelsystem/issues/194 [Write test codes for ShiftType, Shift models]
  2.   https://github.com/fossasia/engelsystem/issues/195 [Test codes for NeededAngelType, Room, Angeltype Models]
  3.   https://github.com/fossasia/engelsystem/issues/207 [Unit Tests for Groups, GroupPrivileges, NewsComments, News, Privileges model files]
  4.   https://github.com/fossasia/engelsystem/issues/208 [Unit Tests for Questions, Settings, User AngelTypes, UserGroups, User, WelcomeMessage model files]
  1. Update Documentation
        Issue: https://github.com/fossasia/engelsystem/issues/227
        Updated the documentation for the code.

This kind of make me feel happy that I have around 230 commits on the master branch now and I believe that I will be working a lot more on EngelSystem to bring a lot of cool and useful feature to it. In case you have any suggestion feel free to file issues on EngelSystem Issues.

 

Continue ReadingFinal submission post: Engelsystem

Lambda expressions in Android

What are Lambda expressions

Lambda Expressions are one of the most important features added to Java 8. Prior to Lambda Expressions, implementing functional interfaces i.e interfaces with only one abstract method has been done using syntax that has a lot of boilerplate code in it.
In cases like this, what we are trying to do is pass a functionality as an argument to a method, such as what happens when a button is clicked.

Lambda expressions enables you to do just that, in a way that is much more compact and clear.

Syntax of Lambda Expressions

A lambda expression consist of the following:

  • A comma separated list of formal parameters enclosed in parentheses. The data types of the parameters in a lambda expression can be omitted. Also the parenthesis can be omitted if there is only one parameter. For example:
TextView tView = (TextView) findViewById(R.id.tView);
tView.setOnLongClickListener(v -> System.out.println("Testing Long Click"));
  • The arrow token ->
  • A body which contains a single expression or a statement block. If a single expression is specified, the java runtime evaluates the expression and then return its value. To specify a statement block, enclose statements in curly braces "{}"

Lambda Expressions in Android

To use Lambda Expressions and other Java 8 features in Android, you need to use the Jack tool-chain. Open your module level build.gradle file and add the following:

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Sync your build.gradle file and if you are having any issue with build tools, you may need to update buildToolsVersion in your build.gradle file to "24rc4" or just download the latest Android SDK Build-tools from the SDK Manager, under the Tools (Preview channel).

Example

Adding a click listener to a button

without lambda expression

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(this, "Button clicked", Toast.LENGTH_LONG).show();
    }
}););

with lambda expressions It is as simple as:

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(v -> Toast.makeText(this, "Button clicked", Toast.LENGTH_LONG).show(););

As we can see above, using lambda expressions makes implementing a functional interface clearer and compact. Standard functional interfaces can be found in the java.util.function package [included in Java 8]. These interfaces can be used as target types for lambda expressions and method references.

Credits : https://mayojava.github.io/android/java/using-java8-lambda-expressions-in-android/

Another way to have Java 8 features in your Android app is using the RetroLambda plugin.

Continue ReadingLambda expressions in Android

Software Testing

In this post I would like to explain what is software testing and different methods, levels of software testing.

What is software testing?

Software Testing is the process of evaluating a system or its components with the intent to find whether it satisfies the specified requirements or not.

Testing is executing a system in order to identify any gaps, errors, or missing requirements in contrary to the actual requirements.

What are the Levels of software testing?

Software products are tested at four levels:
  • Unit testing
  • Integration testing
  • System testing
  • Acceptance testing

Unit testing

  • During unit testing, modules are tested in isolation. If all modules were to be tested together, it may not be easy to determine which module has the error.
  • Unit testing reduces debugging effort several folds. Programmers carry out unit testing immediately after they complete the coding of a module.

Role of Unit Testing

  • Assure minimum quality of units before integration into system
  • Focus attention on relatively small units
  • Testing forces us to read our own code – spend more time reading than writing
  • Automated tests support maintainability and extendibility

Integration testing

After different modules of a system have been coded and unit tested:
  • modules are integrated in steps according to an integration plan
  • partially integrated system is tested at each integration step.

Role of Integration Testing

  • Gain confidence in the integrity of overall system design
  • Ensure proper interaction of components

Integration Testing Strategies

  • Big-bang
  • Top-down
  • Bottom-up
  • Critical-first
  • Function-at-a-time
  • As-delivered
  • Sandwich

System Testing

  • Gain confidence in the integrity of the system as a whole
  • Ensure compliance with functional requirements
  • Ensure compliance with performance requirements

Acceptance Testing

  • Testing performed by the customer or end-user himself
  • to determine whether the system should be accepted or reject

Testing is very important step of software development. We have used unit testing for our project Engelsystem. We are developing new features. Interested Developers can work with us.

Development: https://github.com/fossasia/engelsystem

Issues/Bugs:https://github.com/fossasia/engelsystem/issues

Continue ReadingSoftware Testing

AngularJS structure and directives

Today I am going to tell you how to build a well worked Angular JS structure, as well as to be able to maintain your app’s elements correctly. It’s a basic and most important thing to learn and remember before you start building your own website or app because in the early phases of a project the structure doesn’t matter too much, and many people tend to ignore it, but in the long term it will affect code maintainability. It also helps you to develop it quicker and solve bugs without any additional troubles.

I must admit that I was one of them who  had made this mistake and ignore AngularJS correct structure. The thing is that I had not known how to build Angular JS app correctly before I started coding CommonsNet, and I wanted to start and provide a real outcome as quickly as possible. But unfortunately my mistake has stoped me later. I have realised it this week while implementing a quite simple feature – adding HTML elements dynamically. It turned out that I had a trouble while adding them. I had’t known that it’s better not to manipulate DOM elements in Controllers, but instead do it in directives.

Let me to explain it step by step from lessons I’ve learned while refactoring CommonsNet code structure. Please note that I’m just sharing my experience in building rather a small project and I’m covering only a small part of that subject, so some of these tips may be first – useless if you want to build an extended one, and then – not enough if you want to learn more. I recommend you to find further resources.

AngularJS Structure

First of all please see at AngularJS structure provided below. It’s a very basic structure, but it’ is important to have in mind that you should follow that pattern while developing your own app. If you want to have an order in your files you should seperate them by directories and create different ones like: controllers, directives, services, js and views. This structure makes it very easy for the reader to visualize and conceptualize the concepts you are covering.

AngularJS structure.png

My CommonsNet structure differs a bit because I have one main js directory, and all subdirectories like directives, controllers and services  inside it. I think it’s also an acceptable solution. Imagine that I hadn’t had any directives or services directives’ files before last Wednesday…

Then,  it’s also recommended to put index.html at the root of front-end structure. The index.html file will primarily handle loading in all the libraries and Angular elements.

Next, controllers are main part of AngularJS apps. It always happens that developers when starting out tend to put too much logic in the controllers. It’s a bug. Controllers should never do DOM manipulation or hold DOM selectors, that’s where we use directives and ng-model. Likewise business logic should live in services, not controllers.

Data should also be stored in services, except where it is being bound to the $scope. Services are singletons that persist throughout the lifetime of the application, while controllers are transient between application states. So, if the controller is a coordinator between the view and the model, then the amount of the logic it has should be minimal.

Directives

Take a look at a very basic AngularJS directive. Let’s name this file appInfo.js as well as create an .html file appInfo.html as in example below.

Learn AngularJS 1.X   Codecademy.png

In this example we create a new directive called appInfo. It returns an object with three options – restrict, scope and templateURL

  1. restrict specifies how the directive will be used in the view. The 'E' means it will be used as a new HTML element.
  2. scope specifies that we will pass information into this directive through an attribute named info. The = tells the directive to look for an attribute named info in the <app-info> element, like this: The data in info becomes available to use in the template given by templateURL.
  3. templateUrl specifies the HTML to use in order to display the data in scope.info. Here we use the HTML in js/directives/appInfo.html.

Then we need to build a structure to directive in our appInfo.html

<h2 class="title">{{ info.title }}</h2> 
<p class="developer">{{ info.developer }}</p> 
<p class="price">{{ info.price | currency }}</p>

Of course <h2> and <p> are just examples. You can use here what you only want. The title and developer are controller $scope.elements. Let’s take a look at controller’s content.

$scope.apps = [ 
 { 
 title: 'MOVE', 
 developer: 'MOVE, Inc.', 
 price: 0.99 
 }, 
 { 
 title: 'Shutterbugg', 
 developer: 'Chico Dusty', 
 price: 2.99 
 }, 
]

In index.html we use only  ng-repeat to loop through app element in $scope.apps, and then app-info info=”app”

<div ng-repeat="app in apps">
     <app-info info="app"></app-info>
</div>

That’s it. It’s quite a simple example, but it helps me to refactor my code in CommonsNet project and avoid a long, boring, repetitive work while adding new elements to website. It also helps me to implement a feature I have mentioned above. I’am going to tell more about it in next blog post. Stay tuned!

Resources:

https://scotch.io/tutorials/angularjs-best-practices-directory-structure

https://www.codecademy.com/learn/learn-angularjs.

https://commonsnetblog.wordpress.com/

 

Continue ReadingAngularJS structure and directives

Adding Google Analytics To All Pages Using Flask

Google Analytics gives a detailed insight about your website including how many people visited, time, demography, how many returning visitors and all such information. It’s a real important tool to have. All you have to do is create a Universal Analytics Tracking code and use it in a javascript code. The only problem is this code needs to be present in all the pages that you wants the analytics data for. So changing any part of the javascript code anytime, needs to be changed in all .html files.

However, there is a better way of doing it in flask. Create a file base.html and write the code:

<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘<track-code>’, ‘auto’);
ga(‘send’, ‘pageview’);

</script>

Then using the property of jinja2 template extend this file in all the html files, i.e. {% extends ‘gentelella/admin/base.html’ %}. Thus now when you make some change in the above mentioned javascrpt code, you need to change it only in one place and it is changed in all other places.

Continue ReadingAdding Google Analytics To All Pages Using Flask

Getting started with Docker Compose

In this post, I will talk about running multiple containers at once using Docker Compose.

The problem ?

Suppose you have a complex app with Database containers, Redis and what not. How are you going to start the app ? One way is to write a shell script that starts the containers one by one.

docker run postgres:latest --name mydb -d
docker run redis:3-alpine --name myredis -d
docker run myapp -d

Now suppose these containers have lots of configurations (links, volumes, ports, environment variables) that they need to function. You will have to write those parameters in the shell script.

docker network create myapp_default
docker run postgres:latest --name db -d -p 5432:5432 --net myapp_default
docker run redis:3-alpine --name redis -d -p 6379:6379 \
    --net myapp_default -v redis:/var/lib/redis/data
docker run myapp -d -p 5000:5000 --net myapp_default -e SOMEVAR=value \
    --link db:db --link redis:redis -v storage:/myapp/static

Won’t it get un-manageable ? Won’t it be great if we had a cleaner way to running multiple containers. Here comes docker-compose to the rescue.

Docker compose

Docker compose is a python package which does the job of handling multiple containers for an application very elegantly. The main file of docker-compose is docker-compose.yml which is a YAML like syntax file with the settings/components required to run your app. Once you define that file, you can just do docker-compose up to start your app with all the components and settings. Pretty cool, right ?

So let’s see the docker-compose.yml for the fictional app we have considered above.

version: '2'

services:
  db:
    image: postgres:latest
    ports:
      - '5432:5432'

  redis:
    image: 'redis:3-alpine'
    command: redis-server
    volumes:
      - 'redis:/var/lib/redis/data'
    ports:
      - '6379:6379'

  web:
    build: .
    environment:
      SOMEVAR: value
    links:
      - db:db
      - redis:redis
    volumes:
      - 'storage:/myapp/static'
    ports:
      - '5000:5000'

volumes:
  redis:
  storage:

Once this file is in the project’s root directory, you can use docker-compose up to start the application. It will run the services in the order in which they have been defined in the YAML file.

Docker compose has a lot of commands that generally correspond to the parameters that docker runaccepts. You can see a full list on the official docker-compose reference.

Conclusion

It’s no doubt that docker-compose is a boon when you have to run complex applications. It personally use Compose in every dockerized application that I write. In GSoC 16, I dockerized Open Event. Here is the docker-compose.yml file if you are interested.

PS – If you liked this post, you might find my other posts on Docker interesting. Do take a look and let me know your views.

 

{{ Repost from my personal blog http://aviaryan.in/blog/gsoc/docker-compose-starting.html }}

Continue ReadingGetting started with Docker Compose

Introducing new Developers to Your Project

You may want to introduce new developers into your project. This is either to get help or to allow the community to guide the project. In this blog post, I want to present how I believe an introduction can be designed.

(1) A Landing Page

For the knitting projects, I have designed a landing page, knitting.fossasia.org. It features all related projects with links to documentation and source code as well as a short summary what it is about. You can read more about the landing page in this blog post.

The idea is to to add short snippets of information that allow new developers to explore all available options to enter the projects. This may be contact information, documentation and videos.

(2) Setup Instructions

Especially for the projects I worked on, I created a introduction videos on how to set up your development environment. This could have been in text form, too.

The problem for new developers is often that the start takes a long time. Instead of focusing on the issue they would like to solve, it sometimes takes several hours to set up the environment with lots of possibilities to make mistakes.

In order to speed up the development environment setup, you can provide additional information. The CoderDojo Zen platform has its own landing page for new developers and a description of the steps to take to setup the development environment. In the case of the knitting projects, we have YouTube video tutorials which show the necessary steps.

(3) Introduction Events

You can participate in events to show your projects to other people.

With the knitting projects, we will participate at the Maker Faire Berlin 2016.There may be local user groups where you can present the work and the learnings from them.

Google Code-In is an excellent opportunity to allow new young developers to add code to your projects and document them. You can apply as a mentor and add tasks. A first task for beginners may be to get the project running on their computer. Another task could then be to either use it in a special way and document it or to solve an issue which is easy enough.

In the following Google Summer of Code your project can be used again. You can apply as a mentor for your project and help other students to work on what you left behind.

Summary

I listed some ways I will perform to get the projects I worked on into the community. I hope they may have been an inspiration for other people who read this. If you like to contribute new ways, you can comment 🙂

Continue ReadingIntroducing new Developers to Your Project

Working with Apache Web Server

In this article, I will examine what apache is how to setup apache for ubuntu or debian and how to view error logs for apache and how to understand what the logs contain which will be useful for web development.

What is Apache?

Apache is the most popular web server on the internet. It is used to serve more than half of all active websites.

It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules.

Installing Apache on Ubuntu and Debian

If you do not already have Apache installed, you can do so now by issuing the following commands:

sudo apt-get update
sudo apt-get install apache2

If you visit your VPS’s IP address in a web browser, you will get the default Apache index page. We get the following output.

your_domain_name_or_ip_address
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.

Looking into apache error.log files

In order to effectively manage a web server, it is necessary to get feedback about the activity and performance of the server as well as any problems that may be occuring. The Apache HTTP Server provides very comprehensive and flexible logging capabilities.

Error.log file

The server error log, whose name and location is set by the ErrorLog directive, is the most important log file. This is the place where Apache httpd will send diagnostic information and record any errors that it encounters in processing requests.

It is the first place to look when a problem occurs with starting the server or with the operation of the server, since it will often contain details of what went wrong and how to fix it.

Explanation of log message

There is certain information that is contained in most error log entries. For example, here is a typical message.

[Sat Aug 20 08:09:38.958885 2016] [:error] [pid 1489] [client 127.0.0.1:40810] PHP Notice:  Constant MIN_PASSWORD_LENGTH already defined in /var/www/html/test/engelsystem/config/config.php on line 30, referer: http://localhost/

[Sat Aug 20 08:09:38.958885 2016] The first item in the log entry is the date and time of the message.

[:error] The second entry lists the severity of the error being reported.

[pid 1489] Indicates process Id

[client 127.0.0.1:40810] The fourth entry gives the IP address of the client that generated the error.

Fifth one is error message explaining the error.

Constant MIN_PASSWORD_LENGTH already defined.

File and line number

 /var/www/html/test/engelsystem/config/config.php on line 30

Error logs are easy to understand. Using error logs we can easily figure out the problem in your server or your code and fix it.

For more information about the log files and configuration please visit Apache website Apache provides excellent documentation.

Apache log files were useful for me during web development project Engelsystem. We are developing new features. Interested developers can work with us.

Development: https://github.com/fossasia/engelsystem

Issues/Bugs:https://github.com/fossasia/engelsystem/issues

Continue ReadingWorking with Apache Web Server