Wednesday, 3 April 2019

Scale , Crop , Resize photos for OCI India

Current OCI photo requirements.

... the images must be in jpeg or jpg format, with max size 200kb.

The height and width of the Applicant Photo must be equal.
The minimum dimensions are 200 pixels (width) x 200 pixels (height).
The maximum dimensions are 900 pixels (width) x 900 pixels (height).

Use GIMP - free and brilliant tool on Ubuntu.

Step 1: Open the original photo. File --> Open

Step 2: Crop the Image. Tools --> Transform Tools --> Crop. Select the area of the photo such that height and width is same number of pixels i.e. aspect ration 1:1.

Step 3: Scale the Image. Tools --> Transform Tools --> Scale. Enter height and width as 900px. This will scale the selected photo to 900 by 900 px. 

Step 4: Change the canvas to the layer size. Image --> Fit canvas to Layers.

Step 5: Export the resultant image. File --> Export --> select jpeg , jpg. 

Step 6: Select "Show preview in image window" so that File size is visible. Adjust Quality so that the file size remains under 200Kb.

Monday, 24 December 2018

Share internet with Sky box (not Q) over ethernet from raspberry pi connected to internet via WLAN0.

Moved house. Have old sky box with no WiFi.
Raspberry pi USB WiFi cost couple of bucks just besides sky box able to access internet.

So aim is to share the internet with Sky box. So connected the Sky box to Pi with ethernet cable.

On Raspberry pi:

  • Edit /etc/dhcpcd.conf to add following. IP address for WLAN0 is not one of the following.


interface eth0
static ip_address=192.168.2.1
static routers=192.168.2.255
static domain_name_servers=8.8.8.8

  • Install dnsmasq. Edit /etc/dnsmasq.conf to add the following lines.

interface=eth0 # Use interface eth0 
listen-address=192.168.2.1 # listen on 
# Bind to the interface to make sure we aren't sending things
# elsewhere 
bind-interfaces 
server=8.8.8.8 # Forward DNS requests to Google DNS domain-needed # Don't forward short names # Never forward addresses in the non-routed address spaces. 
bogus-priv
# Assign IP addresses between 192.168.2.2 and 192.168.2.100 with a # 12 hour lease time 
dhcp-range=192.168.2.2,192.168.2.100,12h


  • Edit /etc/sysctl.conf to forward ipv4.
  • Restart. Make sure the WLAN0 interface has the ip address from the configured IP range.
  • Forward the ports.
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

  • Restart

Tuesday, 26 September 2017

Sharing Wireless internet connection on a PC running Ubuntu with the Raspberry pi connected to the PC via Ethernet cable

Sharing Wireless internet connection on a PC running Ubuntu with the Raspberry pi connected to the PC via Ethernet cable.


Laptop running Ubuntu.

Laptop connected to Internet via Wireless LAN.

Raspberry pi and Laptop connected using a ethernet cable. (Cable used to connect a PC to wired LAN. Not a special cable)

Raspberry pi running - RASPBIAN STRETCH LITE (Minimal image based on Debian Stretch)

Steps:

Raspberry pi

1. Enable ssh on raspberry pi. Google for the instructions depending on if you boot headless or have connected the pi with any input (keyboard) / output (TV / Monitor) device.
2. Confirm that DHCP client is running on Raspberry pi. By default the RASPBIAN STRETCH LITE has DHCP client running / listening on ethernet port.

Laptop

3. Install DHCP server.
$ sudo apt-get install isc-dhcp-server

4. Update the DHCP configuration with the IP range of your choice for your pi and laptop network.  Change the file mentioned below. Will need root access on Laptop.
$ cat /etc/dhcp/dhcpd.conf
subnet 17.1.10.0 netmask 255.255.255.224 { *****Network subnet *****
  range 17.1.10.3 17.1.10.30; *****Range of IP address that will be allocated by DHCP*****
  option domain-name-servers 208.67.222.222; *****Open DNS server*****
  option subnet-mask 255.255.255.224;
  option routers 17.1.10.1; *****IP address for the Laptop*****
  option broadcast-address 17.1.10.31;
  default-lease-time 600;
  max-lease-time 7200;
}

5. Set DHCP server to serve requests on the ethernet interface (device). Change the file mentioned below. Will need root access on Laptop.
$ cat /etc/default/isc-dhcp-server
INTERFACES="eth0"

UPDATE-
ON UBUNTU the if command does not work anymore. In order to assign a static IP address use the following--

Helpful names of the kernal interfaces like eth* have changed!!!

Following shows the entwork hardware and new names.
$sudo lshw -class network

$sudo ip addr add 17.1.10.1/24 dev enp0s25

