Dec 13, 2017

Penggunaan VCS (version control system)

Kenapa VCS?

VCS adalah shortform bagi "Version Control System", ia adalah sebuah alat/perisian wujud untuk menyenangkan developer mengurus sumber pengaturcara (source code) tanpa perlunya memindah source code scare manual dari satu sistem ke sistem yang lain.

Padahal, source code sentiasa dikemas kini dan dibaharui mengikut keperluan dari semasa ke semasa, jikalau kumpulan mempunyai lebih daripada satu developer, pengurusan source code yang tidak melibatkan kegunaan alat VCS merupakan satu perkara yang sukar atau boleh dikatakan boleh mencapai tahap mustahil (jika source codenya terlibat beribu-ribu baris kod). Bagi fasa nyahpepijat (debugging) kesukaran tidak dapat dibayangkan jika tidak wujudnya alat VCS ini!

VCS sebagai pegetahuan am

Kegunaan alat/servis VCS sudah menjadi biasa dalam dunia sistem pembangunan, servis yang (bebas digunakan dan percuma) sedia ada pada internet kini:

  • github
  • bitbucket
  • cvs (telah lama ketinggalan, boleh dikatakan tidak berguna lagi selepas kemunculan git ke dunia internet kini)

Keselamatan guna VCS

Kegunaan github/bitbucket memerlukan pengguna simpan (muat naik/upload) source code ke server github/bitbucket. Muat naikkan source code ke server github mungkin menakutkan pengguna bahawa adakah source code masih selamat disimpan pada server "orang lain".

Selepas beberapa tahun pengalaman saya guna dan simpan code atas server github, tiada sebarang masalah bernah berlaku pada source code saya.

Walau bagaimanapun, tragedi yang tidak menyenangkan hati boleh berlaku juga.  

Side note: Usaha-usaha dalam Kommuniti Opensource

Setiap developer perlu berterima kasih kepada syarikat-syarikat IT dari barat seperti Google, FB, Github... dan lain-lain lagi. Mereka telah banyak mengusahakan industri IT bagi kommuniti sumber-terbuka IT (opensource) dan menbenarkan kegunaan servis-servis mereka tanpa had (bagi aktiviti yang tidak berasaskan keuntungan sahaja). Usaha-usaha mereka telah banyak memanfaatkan developer IT memperoleh segala tutorial/artikel IT yang diperlukan atas talian.

Sebagai seorang developer di Malaysia, saya pun telah banyak menikmat usaha-usaha mereka yang sentiasa fokus pada "kemampuan developer dari kommuniti opensource". Tanpa usaha mereka, saya tidak dapat bayangkan sesiapa sanggup akan memurahkan hati pada tahap yang sama seperti apa mereka telah usahakan dalam kommuniti opensource ini. 🙏


Sep 27, 2017

Mount/Unmount external drives through command on Mac (OSX)

Once you have your external device connected to your Mac, the very first step would be making sure your Mac is aware of it, by running:
  
    diskutil list
  
Sample Volumes after running diskutil list

Let's say Mounting the target external drive 1stHDD,

    diskutil mount disk4s1
  

To unmount, run:
  
    diskutil mount disk4s1
  

Working with WinWheel.js and GreenSock's GSAP in Angular

I was assigned a task to make a spinwheel for one of the gamification feature in an webapp which was build with Angular 4.

If you've been working with Angular in Typescript for a while, especially those require 3rd party libraries integrations, you may already experienced the pain integrating stuff which was build to fully compatible with Typescript.

This post is not about solving library integration to your typescript codebase, but how do you get Winwheel.js work in your Angular code which has cost me few amount of trial and error effort, hope my sample code saves some of your development time if you are facing the same issue as I gone through.




As you can see from the typescript code above, the integration of winwheel.js and tweenlite (GSAP) just requires:
  
    import * as Winwheel from 'Winwheel';
    import * as tweenlite from 'tweenlite';
  
Next step is to create a new instance of Winwheel object with:

    this.wheel = new Winwheel.Winwheel(/* your custom config goes here */);

In the rest of your code, you can then start using Winwheel.js API through this.wheel declared above, as the example above does not require data manipulation after the spinning is complete.

GSAP integration

Working with GSAP isn't very hard, but that's one thing I've overlooked at very first time and did aware of the existence of changing target scope to a correct one.

Most of my time spent on fixing the this scope, and found out we have an option to change the this scope with onUpdateScope and this solve most of my headache integrating tweenlite to my winwheel.js.

* In the sample code above is using tweenlite, you can use tweenmax as long as you are pointing to the correct scope.

Improvement/Enhancement

If the spin's end result is required for further calculation, you'll need the service of NgZone to tell Angular to keep an eye on the changes of state.

To do so, you can add following enhancement to the onComplete function:
  
    let onComplete = () => {
      console.log('Done spinning!');
      ngZone.run(() => {
        // do something with the data obtained from the spinwheel
        let prize = this.wheel.getIndicatedSegment();
        console.log(prize);
      });
    };
  

Docs: getIndicatedSegment

Sep 7, 2017

Access raspberry remotely without password

Solution is simple, just 3 steps are required:

On your local machine (which you will access your remote server from)
1. Run:
ssh-keygen (and the following configurations are guided)
2. Configure your config file (~/.ssh/config) with your created public key directory location, for example:
 
Host 192.168.0.2 # your rpi ip address
HostName 192.168.0.2 # your rpi ip address
User pi
IdentityFile ~/.ssh/yourkey
 
3. After done creating public key, copy your public key file content
Example content of public key file
You can copy your public key content with:
cat ~/.ssh/yourkey.pub | pbcopy (for mac OS)

On raspberry pi (remote server)
3. Paste the copied content from step 2 into ~/.ssh/authorized_keys (it is the directory by default) or append to the file if existing content available.

Learning source: How to set up ssh so you aren't asked for a password

Feb 7, 2017

Raspberry Pi - The problem about "cannot change locale"

After having problem at configuring Internationalisation to en_US.UTF-8 with raspi-config,
error messages below keep popping up every time I login to my raspberry pi.

-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
and

pi@raspberrypi:~ $ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = "en_US.UTF-8",
 LC_CTYPE = "UTF-8",
 LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory


And there are bunch of locale warning during my apt-get install which is really annoying even though I am not sure how it does affect my apt-get installation even when the installation is successful.

Raspi-config internationalisation options screen
Every retry of locale change end up here in the error message below, you stuck here forever and that's it!
Change Locale Error
I've tried looking for solution, and I am lucky enough end up in the links at the bottom of this article.
The solution is simple:

  1. sudo nano /etc/locale.gen
  2. uncomment your preferred locale, for example en_US.UTF-8
  3. sudo locale-gen en_US.UTF-8
  4. sudo update-locale en_US.UTF-8

Even though it help getting rid of the annoying 'cannot change locale' or '' error message in your terminal,
it doesn't fix the "There was an error running option I1 Change Locale" issue.
As I tried reconfigure Locale changes, raspi-config will still return me to the same error as in Change Local Error screenshot above.

So until now, I'm still looking for the root cause of this problem.

TL; DR
Solution on StackOverflow - Unable to reconfigure locale in raspberry pi
Original solution source was blog years ago Raspberry Pi -- Fixing your Locale