Monday, September 26, 2016

FUSE sshfs

Installation
sudo apt-get install fuse
sudo apt-get install sshfs
sudo apt-get install exfat-fuse exfat-utils
Create path
mkdir sshfs-path

Mount
sshfs root@172.16.40.83:/run /home/fcm/sshfs-path/
Unmount
fusermount -u /home/fcm/sshfs-path

Sunday, September 25, 2016

python 3 compliance pyzmq sample

These two python script files are modified from pyzmq samples

topics_pub.py

#!/usr/bin/env python
"""Simple example of publish/subscribe illustrating topics.

Publisher and subscriber can be started in any order, though if publisher
starts first, any messages sent before subscriber starts are lost.  More than
one subscriber can listen, and they can listen to  different topics.

Topic filtering is done simply on the start of the string, e.g. listening to
's' will catch 'sports...' and 'stocks'  while listening to 'w' is enough to
catch 'weather'.
"""

#-----------------------------------------------------------------------------
#  Copyright (c) 2010 Brian Granger
#
#  Distributed under the terms of the New BSD License.  The full license is in
#  the file COPYING.BSD, distributed as part of this software.
#-----------------------------------------------------------------------------

import itertools
import sys
import time

import zmq

def main():
    if len (sys.argv) != 2:
        print('usage: publisher <bind-to>')
        sys.exit (1)

    bind_to = sys.argv[1]

    all_topics = ['sports.general','sports.football','sports.basketball',
                  'stocks.general','stocks.GOOG','stocks.AAPL',
                  'weather']

    ctx = zmq.Context()
    s = ctx.socket(zmq.PUB)
    s.bind(bind_to)

    print("Starting broadcast on topics:")
    print("   %s" % all_topics)
    print("Hit Ctrl-C to stop broadcasting.")
    print("Waiting so subscriber sockets can connect...")
    print()
    time.sleep(1.0)

    msg_counter = itertools.count()
    try:
        for topic in itertools.cycle(all_topics):
            msg_body = str(next(msg_counter))
            print("    Topic: {}, msg:{}".format(topic, msg_body))
            s.send_multipart([topic.encode(), msg_body.encode()])
            # short wait so we don't hog the cpu
            time.sleep(0.1)
    except KeyboardInterrupt:
        pass

    print("Waiting for message queues to flush...")
    time.sleep(0.5)
    print("Done.")

if __name__ == "__main__":
    main()


topics_sub.py
#!/usr/bin/env python
"""Simple example of publish/subscribe illustrating topics.

Publisher and subscriber can be started in any order, though if publisher
starts first, any messages sent before subscriber starts are lost.  More than
one subscriber can listen, and they can listen to  different topics.

Topic filtering is done simply on the start of the string, e.g. listening to
's' will catch 'sports...' and 'stocks'  while listening to 'w' is enough to
catch 'weather'.
"""

#-----------------------------------------------------------------------------
#  Copyright (c) 2010 Brian Granger, Fernando Perez
#
#  Distributed under the terms of the New BSD License.  The full license is in
#  the file COPYING.BSD, distributed as part of this software.
#-----------------------------------------------------------------------------

import sys
import time

import zmq
import numpy

def main():
    if len (sys.argv) < 2:
        print ('usage: subscriber <connect_to> [topic topic ...]')
        sys.exit (1)

    connect_to = sys.argv[1]
    topics = sys.argv[2:]

    ctx = zmq.Context()
    s = ctx.socket(zmq.SUB)
    print(connect_to)
    s.connect(connect_to)

    # manage subscriptions
    if not topics:
        print("Receiving messages on ALL topics...")
        s.setsockopt(zmq.SUBSCRIBE,'')
    else:
        print("Receiving messages on topics: %s ..." % topics)
        for t in topics:
            s.setsockopt_string(zmq.SUBSCRIBE,t)
    print()
    try:
        while True:
            topic, msg = s.recv_multipart()
            print('   Topic: %s, msg:%s' % (topic, msg))
    except KeyboardInterrupt:
        pass
    print("Done.")

if __name__ == "__main__":
    main()


raspberry pi (mac os x)

Not yet there.

