Wednesday, February 06, 2013

Tethering speeds with Three on Android

Just purchased myself the £25 monthly contract plan with Three which apart from 2000 minutes in calls and 5000 text messages, it allows me to perform tethering on my android device. To be fair with you guys I was in a quick need of an Internet connection so this sounded like great value for money... I was told that BT sells broadband internet for roughly the same price (but of course no calls/texts/etc) and would be bound by an 18 month contract - a royal ripoff if you may ask.

Would love to ask any geek who may be reading this whether he has any experience with trying to tether on non-allowed (ONE) plans? And I am really asking for the sake of an educational research and not to be a digital cowboy.



I have also noticed that tethering speeds really depend on the location of the mobile device - in my case, placing the Android near the window managed to triple the connection speed as can be seen in the screenshot above. I am quite happy with the results especially since this is an all you can eat data plan!

Update: I noticed that the default apn three.co.uk provided erratic results and a couple of minutes after publishing this article I was getting disconnected from the internet, or suffering from slow connections or even getting blocked on certain websites! I changed the APN to 3internet instead of three.co.uk and now I have better speed, more reliable connection and most of all, uncensored browsing:


Also I am pretty sure that once I charge the battery I get better results! Additionally if you set data connection to WCDMA (rather than auto which allows android to flip between GSM and UMTS) results in better ping and lower latencies (evident from resolving a website address):


Remember that for 3G, the maximum theoretical speed is 5Mb/s so I am getting pretty close! If you still have problems, before contacting your mobile phone operator try to remove wi-fi encryption and set it as an open network:



Additionally I am trying to look for an app for my Android ICS (4.0) which hides the SSID when I configure the mobile as a personal hotspot... Let me know if you are aware of one!

Monday, February 04, 2013

Github primer - pushing code remotely

Someone has recently asked me to give him a no-brainer procedure to push a git repository onto github. So here it is for everyone's convenience...



Assuming you have created a repo on your Github account, let's say you want to commit all your Ruby projects:

james@ebony ~/dev/ruby $ git init
Initialized empty Git repository in /home/james/dev/ruby/.git/
james@ebony ~/dev/ruby $ touch README
james@ebony ~/dev/ruby $ git add README
james@ebony ~/dev/ruby $ git add TaxCalculator/TaxCalculator.rb
james@ebony ~/dev/ruby $ git commit -m 'first commit'
[master (root-commit) a97909f] first commit
 1 file changed, 103 insertions(+)
 create mode 100644 README
 create mode 100755 TaxCalculator/TaxCalculator.rb
james@ebony ~/dev/ruby $ git remote add origin https://github.com/jamesattard/ruby.git
james@ebony ~/dev/ruby $ git push origin master
Username for 'https://github.com': jamesattard
Password for 'https://jamesattard@github.com': 
To https://github.com/jamesattard/ruby.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/jamesattard/ruby.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
james@ebony ~/dev/ruby $ git pull origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://github.com/jamesattard/ruby
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md |    2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md
james@ebony ~/dev/ruby $ git push origin master
Username for 'https://github.com': jamesattard
Password for 'https://jamesattard@github.com': 
To https://github.com/jamesattard/ruby.git
   2de0c70..c96770d  master -> master
james@ebony ~/dev/ruby $ ls
README  README.md  TaxCalculator
james@ebony ~/dev/ruby $ git rm README.md
rm 'README.md'
james@ebony ~/dev/ruby $ ls
README  TaxCalculator
james@ebony ~/dev/ruby $ git commit -m 'remove old README.md'
[master 1cf431a] remove old README.md
 1 file changed, 2 deletions(-)
 delete mode 100644 README.md
james@ebony ~/dev/ruby $ git push origin master
Username for 'https://github.com': jamesattard
Password for 'https://jamesattard@github.com': 
To https://github.com/jamesattard/ruby.git
   c96770d..1cf431a  master -> master

Follow the above procedure, note some common errors and also what you need to do if you want to remove a file from the repo the correct way.

OOP in Ruby - UK Income Tax Calculator

Today I wanted to learn more about OOP and do some actual coding. I started with a procedural paradigm and then recoded to OOP and learn from it. I wrote a very simple program in Ruby which calculates income tax in UK (very original!! hehe). I decided to use three objects....but can you come up with something different?

