Wednesday, May 31, 2017

دنیا خواب سی ہو جاتی ہے

پیارے بابا عرصہ پہلے
تم نے مجھ سے پوچھا تھا
"بیٹا تم کیوں جاگ رہی ہو؟"
رات کی چادر اوڑھے دیکھو
سب کی آنکھ مے نیند ہے بیٹا
"تم کیوں نیند سے بھاگ رہی ہو؟"
اتنا سن کر
کالے بادل
رات اندھیری
پھر بھی تیری بات سے میری
آنکھیں بند سی ہو جاتی تھیں
بابا تیری پیاری بیٹی
گھوڑے بچ کے سو جاتی تھی
عرصہ گزرا
بابا اب وہ
نیند کی چادر
روز ہی رات کو کھو جاتی ہے
ساری دنیا سو جاتی ہے
بابا نیند سے پہلے میری
دنیا خواب سی ہو جاتی ہے
بابا میری
دنیا خواب سی ہو جاتی ہے
(فہد صدیقی)

Thursday, December 8, 2016

Clean Up Your Git Mess - 1

1. Want to stash uncommitted changes
git stash
2. No, the changes are not tracked (untracked changes)
git add . # all the changes in ./ directory (pwd)
git stash # now do this
3. Want to undo the last stash
git stash pop
4. Again?
git stash pop # its a stack, you got the idea
5. Want to clear the stack
git stash clear
6. Want to know more about stash? https://git-scm.com/docs/git-stash
7. You type password every time you need to push something on remote ref. It sucks.
git config --global credential.helper cache
8. Revert local head upto last nth commit
git reset --hard HEAD~nth
9. Take remote head to some commit because all the commits after this particular commit are wrong?
git push origin +:

Thursday, January 28, 2016

Scala Getter/Setter and BeanProperties

Scala provides automatic getter/setter functions for class data members After compiling this piece of code using Scala compiler scalac
scalac Foo.scala
Generates Foo.class file which we can disassemble using Java class file disassembler program javap https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javap.html
javap -private Foo.class
Disassembling class file shows
public class Foo {
  private int foo;
  public int foo();
  public void foo_$eq(int);
  public Foo();
}
Here we can see int foo() returns foo value and foo_$eq(int) assigns the value to private int foo (works like a setter). Which means we do not have to define private data member, getter and setter explicitly like;
private var _foo: Int = _
def foo_=(foo: Int) = _foo = foo    // setter
def foo = _foo    // getter
Instead, we can only declare
var foo: Int = _
On the other hand, Scala provides an annotation @BeanProperty which you can use to declare automatic getter/setter functions. To define a data member as a bean property you just have to write @BeanProperty before declaring member variable
import scala.reflect.BeanProperty
@BeanProperty var foo: Int = _
This should be implemented when you call Scala code from Java. Java libraries and APIs expect a class getter/setter function names as getMember/setMember. @BeanProperty generates these getter/setter functions too. That is why it is feasible to use @BeanProperty instead of simple public variable declaration when intermixing Java with Scala.

Monday, January 25, 2016

Playing with Scala - 1

Being a programmer, whats point in not learning a language that is a bit complex than others?

Being Scala developer from almost 4 months now. I admire its compact logic building and strong syntactical shortcuts. I didn't dive much into its functional part, but I would like to share some of it also.
  1. It has so many flavors; programmers having background in C, C++, Java, Python get easily familiar with its syntax
  2. Object-oriented functional language; unlike Haskell and LISP - that are purely functional and Java - that is purely object oriented language, Scala is everything! All in one
  3. Salient features of Scala are nicely described here http://www.scala-lang.org/what-is-scala.html
  4. Runs on JVM so Java classes in Scala can be freely mixed
  5. Highly scalable; works from your desktop PC to a thousand nodes cluster i-e; Intel, Twitter and LinkedIn use Scala in their clusters
  6. Unlike Kotlin and Ceylon programming languages, Scala decided to make "better Java" instead of staying close to Java and ultimately improving almost nothing in it except syntactic sugar

