Pages

Thursday, January 7, 2016

The inspiration that Seth Macfarlane is to me

From an article titled "Why do we still believe in Astrology":

...  the entire system does everything it can to remove us from being
present with our situation. Instead of dealing with our own
insecurities, fears and uncertainties, we turn to the cosmos for a
reason. And there is certainly no dearth of folk ready to offer one
up.

Perhaps the best response I’ve heard to this mindset was given by
actor/writer Seth Macfarlane last week. Having discussed the random
nature of the universe in his new show, ‘Cosmos: A Spacetime Odyssey,’
starring Neil deGrasse Tyson, Bill Maher asked him how he replies when
someone says to him, ‘You know, everything happens for a reason.’
Without missing a beat, Macfarlane replied,

This was not the coffee that I ordered!

http://bigthink.com/21st-century-spirituality/why-do-we-still-believe-in-astrology

Friday, May 1, 2015

Rename file in Sublime Text 3

To rename a file in Sublime Text 3, install the following package.

git@github.com:brianlow/FileRename.git

Clone the package:
git clone git@github.com:brianlow/FileRename.git

Copy the package in the following directory (OS X):
~/Library/Application Support/Sublime Text 3/Packages/User

Restart Sublime Text and press CMD+SHIFT+P. In the textbox type 'File Rename'. When the package is highlighted, press Enter. You will be able to rename the current file.



Tuesday, February 24, 2015

Testing with Ruby

To get started with Ruby testing, I am using RSpec ruby framework.
http://rspec.info/

To use RSpec, first you will need to have the gem "guard" which is a command line tool to work with RSpec.
$ gen install guard.

$ bundle exec guard list
This will give you a list of frameworks installed and ready for guard to work with.

After that run
$ bundle exec guard.

This will take you to the guard prompt . Do the following to run all tests.

$ guard(main)> all rspec.

You are up and running!

Ruby Installation

Introduction:

Assumes:
* You already have a Ruby project which you want to set up with little or no Ruby knowledge.
* You are on OS X.

I am off to learning Ruby for my new project. It makes me both excited and scared at the same time as I love learning new languages and tools but Ruby is a different beast than any I have tamed before. My understanding of Ruby leads me to believe that Ruby is:

1. A server side language.
2. Very different syntax than C, C++, and Java.
3. Is more than Ruby itself; there are gems and rails I don't know about.
4. It can be used to host apps on cloud servers like AWS.

It is a personal journey and like any other beginner, I am pretty sure the above four bullets will need to be modified once I develop more understanding.

Installing Ruby:

I have started by watching the following course videos:
https://onemonth.com/courses/one-month-rails

Installing Ruby using homebrew resulted in the installation of ruby 2.2.0p0 (2014-12-25 revision 49005). Turns out I need 2.1.5. So using the rbenv to make changes and install the specific version:
https://github.com/sstephenson/rbenv#installation

$ rbenv install 2.1.5

in ~/.bash_profile, add
export PATH="/Users/{home}/.rbenv/versions/2.1.5/bin/":$PATH
where {home} is your own user name.

$ rbenv rehash

$ eval "$(rbenv init -)"

$ gem install bundler

(Deviating but a necessary step is: $brew install qt; $brew linkapps qt) .

Run "$ bundle install" from your Ruby project folder in which "Gemfiles" exist.

Getting Postgres running:

Install Postgress.app from http://postgresapp.com/.

Use commands:

$ createuser -s -r postgres
$ rake db:create
$ rake db:migrate
to create and get the db running.

Install Pow.cx:
From http://pow.cx, install Pow.cx. This utility will get your Ruby server app running without setting up a whole lot of configuration. Just create a symlink to your app in .pow as mentioned on the page.

There you go. If you have symlinked your project to "myapp" you should be able to type http://myapp.dev in your browser and see your app running.



Thursday, August 7, 2014

Change the name of remote git branch

Warning: Reader is strongly encouraged to take a backup of the local repository before performing the steps mentioned in this post.