If a static could not be assigned to laptop, the DHCP server deamon fails with error 

"No subnet declaration for <ethernet device> (no IPv4 addresses)."

The ethernet device is mentioned in the /etc/default/isc-dhcp-server. This file should have the appropriate name as per Ubuntu!

6. Set static IP.
$ cat /etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet static 
address 17.1.10.1
netmask 255.255.255.0

UPDATE-
ON UBUNTU the if command does not work anymore. In order to assign a static IP address use the following--

Helpful names of the kernal interfaces like eth* have changed!!!

Following shows the entwork hardware and new names.
$sudo lshw -class network

$sudo ip addr add 17.1.10.1/24 dev enp0s25

If a static could not be assigned to laptop, the DHCP server deamon fails with error 

"No subnet declaration for <ethernet device> (no IPv4 addresses)."

The ethernet device is mentioned in the /etc/default/isc-dhcp-server. This file should have the appropriate name as per Ubuntu!

7. Set IP address forward.
$sudo sysctl net.ipv4.ip_forward=1

8. Set IP forwarding in IPTables.
$sudo /sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
$sudo /sbin/iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$sudo /sbin/iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

Set up wise thats it.

Commands to - 
Check IP address assigned to pi.
laptop$ nmap -sP 17.1.10.1/29

SSH to pi.
laptop$ ssh pi@<Ip address for the pi>

Check the route on pi or on laptop
laptop$ ip route

Check if domain resolution works fine.
pi$ ping www.google.com

Check the route to internet
pi$ traceroute www.google.com

Sunday, 9 July 2017

Ubuntu Wifi from command prompt.

List the available networks.

$nmcli device wifi list

Command to connect to a Wifi.

$nmcli device wifi connect password

Saturday, 29 October 2016

Tabla (Treetaal / Teentaal) Live coding on Sonic Pi.


Tabla Live coding on Sonic Pi.

  1. Download Sonic PI software by googling for it.
  2. Install Sonic PI. I've done this on a Windows machine. Linux installs on my laptops were going to need more work to make the software work so decided to do it on Windows.
  3. Make sure the tabla samples are available. Try typing "sample :tabla" you should see the auto fill for the tabla bol. If you do you have the tabla samples otherwise not.
  4. Created the following code for the Lehra sath in Raag Bhinna Shadaj and the very preliminary kayda in Treetal.
  5. Copy the following in the buffer and play.
  6. Watch it on Youtube -- here --.
  7. Did you ever think these two skills will come together?

#Treetal using Sonic PI
#Rajendra Sathe

#use_bpm 128
thamb1 = 0.250
x = -10

use_synth :piano

live_loop :lehra do
  raag_bhinna_shadja_lehra_1
end

live_loop :kayda do
  sync :lehra
  1.times do
   treetal
  end
  treetal_dha_dha_tee_tuu_kayda
end



#==========Definitions Start=================#
define :z1 do
  sleep thamb1
end

define :z2 do
  sleep thamb1 / 2
end

define :dha do
  sample :tabla_na
  sample :tabla_ghe1
end

define :dhin do
  sample :tabla_tas1
  sample :tabla_ghe3
end

define :ta do
  sample :tabla_na
end

define :tin do
  sample :tabla_tas1
  sample :tabla_ke1
end

define :tee do
  sample :tabla_te1
end

define :tuu do
  sample :tabla_tas1
end

define :too do
  sample :tabla_tas2
end

define :na do
  sample :tabla_na
end

define :treetal do
  2.times do
    dha
    sleep thamb1
    dhin
    sleep thamb1
    dhin
    sleep thamb1
    dha
    sleep thamb1
  end
  1.times do
    dha
    sleep thamb1
    tin
    sleep thamb1
    tin
    sleep thamb1
    ta
    sleep thamb1
  end
  1.times do
    ta
    sleep thamb1
    dhin
    sleep thamb1
    dhin
    sleep thamb1
    dha
    sleep thamb1
  end
end

define :raag_bhinna_shadja_lehra_1 do
  play 60 + x , sustain: 3, amp: 1.5
  #play 62, sustain: 3, amp: 1.5
  z1
  play 64 + x , sustain: 3, amp: 0.5
  z1
  play 65 + x , sustain: 3, amp: 0.5
  z1
  play 69 + x , sustain: 3, amp: 0.5
  z1
  play 65 + x , sustain: 3, amp: 0.5
  z1
  play 69 + x , sustain: 3, amp: 0.5
  z1
  play 71 + x, sustain: 3, amp: 0.5
  z1
  play 72 + x, sustain: 3, amp: 0.5
  z1
  play 71 + x, sustain: 3, amp: 0.5
  z1
  play 69 + x, sustain: 3, amp: 0.5
  z1
  play 65 + x, sustain: 3, amp: 0.5
  z1
  play 64 + x, sustain: 3, amp: 0.5
  z1
  play 69 + x, sustain: 3, amp: 0.5
  z1
  play 65 + x, sustain: 3, amp: 0.5
  z1
  play 64 + x, sustain: 3, amp: 0.5
  z1
  play 60 + x, sustain: 3, amp: 0.5
  z1