Monday, January 11, 2016

A Few Lessons Learned From 2015

I tried to sum up my mistakes I did last year. Some of them were pretty dumb, others made me embarrassed to the point I took decision to never repeat them ever. Some of them made me proud. Some of them made me think what do I have to be proud of? Some of the key points, I learned, are mentioned below;
  1. Being yourself doesn't hurt you
  2. Hurting people hurts you eventually
  3. Don't sleep too much
  4. Productivity increases late-night (after 1am)
  5. Trustworthy people never ask you to trust them
  6. People who want to be in your life wouldn't stay shut about it
  7. Don't focus on peoples' interests more than you feel like you should
  8. Work quietly and let your work speak
  9. Read books in isolation and feel them
  10. Stay sharp and ready for attacks other frame for you
  11. Don't get framed in others' problems, be smart to judge your surroundings
  12. Don't offer to help if you can't do it honestly
  13. Don't listen to those who want to be listened and never listen to you
  14. Don't be gender biased in public or group talks
  15. Select a few words and make up your wit-dictionary and use it over and over again till you make habit of staying away from slang
  16. Dislike what you don't like but never dislike what others want you to dislike. There is always something beneficial for you what others suggest you to dislike
  17. Don't talk unless you have a strong reason
  18. Don't change yourself to comfort others

Thursday, December 10, 2015

CSV Reading Error (Python)

Just encountered a very ambiguous error in Python while reading a .csv file using the csv library in Python.

The solution made me feel pretty dumb. That is why I am blogging this to remember. From: https://docs.python.org/2/library/csv.html This is the code snippet I was trying to execute to read csv file at path /home/superuser/Desktop/day.csv.
import csv
with open('./day.csv', 'rb') as csvfile:
  r = csv.reader(csvfile, delimiter=' ', quotechar='|')
  for row in r:
    print ', '.join(row)
Python shell was showing error,
AttributeError: 'module' object has no attribute 'read'
Which made me thing that I'm importing wrong csv library. May be this import csv isn't importing the correct CSV I need. I was correct.
But the solution was pretty awkward. I was saving my file as "csv.py" and my program "csv.py" itself was importing itself.
Renaming the script to some other name resolved this issue.
Thanks to bernie's answer here:
http://stackoverflow.com/questions/9711799/csv-module-attributeerror

Thursday, December 3, 2015

Raspbian on Raspberry Pi 2

Following are the steps you need to know before installation of Raspbian - a distribution of Linux for Raspberry Pi 2.
  1. Download image of Raspbian from https://www.raspberrypi.org/downloads/
  2. Linux
    If you are using Linux/Unix, you need to burn (copy contents from) this image file (.img) into the SD card using following sequence of commands,

    df -h

    To check the list of all the drives mounted into system. Figure out from this list what is the name of your device mounted into /dev/device_name. This device name usually ends with p0, p1 and so on, which indicates the partition indexing. Make sure your card has one partition, at the time of installation and configuration of Raspbian, it automatically partitions into necessary parts.

    Easiest way to figure out what is the newly mounted SD card name in /dev/*, simply df -h before mounting SD card into PC, and then plug and find the newly plugged entry record from df -h output.

    Make sure you unmount the card before burning image into it, by using

    umount /dev/

    Run following command

    sudo dd bs=1M if=[DISK IMAGE NAME] of=[FILESYSTEM]


    Here, in bs=1M means the size of read and write of the bytes at a time equals to 1 mega. Sometimes 1M works while burning the SD card. If this doesn't work for your SD card, try using 4M or some other sector size.
    Wait for a while and your card will be burned with OS.

    Windows
    Use Win32 Disk Imager software to burn the SD card .img.
  3. Plug SD card into Raspberry Pi and plug it to 5V power, plug LED on HDMI port, keyboard and mouse on USB ports
  4. You will be logged in to Raspbian
    Default username password combination is pi and raspberry respectively
  5. You can expand storage by using raspi-config on terminal after you log in to LDX