Tuesday, January 8, 2019

Google Colab setup for fast.ai Deep learning course

For past few days I have been trying to setup Google Colab to run fast.ai lesson files.
Found multiple post on the same but  I was getting some or other error.

So here is the code which worked for me, I know there is latest version of fast.ai, but I wasn't able to make it work with that. 
Here the code is based on fastai version 0.7.


I am unable to mention the author of the original post, as I was trying multiple combination at the time. If you are able to find, please comment, I will update my post with proper citation.


PS: sometimes Google colab throws random error, so I will suggest to reset all runtime and then run again

Thursday, February 15, 2018

Rename Domain Computer using Powershell Script

As name suggests, powershell is very powerful way to automate pretty much all the things in windows.

If you want to rename your computer using power shell script where your computer is part of domain. Here is the the simple set of commands to do it :

1. $user = 'DOMAIN-NAME\USER-NAME'
2. $password = 'PASSWORD'|ConvertTo-SecureString -AsPlainText -force
3. $cred = New-Object System.Management.Automation.PSCredential $user,$password
4. Rename-Computer -ComputerName CURRENT-COMPUTER-NAME -NewName NEW_COMPUTER-NAME -domaincredential $cred

After that you need to restart the computer for changes to take effect.

Hope it helps !!

Saturday, February 6, 2016

C++ Graph class Implementation : Without any STL package

Hi All,

Please find the implementation for Graph class in C++ without using any STL reference.
Let me know if you find any issues with it.

Header file.


Cpp file:



Happy Coding !!

Wednesday, November 18, 2015

Parse.com Android : Common Issues faced

If you have just started in the world of BASS service, you might have chosen Parse.com.
Although it has good tutorial for explaining things, still I think community support is not very good.
I also had hard time to try basic things. So let me share a complete tutorial for extracting some data from Parse.com. It will be more towards covering the known issues.

Step 1: Uploading Data
In Tutorial provided by Parse, they talked how you can create a ParseObject, and upload the data by putting.You can follow the Guide provided by Parse to do that. I instead use Import Data option in Data Browser. So create a Json file and upload it there. If you are facing any issue with uploading, like it should be in that particular format, I will suggest to download any existing Table such as User, and open the JSON file. Similar way you can do it. Remember the first name should be "results" only, otherwise it wont let you upload.

Step 2: Creating a subclass of ParseObject
Although you can use normal ParseObject class do that, I will suggest you to use your own customized subclass of ParseObject.
a) Use @ParseClassName("YOUR_CLASS_NAME")  annotation.
b) Keep the file name, class name and Table Name same.
c) There should be default constructor of your customized sub-class.
d) Create set/get method for your fields in the table.

Step3: Registering the subclass
In your Application class's onCreate() method: add this line before calling Parse.initialize() :
ParseObject.registerSubclass(YOUR_CLASS_NAME.class);

Step4: Query using the subclass
 ParseQuery query = Alert.getQuery();
query.findInBackground(); //see the last link to get the full code.

Step5: Manifest changes
a) Please make sure you have defined the name field in tag in AndroidManifest.xml. Better use the complete path.
b) Add android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE permission.

I think this covers pretty much all the points.  Let me know if you face any issues with it. Sorry for lousy writing.
Here is link for all code.



Wednesday, November 4, 2015

Unable to add Google Play Service or Appcompat library project

It has been very long since I wrote any post about Android. So I will try now to continue the writing.

If you have left Android for some time and now starting over again. You might observe that Google is no longer providing ADT (Android Development Tool) bundle. Now the new tool is Android Studio. Although it has all the related tools at one place, but it is slow and little bit hard to start with.

So here is the guide for using old ADT.
Download the last ADT bundle. I am using adt-bundle-windows-x86_64-20140702.
You will find that it doesnt have Google Play Services project. To install it:
1. Go to Sdk Manager. Its there in the same zip file of adt bundle.
2. Refresh the list, in last checkbox named Extras: you can see one sub-item Google Play Services.
3. Check it and install it.
4. You can see that now a folder has been created in the \sdk\extras\google\google_play_services.
5. Now go to eclipse, Import Android project and give the location to this google_play_services folder. Don't forget to Check the Copy Projects into workspace option.
6. That's it.

Now if you want to include this project in your App's Project. Just go to project settings. In Android Option, there is a option to Add, Click on it, it will be showing your play-service/appcompat project.
choose whichever is relevant to you.

The same process could be followed for Appcompat Project.

If you face any other issue, comment here or mail me @ rahul.lnmiit@gmail.com

Friday, September 26, 2014

Device Tree in Linux

In the series of short notes on kernel concepts. Here is my new post on Device Tree. Device Tree has become a important part of linux kernel now. So lets start with it in my usual way of writing :

