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