Posts

Showing posts from 2015

Learning Lua

Image
Learning Lua Table of Contents Background Tables metatable functions coroutine Lua as Object-oriented programming 1 Background Lua as an embedded language was popular in the game industry and also in any embedded scenario. I tried to wrote a Lua module for Nginx, which already has a ported Lua environment inside. And since this is my first time to get familiar with Lua, and to enjoy its simplicity. My learning materials were no special, but its official document . I wrote my notes down in order for future review. 2 Tables To understand table is to understand Lua, or in another word, Lua's syntax was nothing but just tables, no more. Tables in Lua is in similar with the dictionary in Python, in my view. a = {} a.x = 1 a[ 'x' ] = 1 2.1 metatable Lua's metatable is similar to magic methods in python. 3 functions Lua as a functional programming language, because the function is also the first-class variable. That'

ReactiveX Asynchronous Programming In Java

Image
ReactiveX Asynchronous Programming In Java There is a much detailed blog about ReactiveX of myself, checkout here . Table of Contents What is Asynchronous programming? Ways of Asynchronous programming in java Java Callback functions Java Future Benefit of RxJava 1 What is Asynchronous programming? The asynchronous issue exists, because of the blocking nature of every activity in reality. Every operation consume time, in theory, computers need to take at least one frequency to execute one instruct, it takes time between every oral conversation in the speed of voice at least. That's the blocking nature of this world, and the most valuable resource of all is the time. Some times the computer cannot wait for that longer for the blocking API, like in network communication, it waste of the computer resource so much. The another reason is the event-based scenario. In a network connected chatting app, program listens for every coming data continuously and output

Android Account Manager

Image
Android Account Manager Table of Contents the begging of an Internet mobile app Account Management Demos 1 the begging of an Internet mobile app The first component that an Internet startup needs to build is its user system. How to expand his users in an easily, convenient and user-friendly way, and how to develop its account system in a scalable method? The account system is the crucial and the most important part of a company, most of the content and service provider companies always develop its account systems followed the oAuth standard. There are third party authentication plugins, like stormpath and Auth0 targeted into those account management field, you can build your web app above that service. For an Android mobile developer, there are already a middle-ware in API level, AccountManager. Take a glance of Account preference in the Setting App, and experience how Gmail, Youtube, and G+ works with multi-shared google accounts and switch between them i

Logical Volume Management

Image
Logical Volume Management Table of Contents What is LVM? Conceptions How to create PV create VG create LV 1 What is LVM? LVM stands for Logical Volume Management, which is one kind of virtual disk partition. In the traditional way, We need to separate a disk into multiple partitions, then format that partition with a filesystem. Once you write the partition table to the disk, rewrite this table will lose all your disk data. But, LVM gave more scalable and dynamic options, we can adjust and re-create partitions without reboot and re-mount process. 2 Conceptions VG:   Volume Groups PV:  Physical Volumes LV:   Logical Volumes Volume Groups is a collection of Logical volumes, and it is created on top of physical volumes, Physical Volumes are physical disk partitions with LVM header. Logical Volumes are the final partitions that we can format with our favorite filesystem. Topology of these concepts: one Volume Group can include more than one Phys

Javascript Callback Hell

Image
Javascript Callback Hell Table of Contents callback hell Promise bluebird 1 callback hell Javascript callback hell looks like an inherent problem in js language, because of its asynchronous nature, writing callback functions and nesting them together looks the only way to coding for a newbie.    It then gave programmers some mess code, if he persists to writing nesting callback code, and this mess codes are named as callback hell . fs.readFile( "file.json" , function ( err , val ) { if ( err ) { console.error( "unable to read file" ); } else { try { val = JSON.parse(val); console.log(val.success); } catch ( e ) { console.error( "invalid json in file" ); } } }); 2 Promise Promise is a new ES6(ECMAScript 2015) feature, is used for deferred and asynchronous computations. Promise is also a proposal , which represents the eventual

JBIG Android library published