What is Device Tree?
- Device Tree is a tree like structure, which is used to store hardware information.
- It is a description of machine's hardware that is readable by the OS, so that kernel code could separated from machine specific information.
- So using Device tree, you can get any information from it at any point of time by parsing it.

What is the benefit of Device Tree?
- It ensures a single board file for a chipset, rest of the device specific information can be moved to device tree.
- Platform devices are created at run-time by the kernel by parsing the device tree nodes.
- we can add the devices which are not present right now, but in future they will, so no need to write the code again at later stage.
- So overall it steps toward the single kernel binary for all variation of chipset, which can be clubbed with specific device tree blob to  create different binaries for different variation. This will reduce the time to support new platform for the chipset.

How to enable DT support ?
- First thing is create an entry in board file, between DT_MACHINE_START & DT_MACHINE_END. you need to look into a board file to understand it better. Remember you must have dt_compat  field with the appropriate dt_mach structure, which will be containing the chipset details.
- Add your device tree source(dts) file. It have the compatible , model and id field, so it should be filled with appropriate variable. [ check /arch/arm/boot/dts/  folder for .dts file]
- To enable building this tree, there are 2 ways :
a) Enable through menuconfig -> boot options -> flattened device tree
or
b) define 'select USE_OF ' in Kconfig entry in arch/arm/Kconfig

Structure of Device Tree:
 Device tree describes a machine's hardware with a combination of

1) Nodes: It represents the device or bus. Contains properties and child nodes. It is defined as node_name@unit_address.

2) Properties: provides information about a device. It consists of a name and a value. Properties can further be categorized as Standard or Non-Standard.

Standard Properties:
a) compatible : it is used to distinguish between different nodes. Recommended format for compatible property is "manufacturer, model". OS can use it for machine/device driver selection.

b) phandle : specifies an unique numerical identifier for a node with the device tree. Used by other nodes that need to refer to the node associated with the property.

c) status : Indicate the operational status of a device. Values for this could be "okay", "disabled", "fail".

d) #address-cells,#size-cells : May be used in any device node that has children in the device tree hierarchy. Describes how the child nodes should be addressed. #address-cells tells no of cells to encode the address field in child's reg property. #size-cells tells no of cells to encode the size field in child's reg property.

e)reg : Arbitrary number of pairs of address and size. It describes the address and the size od the device's resources. It tells no of cells to specify address and size are specified by the #address-cells and #size-cells properties in the parent of the device node.


These are the main things. If you want more details, I will suggest you to refer Documentation/devicetree in linux kernel.

Thursday, September 25, 2014

Short Notes on System Call

This post covers pretty much all main points which you need to know about System Call in Linux. These points are my notes which I covered through many blogs/sites for my study. So lets start it :

What is System Call ?
- As Linux doesn't allow user process to directly modify anything in kernel space. It has provided a way to achieve it, which is known as System Call. So basically system call provide a layer between the kernel and user space process. Using this, kernel performs user space process's task inside the kernel space. This way kernel have control on, what a user process can do.

Why you need a System Call ?
- As system call is the only legal entry point to kernel, sometimes you may need some information, which can only be provided with kernel space credentials, so Kernel developers give you some system call. Although user space doesn't use it directly(in general), they uses some API for the same. 
So the flow will go like 

read() ----> read() wrapper ------> system_call() ------> sys_read()

Here first two thing is in user space and last two is in kernel space.

How do they work ?
- Application program calls the API.
- A system library routine is called first.
- It transforms the call to the system standard and traps to the kernel.
- Control is taken by the kernel running in the system mode.
- According to the code, the call dispatcher invokes the responsible handler.
- Interrupt is disable during this handler.
- After call is finished, mode is changed from system mode to user mode and calling process execution resumes.

How it works at low level ?
-  So whenever you call any system call, it is translated to SWI .
- Whenever processor sees SWI, it interrupts whatever is running currently( except IRQ/FIQ), changes the mode to supervisor mode(SVC).
- Whatever parameters were there in the system call, are passed using registers. 
- Also PC is stored in LR of svc mode and CPSR is saved in SPSR_svc, so that we can recover the previous state while returning from SWI.
- On execution of SWI, processor looks for SWI_handler address, which was already defined in the vector table. 
- From this SWI handler, processor jumps to the specific system call handler. Here we use the system call number to get the corresponding handler.
- Once the system call handler finishes its execution. Processor change the mode to user, and recover PC from LR.

Type of System Call :
- Process control and IPC : fork(), exec(), pipe()
- Memory Management : malloc(), free()
- File and File System management : open(), read(), write()
- Device Management : ioctl()
- Others : kill(), signal()

Implementation of System Call :
For this you can refer my previous blog on creating system call.