This post is intended to guide the reader about how to change the name of a remote branch in Github. Suppose there is a branch named feature/branch_a, and it is to be renamed to test/branch_a. The initial remote and local repositories may look something like this:

Remote:

enter image description here

Local:

enter image description here
* Command(s):
-  git branch -v (Shows a list of all branches, with current branch highlighted)

With the branch feature/branch_a checked out, create a new branch with the name test/branch_a.

enter image description here
* Command(s):
-  git branch -v (Shows a list of all branches, with current branch highlighted)
-  git checkout -b test/branch_a (Creates a new branch and at the same time switches to the branch)

Push the branch on the remote server, and then delete the older branch from both remote and local repositories.

enter image description here
* Command(s):
-  git push --set-upstream origin test/branch_a (link locally create branch to the remote server, and push it)
-  git push origin :feature/branch_a test/branch_a (Deletes branch from remote and replaces it with the new one)

That is it! You are good to go.

enter image description here

Enjoy!

Thursday, July 31, 2014

Use Jekyll to create a blog and host it on Github

Github is an attractive option for hosting a technical blog. The process is as simple as creating a repository, and adding index.html to it. Details can be looked up at https://pages.github.com/. Github uses Jekyll to generate the site. Jekyll is a simple, blog aware, static site generator. Using markup for the blog entries is one of the features of Jekyll. The installation can be done via gem ruby tool. http://jekyllrb.com/docs/quickstart/
Once installed, follow the following steps:
  • Clone the github page repository.
    git clone abc.github.io
  • Create a new file in the local git repository.
    touch Gemfile
  • Edit the file and put the following lines in it.
    source 'https://rubygems.org'
    gem 'github-pages'
  • Install Bundler http://bundler.io/
    gem install bundler
    bundle install
  • To run Jekyll with Bundler, issue the following command in the root repository.
    bundle exec jekyll serve
  • The site should now be available at:
    http://localhost:4000
More can be read about working with Jekyll at http://jekyllrb.com/docs/structure/. A very good example can be found at https://github.com/maciakl/Sample-Jekyll-Site/.

Wednesday, July 30, 2014

Fix INSTALL_FAILED_INSUFFICIENT_STORAGE while installing the Android App during development phase

On a device like Samsung Y Duos with only 160MB of internal memory, it is common that the app gets installed first time but when you reinstall the app, you get:

Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]

This is an annoyance when an IDE is being used to deploy and redeploy app while in development.

Usually the IDE does the following to install the package:

adb shell "pm install -r '/data/local/tmp/com.your.package'"

This results in the INSTALL_FAILED_INSUFFICIENT_STORAGE error if the app is already installed on the device. A simple solution to this is to uninstall the app first through command line (uninstalling does not work when using Application manager in phone's settings):

adb shell "pm uninstall com.your.package"

And once the app is uninstalled, then either do a command line install or let the IDE handle installation.

adb install YOUR_APK

Monday, July 21, 2014

Check Google Cloud Messaging (GCM) Client for Android using Curl

This post deals with testing a GCM Client without implementing a formal backend server. It uses the unix command line tool curl to send messages to the devices registered with GCM. Please note that this is not an end-to-end tutorial on how to implement GCM in your apps. If you want more information on the topic, please refer to http://developer.android.com/google/gcm/index.html.
You can run the following script on terminal to send messages to your test device.
curl -X POST \
-H "Authorization: key= YOUR_AUTHORIZATION_KEY" \
-H "Content-Type: application/json" \
-d '{
"registration_ids": [
"YOUR_DEVICE_TOKEN"
],
"data": {
"message": "YOUR_MESSAGE"
}
}' \
https://android.googleapis.com/gcm/send

YOUR_AUTHORIZATION_KEY:



YOUR_DEVICE_TOKEN: Token received when the client device registers with GCM server.

YOUR_MESSAGE: Message to send.

Happy messaging!

Monday, April 7, 2014

Grab Screenshot from Android device using Command line (adb)

The simple one liner will be:

adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

The above command:

