# A Puzzle in probability theory

Calculating probability for a never ending situation which is recurring.

Problem: A coin tossing game between two friends (of course Alice & Bob may be Eve is also there watching them play).

Find probability of Alice winning if both Alice and Bob has two weighted coins which has a and b

Assume Alice plays first and whoever gets Head first wins.

Solution:

P(A) = Probability of Alice winning the game = Probability of Alice coin to show head on first throw + (Probability of Alice count to show Tail on first throw)(Probability of Bob coin to show tail)*Probability of Alice count to come head + .. …

 H + TT H + TT TT H

 P(A) = a + (1-a)(1-b) P(A) => P(A) = a / (a(1-b) + b) 

# Running DHCP client manually

dhclient: Dynamic Host Configuration Protocol Client


dhclient eth0



I have to put above in init.d to make it run at startup. In my system something was screwed and eth0 was not getting the IP address.

dhclient is also used for renewing IP address


dhclient -r && dhclient



# Running application just with X11

I have ubuntu core on my system without any UI just the bare bone minimum ubuntu core. I want the system to run some qt application nothing else.

There was two ways to it either I can take the Ubuntu mate and remove useless stuff and make my process run at startup with auto-login or to use bare bone ubuntu core and then just add the things needed to run my application.

Actually I would not have needed anything else for qt application and just used –platform linuxfb flag to run the Qt app with gun on the frame buffer. I actually did that but the problem was frame buffer approach was too slow I can actually see the screen restoring from top to bottom and for my application there was some times where screen was updated quite frequently. So I needed some other windowing system library like Wayland or X11 to handle the slow Frame buffer approach.

I chose X11 first and with some hiccups I made it work woohoo!!

You just need to install xorg and then use startx. I have put this in startup script inside /etc/init.d I will cover application starting at boot up in some other post.

apt-get install  libqt5declarative5
# for my qt application this will install qt5-default and other qt related dependencies



It was quite a great learning and good experience to make everything work. Now the ubuntu core boots with my splash and starts all three of my qt apps with Gui and works well. It is very fast and no extra processes consuming my processor or hogging the system’s RAM. No window manager no session manager no desktop manager.

You can start any application simply by

startx application_name
[\code]

# Boot log of nano pi

### Alternative of slack:Mattermost

Today I met a friend of mine and he showed me this software hosted on his companies server. This is a great alternative for paid slack. We are using unpaid version of slack and some restriction like search limit no search functionality in archived history chat. Limitation on files shared are annoying. I don’t mean to say that I want all this free it is just that for us (trying not to pay for this) mattermost will be more suitable option.

# How to give permissions to devices

Many a time you face with this challenge that as a user you do not have permission to read write a device file in Linux without becoming sudoer.

Example: Let us say you have a USB device say a camera or any other device file let us say /dev/uinput the file for multi touch.

You can only run this program with sudo as the device files will not be accessible otherwise.

There is a workaround to make these files read/writable once and for all by doing something like:

sudo chmod 777 /dev/uinput


But You need to do above on each restart and also not a great way to handle this problem.

There is an easy way by creating rules file inside /etc/udev/rules.d.
For example:


# DVP sensor driver rule

KERNEL=="video0", SUBSYSTEM=="video4linux", ATTRS{name}=="vfe_0", GROUP="video", MODE:="766"



# Markdown Cheatsheet (.md)

This is mostly for my note and remembering. Markdown is very common now, and the simple formatting language trick  is very common in other formatting also at least partially. Some sample use cases: GitHub readme, Wikipedia ..

<h3>Attaching an image </h3>

![alt text](image.jpg “image title”)

For image “!” mark is very important otherwise it will just link the file and image will not show.

## for smaller heading and so on

In both above cases you can link to outside world also and in directories also.

# WordPress Cheatsheet

### Posting code in your blog

Depending upon your need you can use tag code
e.g.

 ls

A proper detailed version:
[ code language=”language of your choice”]  Code in language of your choice [/code]
language can be many like cpp, bash, css, html

will give you (for language = “csharp”)

 Console.Writeln("Learning WordPress");

You can insert formula using $\LaTeX$

Like let us say you want to write formula 4/2 = 2 with latex

$\frac{4}{2} = 2$

Like

$A = \int \frac{1}{t^2}.dt = -\frac{1}{t}$

$\int_0^1 f(x) \, \mathrm{d} x$

$i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$

Find the GitHub link for the post source file here

# All ip assigned within a network

Many a time you wanted to know the assigned ip addresses in your LAN. My use cases:

I was working on nano pi neo cheapest things can be!!

You don’t want to move from your ass but this is more of a reason when you already know how to do this 🙂

Okay so on windows you have Advanced ip scanner. You can even log into your router and get to see the client list this is always the easiest way but (ohh but again)..   what if you have reset your router password. Most of the time you will forgot it!! It is not often that you need to login into your router so reset password means forgot. Do you want to reset the router password now just for this with router’s reset button. Or you are in office or you don’t own the router.

