Friday, 22 January 2016

Post 40: How to check for integer in JavaScript

In JavaScript there is no better way:

var isInt = function (x) {
        return (typeof Number(x) === 'number') && (x % 1 === 0);
      }

Tuesday, 19 January 2016

Post 39: Add audio to ionic app

ionic start IonicProject blank
cd IonicProject
ionic platform add android
cordova plugin add org.apache.cordova.media
ng-cordova.js in your www/js folder

Inject the dependency:
var example = angular.module('starter', ['ionic', 'ngCordova'])

Add a new controller in app.js:
example.controller("ExampleController", function($scope, $cordovaMedia, $ionicLoading) { $scope.play = function(src) { var media = new Media(src, null, null, mediaStatusCallback); $cordovaMedia.play(media); } var mediaStatusCallback = function(status) { if(status == 1) { $ionicLoading.show({template: 'Loading...'}); } else { $ionicLoading.hide(); } } });

in index.html add in the header:
<script src="js/ng-cordova.min.js"></script> <script src="cordova.js"></script> <script src="js/app.js"></script>

In Index.html add in the body (you have to use "android_asset"):

<ion-content ng-controller="ExampleController"> <button class="button" ng-click="play('/android_asset/www/test.mp3')">Play from file system</button> </ion-content>



Sunday, 17 January 2016

Post 38: Pulbish Ionic app to google play store

cordova plugin rm cordova-plugin-console
cordova build --release android
If you have already the key then skip this step (keep in mind to save that file, otherwise you can not update your app).
keytool -genkey -v -keystore my-release-key.keystore -alias myApp -keyalg RSA -keysize 2048 -validity 10000
(if you can't remember the information you put in there you can run this command)
keytool -keystore formconnect.keystore -list -v
Go to the /platform/android/build/outputs/apk/ and copy the file android-release-unsigned.apk to root folder
cd to root folder
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore android-release-unsigned.apk myApp
copy my-release-key.keystore and android-release-unsigned.apk to android-sdk-linux version folder (android-sdk-linux/build-tools -> select the version you want)
cd to that folder
./zipalign -v 4 android-release-unsigned.apk myApp.apk
After you have done this, you can upload it to google play store.

Thursday, 7 January 2016

Post 37: Vietnamese pronoun app

Vietnames pronoun app

This post is about an app that "calculates" the appropriate Vietnamese pronoun (or a person's family title). What may be simple in other languages like English, it's not as straightforward in Vietnamese. Vietnamese pronouns are heavily dependent on context of the conversation, your age and the age of the person you're referring to, your and the other person's social status, your relationship towards each other, and also your feelings toward the person you're talking to.

Especially for beginners but also intermediate learners, these concepts are hard to grasp. Sometimes even advanced learners still make mistakes when using Vietnamese pronouns.

Explanations in other sources only cover the most basic Vietnamese pronoun concepts but exlude more complex concepts e.g. how to correctly address close friends or family members.

This app will help you finding the correct pronoun in every situation. (However in this app I'll exclude insults and colloquial language.) To be specific, the situations I want to cover are:
- how to correctly address family members, e.g. mother-in-law, aunts, cousin, etc.
- How to correctly address friends and aquaintances, e.g. girlfriend, boss, colleagues, etc.
- how to correctly address people you met for the first time, e.g. vendors in the street or any other people from all ages you just met.

How the app is structured:
The app has three tabs: "Start", "Help", and "About" (see the image below).

In the "start" tab you'll see different buttons. Click on the button that applies to the person you want to address and the app will guide you to the correct pronoun for that person but also for yourself.


For example you want to address your mother-in-law in Vietnamese, then you first click on "start", then select "family member.


After that you get to the view "family". Here you want to select "parents".


After that "mother-in-law".


At the end you'll see the correct pronoun, an explanation (and in certain cases also additional information or exceptions when to use that pronoun) and also the correct pronoun for yourself. In this example the app will tell you that "Mẹ" is the correct pronun when you want to address her and "con" is the correct pronoun for you when you want to address yourself in a conversation with her.


You can download the app for FREE here on Google Play: Vietnamese Pronouns

This is a NON-PROFIT project that I do in my spare time alone and it's done in order to help learners with the Vietnamese language.

Another app I made for learning Vietnamese is this one: North and South Vietnamese dialect app

If you want to support this project, please share and rate highly on Google Play Store and on this blog. Your support would be much appreciated. Let me in the comment below what you think. Any feedback is much appreciated. Thanks in advance.

Post 36: ionic android cordova

First install nodejs:
https://nodejs.org/en/download/
Install Java:
How to Install Java
Install cordova
sudo apt-add-repository ppa:cordova-ubuntu/ppa sudo apt-get update sudo apt-get install cordova-cli npm install -g cordova
Install ionic
sudo npm install -g cordova
download android sdk (go down to "SDK only"):
http://developer.android.com/sdk/index.html

update android manager
open the directory "android-sdk-linux" and go to the "tools" folder. Open android manager:
./android
set variable ANDROID_HOME to where the android sdk is located:
export ANDROID_HOME=/path/to/the/diretory/android-sdk-linux"

Start a new ionic project:
ionic start app_name blank
Selecting "blank" gives you a blank project. Optionally you can also choose "tabs", or "sidemenu".

cd app_name

Add platform:
ionic platform add android
Build ionic project:
ionic build android

test it on browser:
ionic serve --lab

test it on device:
ionic run android

Saturday, 21 November 2015

Post 35: VisualStudio is now open source

You've heard it correctly. Microsoft's VisualStudio is now open source. You can check out the code on their gitHub account:

https://github.com/Microsoft/vscode

If you want to run it on Linux, make sure you have these installed:
  • NodeJS > v0.12
  • Python > v2.7
  • make
  • A proper C/C++ compiler tool chain, for example GCC
Open your terminal and build VS with these commands.
git clone https://github.com/microsoft/vscode
cd vscode && npm install -g mocha gulp
./scripts/npm.sh install --arch=x64
# for 32bit Linux
#./scripts/npm.sh install --arch=ia32
In order to run it type in this code:
./scripts/code.sh

Friday, 13 November 2015

Post: 34: How to add a linebreak with CSS

Apart from inserting a line break (or carriage returns) with </br> in your HTML, you can insert a linebreak with CSS too, since CSS is responsible for layout and flow - a line break can be considered either of those.

.linebreakWithCSS {
  display: block;
  white-space: pre;
  content: "Line 1 \ALine 2\A...";
}

The CSS snippet above will print you the following:
Line 1
Line 2
...
Tweet