1. Uses adb to grab the screenshot and sends binary data to stdout, which is then ...
2. ... appended to a file screen.jpg. The perl command in between converts CRLF to LF.

Source

Sunday, March 30, 2014

Using OSX keychain to store git credentials

On Mac if you have the latest version of git, you can use following command to tell git to use OS X keychain.

git config --global credential.helper osxkeychain

Note that the credential helper only works with HTTPS requests.

Wednesday, March 12, 2014

Updating git repo with changes in .gitignore

When .gitignore file is updated, the changes do not appear to take effect in the output of git status. Following set of commands will update git with the changes.

git rm -r --cached .
git add . --all
git commit -am "Updated .gitignore"

Note that these commands must be executed in your project root.


Friday, January 31, 2014

Fetching a remote git branch

The following command will update your local repo with remote changes.
$ git fetch --all

After that use the following command:
git checkout --track origin/the_branch


Deleting the last commit pushed to remote repo

Let's say that you have a repo called "origin" with a branch named "UK-December". In order to remove the last commit, follow these steps:

1. Get the commit history.

$git hist
* ef92aa4 2014-01-31 | pretty sure?
* e5d2440 2014-01-30 | Bitmap loading
* 954b23a 2014-01-30 | PRIO-40: fixed?
...

The commit we want to delete is ef92aa4

2. Use the following command to force git to rebase the UK-December repo to the parent of ef92aa4.

$git push origin +ef92aa4^:O2UK-December

Thats it. Your remote commit is gone!

Friday, January 3, 2014

Decorator Pattern Using Fortran

Structural design patterns deals with using existing classes. One of the structural pattern is Decorator. It acts as a wrapper to existing class object and adds functionality to it without changing the signature of the class. It attaches additional responsibilities to the object without modifying the class.

Following is an example of Decorator pattern implemented in Fortran:

GitHub - Decorator Pattern In Fortran
Fork

Wednesday, January 1, 2014

Criteria Design Pattern In Fortran

"Criteria" is a simple yet useful structural design pattern. It is applied in the cases where there are different types of object of the same class and it is a requirement to fetch objects of certain kinds. The criteria pattern helps defining a class hierarchy which makes applying any possible criteria for the objects trivial. Adding a criteria to the existing set of criteria is as simple as adding a class.

Following is an example in Fortran:

GitHub - Criteria Pattern
Fork

Saturday, December 28, 2013

The Composite Design Pattern In Fortran

The Composite design pattern is a structural design pattern which is used to group the objects of same type together and create hierarchies of objects. As an example consider a factory where "Manager" is an "Employee" but also has subordinates which are "List<Employee>" and in this way a tree structure for a group of "Employee" is created.

As an example following is an implementation in Fortran:

Github - Fortran implementation of Composite pattern
Fork

Friday, December 27, 2013

Bridge Design Pattern in Fortran

Bridge pattern is used to separate an implementation from its abstraction so that both may vary without any dependancy upon other. Due to this decoupling, the bridge pattern is classified as a structural pattern. All that is needed is to create an interface to act as a bridge to make the functionality of concrete classes independent of interface implementer.

Following is an example in Fortran:

GitHub - Bridge Pattern
Fork

Thursday, December 26, 2013

Adapter Pattern Implementation in Fortran

Sometimes the classes that need to work together do not have compatible interfaces. In that case, to make the two classes talk to each other, Adapter pattern is implemented. This pattern is a structural pattern as it combines the capabilities of two different interfaces. Think of it as a dvd player which acts as an adapter between the dvd and the television.

Following is an implementation in Fortran.

Github - Adapter Pattern
Fork

Wednesday, December 25, 2013

Prototype Design Pattern Implementation in Fortran

Although the modern systems have lots of computing power, there are some operations which still become a bottleneck. Disk I/O and database access being few of them. Prototype design pattern is a creational pattern which is used to duplicate/clone objects keeping performance in mind. For example, a system where disk I/O is expensive can reference the same pointer when creating different objects of the same class.

Following is an implementation of the pattern using Fortran:

Github - Prototype Pattern
Fork