Anyway whatever your cause is here is a very easy command to get the list of all assigned ip using linux system:

 sudo apt-get install nmap 

 :~$sudo nmap 192.168.100.5/24 -sP  Starting Nmap 6.40 ( http://nmap.org ) at 2017-01-04 18:23 IST Nmap scan report for domain.name.dlink.com (192.168.100.1) Host is up (0.00024s latency). MAC Address: 1C:5F:2B:4D:05:71 (Unknown) Nmap scan report for 192.168.100.26 Host is up (0.00028s latency). MAC Address: FA:7B:DE:ED:46:55 (Unknown) Nmap scan report for 192.168.100.4 Host is up. Nmap done: 256 IP addresses (3 hosts up) scanned in 3.27 seconds  If there are not much of machines in your LAN you will figure out which machine has what ip or you can ssh to each to verify. Without nmpa also you can ping all the ip and get the list but nmpa also tells you the friendly name of the machine. # Clone an SD-card You will find many ways to clone an SD-card there are softwares like win32diskimager (A great tool for all practical purposes related to flashing cloning). You have the famous Linux dd command. The problem arise when you are working on a bigger sd-card say 64 Gb. You have done something really cool and you want this to be in production or just share this with your friend so they will not spend 4-5 hours following your script to recreate the same image. You can just clone your card and zip it that will make the footprint small because anyway most of the 64 Gb part was empty to zip has done it’s trick but what if your friend has a  8 Gb card. You shouldn’t have started with a big card? Anyway cloning the whole card look very ugly to me (time factor is also there). ## How to cleanly clone a SD card? This is very simple I will explain it first then we will walk through a sample use case with all the commands. All the exercise is on Linux machine. #### Steps: 1. Insert the SD-card on Linux machine and get the device name e.g.  /dev/sdb sdb1 sdb2 2. Start Gparted and select your device from top.  sudo apt-get install gparted If you do not have this. I like using the GUI interface but if you are the bearded Unix man you can just use the parted command. 3. Shrink your partition with the graphical interface. You need to unmount the partitions if it is auto mounted. You can do this from the gparted UI itself by right clicking on the partition and selecting unmount. After the device is unmounted(all its partitions) you can select a partition and see the options of deleting the partition shrinking/resizing it. 4. gparted will automatically recognize the unused space with some margin and give you option to shrink it to that much space. shrink your partition and click save to apply it. This will take some time. 5. Now you have just sufficient amount of space for each partition unused area is mark unallocated now. We can now clone the SD-card as usual. 6. Just check the memory used via your favorite software/command then copy using dd  sudo dd if=/dev/sdb of=~/shrinked.img bs=1M count=2470 ### The way to it Now let us walk through an example with all the commands: :~$ sudo gparted

:~$sudo dd if=/dev/sdb of=~/myRaspberryPi.img bs=1M count=2470  :~$ sudo fdisk -l

Partition table entries are not in disk order

Disk /dev/sdb: 64.0 GB, 64021856256 bytes
64 heads, 32 sectors/track, 61056 cylinders, total 125042688 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00042380

Device Boot Start End Blocks Id System
/dev/sdb1 49152 131071 40960 83 Linux
/dev/sdb2 131072 5160959 2514944 83 Linux


You need this information to know the size you have to copy with dd command.
 :~$sudo dd if=/dev/sdb of=~/eyerisDvpCam.img bs=1M count=2470  2470+0 records in 2470+0 records out 2589982720 bytes (2.6 GB) copied, 82.9483 s, 31.2 MB/s  Do you know SD stands for Secure Digital? There are some open points like: • What if your partitions are not continuous? • What if there is a big unallocated space in the beginning of the sd-card? You can use skip with dd to reject the initial space I tried once didn’t worked for me got image was corrupted. May be I have done it incorrectly. Then you can also copy your partitions one by one and then create an image separately by joining them. command with skip  :~$ sudo dd if=/dev/sdb of=~/myCoolTvSkip.img bs=1M skip=23552 count=2444

2444+0 records in
2444+0 records out
2562719744 bytes (2.6 GB) copied, 107.389 s, 23.9 MB/s


This really is Future of television Open source entertainment

I am not a fan of news and television programs broadcasted in India so my tv was just lying there never being used. I had a spare CPU connected with tv but it wasn’t used extensively. You can watch movies tv-series on your laptop so why bother.

I was thinking about buying chromecast but wasn’t sure how helpful it is another option was Teewe. There are so many from chinese vendors (Allcast, MiraScreen, Anycast etc). I was weighing on which one to buy then I realize that I have a spare board which I ordered sometime back on aliexpress when I was experimenting with raspberry pi/cubieboard/beaglebone/odroid.

The board name is not important as you can use any of the boards you will find someway to run kodi. I realized there is a android lollipop image available for that board. Just took the micro-sdcard from my camera and flashed the image. It was okay fast. Downloaded some apps like netflix, hotstar, gaana, wynk music, google drive, one drive, youtube, tvf, Kodi etc. The option would have been to use Open-elec. That will be faster but android suited my purpose it had a familiar interface for everyone. Open-elec may scare some new friend using the television.

I was thinking of signing into netflix then I realized let me first try Kodi. I saw some youtube videos on how to add addons on kodi and boom. It was so simple to setup everything. with tvaddons my simple plain board which was useless has made my tv a smart useful piece of entertainment system. I can watch any movie, tv -series in no time. You name it and it is there. I tried some recently released movies and it is there.

No torrent required no wait for download etc. anyway now torrent sites are getting banned in India this will also get blocked someday but for now enjoy streaming from putlocker. primewire, alluc etc.

There is one more service which I liked most it is called Trakt.tv. This is really cool service for movies and tv-series watchlist. It is better than IMDB for this particular service. Since you can directly configure it with Kodi it will keep tracking what you are watching just like last.fm for movies/tv-series.
I like the web interface and the data they show. Example:

Even better:

Trakt.tv may be a cancer for privacy and for pirate users as the data is synced on their server and can be used/shared. Technically you can make your profile private by checking the box in your profile settings page.

If you open a movie or tv-series page you will get lot more user insight:

I generally used Exodus and for most of the time I am just satisfied with the service. I have other addons but I never feel any need to use them.