Virtualbox folder sharing

Here are the instructions:

When Guest and Host are Linux/Windows...
http://www.murga-linux.com/puppy/viewtopic.php?t=76061

When Guest and Host both are Linux...
http://www.murga-linux.com/puppy/viewtopic.php?t=110070

An Engineer and a Salesman

An Engineer is said to be a man who knows a great deal about a very little, and who goes around knowing more and more, about less and less, until finally, he practically knows everything about nothing; whereas, a Salesman, on the other hand, is a man who knows a very little about a great deal, and keeps on knowing less and less about more and more until finally he knows practically nothing, about everything. – from a newspaper in the 1930s

http://harry-lewis.blogspot.in/2016/12/classics-of-computer-science.html

LOC Produced

If we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent".

- Edsger Wybe Dijkstra

(in EWD 1036: On the cruelty of really teaching computing science)

Sync database with SJA (SQLyog Job Agent)

~# /opt/lampp/bin/mysql -u root -p -e "create database flog"
~# /opt/lampp/bin/mysqldump -d -u root -p blog > blog.sql
[-d means without data, that means only schema export]
~# /opt/lampp/bin/mysql -u root -p flog < /root/blog.sql
~# mkdir sja
~# cd sja
[download sja from https://code.google.com/p/sqlyog/wiki/Downloads]
~/sja# tar -xvzf sja1209.x86_64.tar.gz
~/sja# ./sja blog_to_flog_sync.xml
[if sja says, couldn't connect through /tmp/mysql.sock, ln -s /opt/lampp/var/mysql/mysql.sock /tmp/mysql.sock]
============

~/sja# cat blog_to_flog_sync.xml
<?xml version="1.0" encoding="UTF-8"?>
<job version="11.1">
<syncjob>
<fkcheck check="yes" />
<twowaysync twoway="no" />
<source>
<host>localhost</host>
<user>root</user>
<pwd></pwd>
<port>3306</port>
<compressed>1</compressed>
<cleartext>0</cleartext>
<sessiontimeout>28800</sessiontimeout>
<ssl>0</ssl>
<sslauth>0</sslauth>
<clientkey></clientkey>
<clientcert></clientcert>
<cacert></cacert>
<cipher></cipher>
<charset></charset>
<database>blog</database>
</source>
<target>
<host>localhost</host>
<user>root</user>
<pwd></pwd>
<port>3306</port>
<compressed>1</compressed>
<cleartext>0</cleartext>
<ssl>0</ssl>
<sslauth>0</sslauth>
<clientkey></clientkey>
<clientcert></clientcert>
<cacert></cacert>
<cipher></cipher>
<charset></charset>
<database>flog</database>
</target>
<tables all="yes" />
<sync_action type="directsync" />
<abortonerror abort="no" />
<sendreport send="no" /></syncjob>
</job>
~/sja#

How to run your own OS kernel

# prepare a disk image to boot
harddisk_image_size=$((4*1024*1024)) # 4 megabytes
harddisk_image="harddisk.img"
kernel_args=""
kernel_binary="bin/kernel.bin"
if [ ! -f $harddisk_image ]
then
# create image
dd if=/dev/zero of="$harddisk_image" bs=4k count=$((harddisk_image_size/4096)) 2>/dev/null
# format image
mkfs.vfat "$harddisk_image"
# install syslinux
syslinux "$harddisk_image"
# copy mboot.c32 (required for Multiboot)
mcopy -i "$harddisk_image" /usr/lib/syslinux/mboot.c32 ::mboot.c32
# create syslinux.cfg
echo '
TIMEOUT 1
DEFAULT mboot.c32 kernel.bin '$kernel_args'
' | mcopy -i "$harddisk_image" - ::syslinux.cfg
fi
# now copy your own OS kernel to it
mkdir -p /tmp/harddisk
mount -o loop "$harddisk_image" /tmp/harddisk
cp "$kernel_binary" /tmp/harddisk
umount /tmp/harddisk






# prepare another disk to store some data
if [ ! -f "harddisk2.img" ]
then
dd if=/dev/zero of=harddisk2.img bs=4096 count=2560 # 10 megabytes
mkfs.ext2 -F -N 4096 -b 4096 harddisk2.img 2560
fi
# copy data to it
mkdir -p /tmp/harddisk
mount -o loop harddisk2.img /tmp/harddisk
cp -r ../hdd/* /tmp/harddisk
umount /tmp/harddisk





# prepare yet another disk to use with virtio
cp harddisk2.img harddisk3.img





# now run quemu

# booting from bootable disk
#qemu-system-i386 -m 64 -vga vmware -serial stdio -hda ./harddisk.img

# booting kernel directly from binary
#qemu-system-i386 -m 64 -vga vmware -serial stdio -kernel "$kernel_binary"

# booting from virtio disk (bootable) - works!
#qemu-system-i386 -m 64 -vga vmware -serial stdio -drive file=harddisk.img,if=virtio

# all together: booting kernel.bin, hda with ext2 fs, another non-bootable ext2 disk connected through virtio interface
#qemu-system-i386 -m 64 -vga vmware -serial stdio -kernel "$kernel_binary" -hda ./harddisk2.img -drive file=harddisk3.img,if=virtio

A function and a macro with same name.

~# cat a.c
#include<stdio.h>
#define inc(a) inc(a,1)
int inc(int a, int b)
{
return a+b;
}
int main()
{
int k = 9;
k = inc(k);
printf("%d\n", k);
return 0;
}
~# gcc a.c
a.c:3:21: error: macro "inc" passed 2 arguments, but takes just 1
a.c:4:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
~#

Here both function and macro with same name can't co exist.
Preprocessor performs macro expansion at function definition as well (at line 3).
But we don't want preprocessor to perform macro expansion there.
So we simply enclose the function name with parentheses while defining the function.
And we are done.

~# cat a.c
#include<stdio.h>
#define inc(a) inc(a,1)
int (inc)(int a, int b)
{
return a+b;
}
int main()
{
int k = 9;
k = inc(k);
printf("%d\n", k);
return 0;
}
~# gcc a.c
~# ./a.out
10
~#

Answer Set Programming: with dlv and ASPIDE

- go to http://www.dlvsystem.com/dlv/
- download dlv.x86-64-linux-elf-static.bin
- go to https://www.mat.unical.it/ricca/aspide/download
- chose ".jar packages without installer" to download ASPIDE-Installer-Java-Package.zip
- # mv dlv.x86-64-linux-elf-static.bin dlv
- # chmod a+rx dlv
- extract ASPIDE-Installer-Java-Package.zip, it gives a folder ASPIDE
- go to ASPIDE
- # java -jar startAspide.jar
- internet connection is required here.
- it asks to install latest aspide, chose to install.
- it asks to install aspide add-ons. allow to install it.
- after installation, it asks for registration, register with your name and email.
- it sends a authentication code to mailbox and asks to input authentication code.
- provide authentication code and aspide starts...
- it asks for a project workspace path and then asks for path to dlv, provide them.
- now IDE of aspide opens... close it.
- now onwards aspide can be opened by # java -jar startAspide.jar
however, it needs internet to check updates etc. before starting IDE.
better to use # java -jar application/aspide/aspide.jar
- now IDE opens...
- create a new project
- create a new file : "DLV File with Arithmetic Expressions"
- write an asp program in the file and save it.
- to run the asp program, click Execute->Run.
- to make a query, click Execute->Query.
- query dialog opens, tick the checkbox "Epistemic Mode".
- type the query and suffix it with a question mark, then click "Execute".
- you may need to click "Run Configurations" and set path of dlv executable, if it asks: executable not found.
- enjoy.