end



define :treetal_dha_dha_tee_tuu_kayda do
  dha
  z1
  dha
  z1
  tee
  z1
  tuu
  z1
  
  dha
  z1
  dha
  z1
  too
  z1
  na
  z1
  
  ta
  z1
  ta
  z1
  tee
  z1
  tuu
  z1
  
  dha
  z1
  dha
  z1
  dhin
  z1
  na
  z1
  #============================#
  2.times do
    dha
    z2
    dha
    z2
    tee
    z2
    tuu
    z2
    
    dha
    z2
    dha
    z2
    too
    z2
    na
    z2
    
    ta
    z2
    ta
    z2
    tee
    z2
    tuu
    z2
    
    dha
    z2
    dha
    z2
    dhin
    z2
    na
    z2
  end
  #============================#
  #========palta 1 ==start=====#
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  too
  z2
  na
  z2
  
  ta
  z2
  ta
  z2
  tee
  z2
  tuu
  z2
  
  ta
  z2
  ta
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  dhin
  z2
  na
  z2
  #========palta 1 ==end=====#
  
  #========palta 2 ==start=====#
  dha
  z2
  dha
  z2
  dha
  z2
  dha
  z2
  
  tee
  z2
  tuu
  z2
  dha
  z2
  dha
  z2
  
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  too
  z2
  na
  z2
  
  ta
  z2
  ta
  z2
  ta
  z2
  ta
  z2
  
  tee
  z2
  tuu
  z2
  ta
  z2
  ta
  z2
  
  ta
  z2
  ta
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  dhin
  z2
  na
  z2
  #========palta 2 ==end=====#
  
  #========palta 3==start=====#
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  z2
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  too
  z2
  na
  z2
  
  ta
  z2
  ta
  z2
  tee
  z2
  tuu
  z2
  
  z2
  z2
  tee
  z2
  tuu
  z2
  
  ta
  z2
  ta
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  dhin
  z2
  na
  z2
  #========palta 3 ==end=====#
  
  
  #========Tihaee ==start=====#
  2.times do
    dha
    z2
    dha
    z2
    tee
    z2
    tuu
    z2
    
    dha
    z2
    dha
    z2
    too
    z2
    na
    z2
    
    dha
    z2
    z2
    z2
    z2
  end
  dha
  z2
  dha
  z2
  tee
  z2
  tuu
  z2
  
  dha
  z2
  dha
  z2
  too
  z2
  na
  z2
  #========Tihaee ==start=====#
end

Friday, 20 November 2015

Mount iPhone onto Ubuntu

1. Prerequisite - Install ifuse

2. Connect the iPhone  to the computer using USB.

3. Click Allow / Trust on the iPhone when asked to Allow access or Trust the computer.

4. Following command will display the information about all devices connected to the computer through the USB. The information of our interest is the "Serial number".

$usb-devices

T:  Bus=02 Lev=01 Prnt=01 Port=03 Cnt=01 Dev#=  2 Spd=480 MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  4
P:  Vendor=xyz ProdID=xyz Rev=xyz
S:  Manufacturer=Apple Inc.
S:  Product=iPhone
S:  SerialNumber=
C:  #Ifs= 3 Cfg#= 4 Atr=c0 MxPwr=500mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=06(still) Sub=01 Prot=01 Driver=(none)
I:  If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=fe Prot=02 Driver=usbfs
I:  If#= 2 Alt= 1 #EPs= 2 Cls=ff(vend.) Sub=fd Prot=01 Driver=iphe

5. Create a directory - mount point for the iPhone.
$mkdir /media/iPhone

6. Now mount the iphone using the following
$sudo ifuse /media/iPhone/ -u -o rw,allow_other

7. All done. List, copy files from iPhone.
$ls /media/iPhone/


Wednesday, 6 May 2015

Turning on Sony Bravia TV from a computer terminal

Sony Bravia TV allows one to wake it up using (WoL) Wake On LAN. Look for settings on your respective models.

$ sudo apt install wakeonlan 

wakeonlan is a script/utility which allows sending magic packets to networked devices which allow WoL.

The IP address can be found from modem admin utility which also shows the mac address for the TV.

Following command will turn the TV on.

$ wakeonlan -i "IP address of the TV" "Mac address of the TV"