Image
JBIG Android library published Table of Contents Design details Where it come from? Include the dependency into your gradle script Start to use it Please jump to jbig-android 's home page . 1 Design details jbig-android is just a JNI level wrapper of jbig-kit , so it inherited its License as GPL v3. If you are a newbie of JNI programming, you can refer my JNI tutorial . Basically, JNI part is the key of porting jbig-kit to android platform. Beside the core implementation of this project, the sample code pleased me the most. I tried to wrote it in an MVC way, which took me the most time, and it succeeds, Maybe I will use another post to describe this MVC paradigm and its apply in Android App. Of course, I learned this way and copy it from Chris Banes's sensational work philm . 2 Where it come from? About years ago, I met this problem, the format of hand write a signature in bank related system, like a POS. The customer sign in the screen(LED)

How to publish and distribute your Android AAR package?

Image
How to publish and distribute your Android AAR package? Table of Contents JCenter vs Maven Central Add build script dependencies Configure the library module Sign up an account in bintray Sample 1 JCenter vs Maven Central I don't know since when Android Gradle's default repository started to use jcenter instead of the older maven central as the default archive repository. According to some talks, Jcenter can leverage the JFrog's technology, which is a superset of Maven central, so it improved and promoted the efficiency of Android project compilation. In a word, Jcenter is better than Maven Central. 2 Add build script dependencies dependencies { classpath 'com.android.tools.build:gradle:1.3.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' // NOTE: Do not place your application dependencies here; the

Install Software RAID in Linux System

Image
Install Software RAID in Linux System Table of Contents Benefit Prepare install and configure mdadm finished 1 Benefit RAID can provide stable, speed and security for your data access, but not at the same time. We need different performance at a different scenario, and the above three traits that I mentioned, are trade-off factors in real apply, some time we sacrifice one to achieve another. In my desktop work station, what I really need is the speed all the time. That's the RAID-0. Here is my disks, one SSD as the system disk for ubuntu, and two additional 1T disks to be an RAID-0 array. 2 Prepare Plug two disks into the motherboard first, then erase the disk's format use fdisk tool and build one partition for each one with the same size. In my case, I got two devices, /dev/sdb, /dev/sdc. sudo fdisk /dev/sdb # d .... delete all partition in the hard driver # n create one partition for the whole disk # t choice fd (linux raid disk)

Python yield paradigm

Image
Python yield paradigm Table of Contents generator or iterator generator pipe coroutine concurrency The yield keyword in python language is its landmark and invention, it is not just a language syntactic and feature, it lets python programming rocks in the functional programming way. Here in this article, I try to collect all the yield magic here to surprise the python newbie. 1 generator & iterator "yield" is the keyword that to make a generator in python, so what the generator is? Before that, I just try to explain what the Iterator is first? An iterator is an easier and more common concept in objective oriented languages, take java, for example, basically, every container can be converted to an iterator. List < String> namesList = new ArrayList < String> (); // add 3 names namesList.add( "moses" ); namesList.add( "jacobs" ); namesList.add( "davide" ); // iterate via Iterator Iterator < Str

RAID learning

Image
RAID learning Table of Contents RAID's benefit RAID's types type 0 type 1 type 10 type 2, 3, 4 type 5 type 6 RAID's limitation 1 RAID's benefit So, what the RAID is? RAID is short for Redundant Array of Independent Disks. In the storage industry, the speed, redundancy, and cost are the three factors that the market cares about. I/O speed: hard drive's I/O performance is limited by the physical law, if we continue to use magnetic storage materials. redundancy: the fault of a subset disks in an array can't damage the whole data stored in them. cost: the density of data per dollar. RAID is a common solution to face that. 2 RAID's types 2.1 type 0 parallel multi disks together, with the highest disk write/read IO performance, but none data security. split the data into n pieces, n equals to the array size of the disks. And both the write and read are parallel to improve the speed, but one disk's damage c

DIY my dreaming machine

DIY my dreaming machine Table of Contents My Requirements Composition of a PC Where to begin Budget 1 My Requirements Now I works in a PC desktop only on my office time, and it is a Mac machine, and after my office time, I primarily do entertainment and learning on my MacBook air (mba). To be honestly, I like my mba, but not my IMac, Mac system is stable, UI friendly and upgrade my efficiently a lot only with a high-ranking hardware, its so bad IO efficiency make her only perform good with a SSD driver inside. And also it's horrible scalability and its closed nature like Windows make her less funny in a nerds's eye. So what's my dreaming machine is? I think the answer is on the DIY field. It has to running a Linux system, for software hacking and audio composition. My favorite configuration is intel haswell CPU with more the 8G memory with a nice display, and also with vt-d compatible. 2 Composition of a PC The CPU, Motherboard, Mem

