Sunday, 21 December 2014

Android Quickies

With the amount of free time I "apparently" have on my hands, I have finally been able to dabble more into android programming. This blog will be a collection of some short lines which I have found useful.

Updating an ArrayAdapter for a list view


            ArrayList newData = new ArrayList(Arrays.asList(jsonString));
            myData.clear();
            myData.addAll(newData);
            myArrayAdapter.notifyDataSetChanged();
And that takes care of that!


ACTION BAR IN SETTINGS ACTIVITY

Typically, Settings activity extends a Preference Activity. However, for easy addition of the action bar, activities extend the ActionBar activity. You cannot extend more than one class in Java which means that if you are using the Preference activity method you will have to find a hack to hook up the action bar to your Settings activity. There a few workarounds.

If you are targeting android 3.0 and above (quite frankly, I see very little reason why you would be targeting anything less) then you should use PreferenceFragments and attach it to an activity which extends ActionBar activity. A description is given here in the android Docs.

If you are still bent on supporting other devices,..., well I have not figured that out yet. When I do will let you know. If you have please do post a comment.

Wednesday, 17 December 2014

Helpful Linux Terminal Commands

Okay, so I would be compiling a list of helpful linux commands for getting you out of that jam in no time.

REPAIRING A CORRUPT ZIP FILE

You have downloaded a large zip file, with possibly several files in the archive but your Internet connection decides to mess up at the last minute and so a few files at the end have not been downloaded. As a result, there is an end of file (EOF) error and you would have to start all over again.

Well with a simple command you can at least get the files which were completely downloaded with this command:

zip -FF Corrupted.zip --out New.zip
and now you can extract em, good luck!


INSTALLING A .deb FILE FROM COMMAND PROMPT


sudo dpkg -i "file"

CHECKING YOUR FORMATTED DISK SPACE

df -h

RUNNING A COMMAND AS ANOTHER USER (SOURCE)

sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"' 

Sunday, 14 December 2014

Setting Up VIM for Python Code Testing

Hello guys,

So I have got a bit more time on my hands which would mean that I can be doing this alot more often.

I will quickly show how to set up auto-complete features for python on the vi editor in Linux (I am running Ubuntu Gnome 14.04).

First things,

Get Vundle (It's a package manager for vim). The link is here. Follow all the instructions on the page, it is quite detailed.

Next up, head over to the github site here and add this to the .vimrc file and then add it to the plug-ins to be installed. And that is all.

Thank you!