http://www.jaredwolff.com/blog/cross-compiling-on-mac-osx-for-raspberry-pi/

git:
https://github.com/raspberrypi

buildroot sample
https://github.com/gamaral/rpi-buildroot/

PiLFS
http://www.intestinate.com/pilfs/
http://www.intestinate.com/pilfs/guide.html

GPIO

gpio.c

#include <linux/module.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>

int irq_number;

static irqreturn_t gpio_interrupt_handler(int irq, void* dev_id) {
        printk(KERN_ERR "gpio0 IRQ %d event",irq_number);
        return(IRQ_HANDLED);
}


static int __init gpio_init(void) {
        irq_number = gpio_to_irq(25);

        if ( request_irq(irq_number, gpio_interrupt_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING|IRQF_ONESHOT, "gpio_reset", NULL) ) {
                printk(KERN_ERR "GPIO_RESET: trouble requesting IRQ %d",irq_number);
                return(-EIO);
        } else {
                printk(KERN_ERR "GPIO_RESET: requesting IRQ %d-> fine\n",irq_number);
        }

        return 0;
}

static void __exit gpio_exit(void) {
        free_irq(irq_number, NULL);
        printk ("gpio_reset module unloaded\n");
        return;
}

module_init(gpio_init);
module_exit(gpio_exit);

MODULE_LICENSE("GPL");

Makefile

CCPREFIX=arm-linux-gnueabihf-

obj-m += gpio.o

all:
 make ARCH=arm CROSS_COMPILE=${CCPREFIX} -C /home/fcm/rpi/rpi-buildroot/output/build/linux-rpi-4.4.y M=$(PWD) modules
clean:
 rm *.ko
 rm *.o
 rm *.mod*

Thursday, September 8, 2016

Unity 3D on iOS

Doc:
https://docs.unity3d.com/Manual/iphone-GettingStarted.html

Part 1:
https://www.raywenderlich.com/25205/beginning-unity-3d-for-ios-part-13
Part 2:
https://www.raywenderlich.com/?p=25349
Part 3:
https://www.raywenderlich.com/?p=25828

Submission:
https://unity3d.com/learn/tutorials/topics/mobile-touch/how-submit-ios-app-store-overview

Bezier Curve

Quadratic:

Cubic:



In case of the cubic formula P0, P1 and P2 are your control points. t has to be a value between 0 and 1 and represents the "position" on the curve. By incrementing t step by step you'll get several points you can use to actually draw the curve.

So using the above formula you could do something like
glBegin(GL_LINE_STRIP);
for(float t=0; t <= 1; t += 0.1) {
     float x = (1-t)*(1-t)*p0.x + 2(1-t)*t*p1.x + t*t*p2.x;
     float y = (1-t)*(1-t)*p0.y + 2(1-t)*t*p1.y + t*t*p2.y;
     float z = (1-t)*(1-t)*p0.z + 2(1-t)*t*p1.z + t*t*p2.z;

     glVertex3f(x, y, z);
}
glEnd();
The smaller the steps you use for t the smoother the curve will become. That's it. Really.
Generic:
http://www.gamedev.net/topic/534082-drawing-a-curve-in-opengles---how/

iOS:
http://stackoverflow.com/questions/5054790/cgpathref-bezier-curves-in-opengl-es

Android:
http://blog.uncle.se/2012/02/opengl-es-tutorial-for-android-part-ii-building-a-polygon/

Unity:
http://www.theappguruz.com/blog/bezier-curve-in-games

Wednesday, September 7, 2016

github access from ubuntu

sudo apt-get install git
sudo apt-get install ssh
export SSH_AUTH_SOCK=0
eval `ssh-agent -s`
ssh-keygen -t rsa
ssh-add ~/.ssh/id_rsa
ssh-add -l
cat ~/.ssh/id_rsa.pub
go to github and add public key

ssh -vT git@github.com
"Hi XXX! You've successfully authenticated, but GitHub does notprovide shell access"

git clone git@github.com:xxx/xxxx.git
cd xxxx/
git add xxxx.py
git add xxxx.*
git remote -v
git remote remove origin
git remote add origin git@github.com:xxx/xxxx.git
git push --set-upstream origin master
git branch
git push