How to install and switch between multi JDK?

How to install and switch between multi JDK? Table of Contents How to install and switch between multi JDK? Linux Mac OS X Common incompatible errors between different version 1 How to install and switch between multi JDK? I suppose that you are installed both java 7 and 8 into your system. So how to switch between them. 1.1 Linux # !/bin/ bash # java1.7.sh # source java1.7.sh to switch jdk 1.7 export JAVA_HOME = "/opt/tools/jdk1.7.0_60" export CLASSPATH =.:${ JAVA_HOME }/lib:${ CLASSPATH } export JDK_HOME = "/opt/tools/jdk1.7.0_60" export PATH = "/opt/tools/jdk1.7.0_60/bin" :${ PATH } # !/bin/ bash # source java1.8.sh to switch to JDK 1.8 export JAVA_HOME = "/opt/tools/jdk1.8.0_05" export CLASSPATH =.:${ JAVA_HOME }/lib:${ CLASSPATH } export JDK_HOME = "/opt/tools/jdk1.8.0_05" export PATH = "/opt/tools/jdk1.8.0_05/bin" :${ PATH } 1.2 Mac OS X # ~/.bash_profile

Android UnitTest

Android UnitTest Table of Contents kinds of Unit Tests in Android Android Instrument Test Junit Test the Demo Unit Test was always the most import part of a project, especially for Object-oriented programming like Java codes, and also was the necessary part of Test-Driven Development technology. But how to process test-driven technology in Android app developement, we all know that android app is based on Java code, and the thought of TDD was in the blood of Java. There are must be some ways to do TDD in Android, and this article will guide you to the Unit test in Android Development. 1 kinds of Unit Tests in Android There are two levels of Unit Test in Android, Android Instrument Test, which running in the Android Devices; and Junit Test, which running without any Android environment. The key difference between two of them are the dependency on the android.jar, in other word, the Android API. We develop android app by import the dependency of android.jar, whi

Android ViewPager to implement guide page

https://github.com/suzp1984/welcome This demo started up, because one of my former colleague tried our app, and blamed the guide UI, which is a little stuck. I know the viewpager is a convenient and simple substitute for our bad implementation. So I started it. Make your app guide UI smooth and response quickly, use ViewPager.

Customize ubuntu login console by Cowsay, ascii art

Before this article, I wanna introduce cowsay again, cowsay is an ASCII art generator, which is alway the nerd's favorite toy. Cowsay & Fortune I already used cowsay in my email client, gnus. And at that moment, I found out cowsay's closet mate, fortune . And this time is the moment to make some fun to my ssh login terminal. How to decorate your ssh login console? Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-53-generic x86_64)  * Documentation:  https://help.ubuntu.com/  ____________________________ / Expect the worst, it's the least you \ \ can do.                                            /  --------------------------------------         \   ^__^          \  (oo)\_______             (__)\              )\/\                   ||--------w |                   ||              || Following is a step to step tutorials to make the above dark ASCII art. install both cowsay and fortune. install following script into /etc/update-motd.d/    

Dig into Https client connection in Android

Dig into Https client connection in Android Table of Contents reference resources Java Keytool Certificate formats Use Https in Android Client Java SSLContext Two ways SSL verification TLSDemo 1 reference resources http://developer.android.com/training/articles/security-ssl.html http://ogrelab.ikratko.com/using-android-volley-with-self-signed-certificate/ http://stackoverflow.com/questions/2138940/import-pem-into-java-key-store http://stackoverflow.com/questions/3685548/java-keytool-easy-way-to-add-server-cert-from-url-port 2 Java Keytool Java keystore is like a database which store certificates and private keys and protect them by a password maybe. There are at least three format s of that, JKS, PKCS12, JCEKS, and many more. But in this tutorial, I only consider two formats of that JKS which is the Java's default format and BKS which is the Android's default format. How to import a certificate to the BKS style KeyStore? First step was to pr