Wednesday, July 12, 2017

Disabling Some Argument In Shell Command (Linux)

To disable any shell command's argument, all you need to do is to add following code in any of the initialization script of your shell/terminal.
cats_dont_meaow() { 
  if [ $1 = "meaow"]; then
    echo "Cats don\'t meaow in parallel universe."
  else
    cat $*
  fi
}
alias cat=cats_dont_meaow
Thanks to https://cdn.meme.am/
Consider the application of the script in case you have cached your git credentials and you accidentally hit enter after randomly typing some keys that may become git push origin master. This function will save your gits (pun intended).
block_git_push() {
  if [ $1 = "push" ]; then
    echo "\"push\" is blocked temporarily to prevent volcano eruption."
  else
    git $*
  fi
}
alias git=block_git_push
Gist: https://gist.github.com/fahadsiddiqui/ecb81755ae19eb5add1fce17bf7c730a

Tuesday, July 11, 2017

Customize Your Linux Dude

How can you use Unity without any tweaking? Why don't you feel the need to change your desktop appearance? I think it is time for me to write something that can put a new cloth on your lets-not-touch-it-we'll-break-it OS. I know you fear. I know your fingers shake when you type sudo. I know you are a coward and think you will break something like apt-get or you will get like 374 error messages and 34 warnings next time you boot. Nothing is going to happen. Try these.

1. Numix
Numix is an open-source project having icon sets and appearances for Debian/Android for free. You can go to their website and install (its pretty straight forward). Just add their PPA
sudo add-apt-repository ppa:numix/ppa
For more information go to https://numixproject.org/.
To change the theme/appearance you must install some tweak tool first. I prefer unity-tweak-tool, easily available from default repository
sudo apt-get install unity-tweak-tool
You are good to go.

2. Hyper
Do you like the default terminal? That's okay. But I would suggest you to try Hyper once. Built on top of Electron (by Github) framework, Hyper provides you much customization. I mean who wouldn't want to watch a YouTube video on your BASH terminal just by pasting a YouTube link? Interesting? Okay, go for it then. https://hyper.is/
A word of advice, do install node package manager and node itself before installing plugins in your Hyper terminal. Hyper internally uses node.js to install its packages. It also has its own package manager named "hpm". Try these packages https://github.com/bnb/awesome-hyper.

3. Atom
I wouldn't suggest this if you are a geek. Sure you'd want VIM or EMACS. But if your pokemons are evolved, and you have heard of Sublime text, you should try Atom (by Github). Click https://atom.io/.

4. f.lux
Do your eyes feel tired working straight 8 hours a day? They should be, you are wasting them.
Try f.lux (https://justgetflux.com). The reason why I recommend everyone to use f.lux is the blue screen hazard. It blinds you over time. You should read the research over here https://justgetflux.com/research.html.
Installation instructions are pretty straight forward, you just have to install the application indicator and run some scripts. See https://github.com/xflux-gui/xflux-gui.
Another option for screen color temperature adjustment is redshift-gtk, but it sometimes goes too off while adjusting (too warm for eyes).

And for God sake, change the default wallpaper. Huh.

Tuesday, June 20, 2017

پرندے مر نہیں جاتے

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

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