#!/usr/bin/env ruby

class Employee

 attr_reader :salary, :type, :taxtotal

 def initialize( salary, type )
  @salary = salary
  @type = type
 end

 def computetaxbands
  case type  # current tax rates are the same for single and married persons
  when 1
   bandA = 2790
   bandB = 32010
   bandC = 150000
   rateA = 0.1
   rateB = 0.2
   rateC = 0.4
   rateD = 0.5
  end
  
  case salary
  when 0..bandA
   calctax( IncomeTaxBand.new( salary, rateA ) )
  when bandA+1..bandB
   calctax( IncomeTaxBand.new( salary, rateB ) )
  when bandB+1..bandC
   calctax( IncomeTaxBand.new( bandB, rateB ), IncomeTaxBand.new( salary - bandB, rateC ) )
  else
   calctax( IncomeTaxBand.new( bandB, rateB ), IncomeTaxBand.new( bandC, rateC ), IncomeTaxBand.new( salary - bandC, rateD )  )
  end
  
 end

 def calctax( *taxbands ) #taxbands is an array of IncomeTaxBand objects
  @taxtotal = 0
  taxband_inst = taxbands
  taxbands.each { | taxband_inst | @taxtotal += taxband_inst.tax }
 end
 
end

class IncomeTaxBand
 
 attr_reader :tax
 
 def initialize( amount, pct )
  @tax = amount * pct
 end

end

class TaxViewer

 def inputvalid?(salary)
  if (salary.respond_to?(:match) && salary.match(/\d/))
   true
  else
   false
  end
 end 
 
 def annual(salary, tax)
  netannual = (salary - tax).round  
 end
 
 def monthly(salary, tax)
  netmonthly = ((salary - tax) / 12).round
 end
 
 def weekly(salary, tax)
  netweekly = ((salary - tax) / 52).round
 end

end

puts "UK Income tax calculator (2013-2014):\n\n"
loop do

 viewer = TaxViewer.new
 print "Please enter your gross annual Salary: £"
 salary = gets.chomp

 if viewer.inputvalid? salary

  emp = Employee.new(salary.to_i, 1)
  emp.computetaxbands

  printf "Total Tax: £%d\n", emp.taxtotal
  printf "Net Salary: £%d\n", viewer.annual(salary.to_i, emp.taxtotal)
  printf "Net Month: £%d\n", viewer.monthly(salary.to_i, emp.taxtotal)
  printf "Net Week: £%d\n", viewer.weekly(salary.to_i, emp.taxtotal) 
  break
 else
  print "\nPlease enter a valid number!\n\n"
 end

end


You can pull this code from Github for easier readability - please note that I am using 3 Classes -
1. Employee - reflecting a real world object
2. IncomeTaxBand - another real world object
3. TaxViewer - since Ruby encourages MVC, any viewer methods can be placed as an object too

This post is by no means any guide or tutorial - but if you need to ask me any queries please do. What I wanted to illustrate is an example of how a simple program which I personally used to undertake in a procedural approach in Bash or Perl in the past, can be made as OOP. The advantages of this design are too many to mention although some people might think it looks overbloated or complex.

Sunday, February 03, 2013

Malta song for Europe and the art of plagiarizing

If we Maltese are not good for anything, we are so good in plagiarizing music that we fool entire nations. Take a tried and tested song from the past, change the lyrics (unless you're Klinsmann and don't even bother!), and drop the key by a few tonal intervals to adjust the melody to your not well developed vocal range. Take a look at the following clips of the Maltese winners of the past two editions (2012, 2013) alongside with the 'what I think where plagiarized from' and judge by yourselves:


2012 Edition: 

Alexandra Stan - Get Back ASAP (Original): 


Kurt Calleja - This is the night (Maltese winner): 




2013 Edition: 

Train - Soul Sisters (Original): 


Gianluca Bezzina - Tomorrow (Maltese winner): 



And for the simpletons who say that 'they just share the same style'...there are 7 basic notes and 120 pitch sounds in music with an infinite number of intervallic possibilities to choose from.