Thursday, 23 February 2017

Cocoa Pods: Dependancy Management Became Easier

Everything you need to know about pods…



What is CocoaPods

"CocoaPods is the dependency manager for Swift/Objective-C projects. It has thousands of libraries and can help you scale your projects elegantly." via http://cocoapods.org

Essentially, it helps you incorporate 3rd party libraries, frameworks, into your product without worrying about how to set them up and configure your project, which at times could be a huge pain.

Why Pods ? Why not Git ?

Since libraries are 3rd party so you will have to download and copy them to your project every time there is a new version? Lets say, you have 10 libs or frameworks in your project, now imagine the time it will take you to check if anyone of them has any new version that you want to update? and Worst if something does not work, you need to revert back to previous version? It does take time and is a nuisance, with CocoaPods you simply type pod update and updates the ones that have newer versions available.
Now If you want v1.1 of one particular library? How easy would it be for you to skim through Git commit history to find out which one you need? With CocoaPods, you simply say pod 'AFrameworkLib', '1.1'
Every lib requires setting up your project with a certain set of configuration to make them work, doing it for 10 or so libraries and then fixing conflicts is pain in itself. With CocoaPods, its taken care of automatically. 
Last but not least, you have to include licenses for all 3rd party libraries you are using to provide credit to original developer of that library. Imagine copying 10 license docs and making sure they are up to date? CocoaPod automatically creates an acknowledgement file in your project that you can simply include somewhere appropriate.


How pods work ?

Dependencies are listed in a pod file. When pod update/install command is fired, listed pods get installed and CocoaPods creates a new project file i.e. .xcworkspace file in which all your pods are listed. This makes it easier to use, but also less error proof.

How to install pods ?

Installation of pods is very easy and this is something that makes pods so popular. You can install pods in 4 easy steps.
Install gems : Fire [sudo gem install pods]  from terminal and gems would be installed.


Make a pod file: Either make a text file named Podfile in your project directory using terminal or use cocoa pods application and add pods to your application.

Search for the pod to be added: Search for the name and version of the pod you want to add on cocoapods.org
Add the pod and version in pod file: You need to mention the dependancy of the pod that you need to add in pod file you just created. This can be done using any editor (preferably use cocoa pods application)


Click Install: Either fire the command [pod install] or click on the install button in cocoa pods application and the mentioned dependancies would be installed.

Done. Just start using the workspace created by cocoa pods and instead of xcodeproj file. Mentioned dependencies have been added to your project.

How to remove installed pods ?

 Earlier it was a mess to remove the installed pods from Xcode project. Just deleting the pod file and directory was not enough. You need to remove the pod resources, embedded pod frameworks and few other stuffs from build phases. But cocoa pod application has made this job quite easy. All you need to do is a click “Remove cocoa pods from a project”. This would remove all the pods from the selected project. In case you need to remove some particular pods, just remove them from the pod file and fire the command pod update. Holla.. its done.

Podfile.lock

Every time we use [pod install] or [pod update], a podlock file is made ( or updated). It keeps track of all the pods installed along with the versions. Thus it helps in source control. Moreover, podfile.lock is of great use when work is being done in a team. Because of podfile.lock, the other guy using your project will get the same version you are using until he updates. Installation will not check for the newer version until you make the change in podfile.lock
This video from GoogleDevelopers explains the concept: https://www.youtube.com/watch?v=H-zK1mEwTe0


Making your own pod and publishing it to cocoapods.org

Like installing the existing pods, creating your own pod and making it available for the world to use is also damn easy. Let us look the entire process in detail.
Make a git repository and clone it: All the project files that you need to include in your pod must reside at git or at some reachable location by cocoapods (discussed in detail in podspec section). For ease, make a git repository and clone it in some directory at your Macbook. 
Push the code to master: Create a Xcode project in your directory (the one which you cloned), code, and push you code to origin. (This can be done either using git commands on terminal or using tools like source tree etc).
Add a podspec file: For making a pod, a podspec file must reside in your project directory. We will discuss about this file later. To create it, navigate to your project directory in terminal and fire the command pod spec create NameOfThePod 

We also need to mention about the swift version which we are using for our code. This is done by creating a .swift-version file. Create it using echo “3.0” >> .swift-version


Commit the changes to origin and your repository should look like this.

Create a release for your product: Click on the release button and create a release for your product with version 0.1.0 (or whatever convention you wish to use).
Edit the podspec file: The existing podspec file would be having lots of variable along with proper documentation. However, all of them are not necessary. Replace the code in podspec file with below code
Pod::Spec.new do |s|

s.platform = :ios
s.ios.deployment_target = '10.0'
s.name = “Name of the pod
# For example,
  # s.name = “InterestCalculator”

s.summary = “Summary for the pod
# For example,
  # s.summary = “Something about your pod”

s.requires_arc = true

s.version = “0.1.0"

s.license = { :type => "MIT", :file => "LICENSE" }

s.author = { “Your Name" => “Email Id" }
# For example,
  # s.author = { “Pallav Trivedi" => “pallavtrivedi03@gmail.com” }

s.homepage = “Link to your repository homepage
# For example,
  # s.homepage = “https://github.com/pallavtrivedi03/InterestCalculator”


s.source = { :git => "https://github.com/pallavtrivedi03/InterestCalculator.git", :tag => "#{s.version}"}

s.source_files = "InterestCalculator/*.{swift}"

end

These variables supply necessary information to CocoaPods.
Please refer https://guides.cocoapods.org/syntax/podspec.html#group_root_specification for details on podspec syntax.
Linting the Project : Before you can make your pod live, you need to lint your project. 


Basically this step checks for any errors and verify that there’s nothing wrong with the project. Linting the project is extremely easy. All you need to do is fire the command [pod lib lint] in the terminal. 

Once your pod passes validation, it is ready to be published.
Publish the pod:  In order to publish your pod, you need to have a trunk account. The word account is confusing because all you need is to create a session (cocoapod calls it trunk account). To create a session, you just need to fire this command in terminal
pod trunk register <Email> <Name> - - description=‘macbook pro’
A link would be mailed to you, clicking to which your session would be activated. This is what you see after clicking the link.



Pushing your Pod: This is the last step and easiest of all. Now that linting of your pod is successful, trunk session has been created, you just need to push the pod by following command. 
pod trunk push NameOfPod.podspec
Congrats, your pod is now accessible by the world.

Friday, 18 December 2015

Android or iOS : Developer’s Perspective

Image Source: www.technobuffalo.com
    One cannot deny to the fact that past two decades witnessed a rapid change in the technology. Our generation saw a long leap over letters, telegrams, landline and cordless phones which finally landed up at mobile phones. Or should I say, mobile world. While the thirst is still alive, research says that in couple of years, 3 out of 5 people will be carrying a mobile phone and 86.7% of these devices would be smart phones. Thus, people would be putting minimum efforts in ordering a pizza, booking a flight ticket or reserving seat for a movie. Keeping the same in mind, companies are focused on targeting their customers in the best possible way i.e. through responsive websites and native mobile applications. This eventually opens up the market for app developers. In this article, I would keep the responsive websites or hybrid apps aside (considering it a different lateral) and would focus on development of native apps. 
    Now comes the million dollar question, which platform should I develop for, Android or iOS ? While both have their own pros and cons, let us have a look at some of the points from developer’s perspective.

Programming Language

Considering programming language, there can be no doubt that Android seems better. As Android applications are written in Java, which appears easy to most of the developers as compared to Objective C for iOS, which is not a familiar one. You need to write more complex lines in Objective C for doing the same job than in Java.

String updatedString = originalString.replace(“Android”, “iOS”);

While in Objective C, this would be
NSString *updatedString=[originalString stringByReplacingOccurencesOfString:@“Android” withString:@“iOS”];

    This might appear more complex and lengthy, but at the same time, it gives more clarity. Not only clarity, but Java lacks with the features like Categories and Blocks. Modifying existing classes (even predefined ones) by introducing your own methods using categories is something which makes developers fond of Objective C.
    Above all, ARC (Automatic Reference Counting) plays a key role in making the Objective C better. It makes the programmer free from the overhead of memory management. In most of the cases,allocation, deallocation and other memory related issues are taken care by ARC. Thus, iOS lead here.

Development Environment

    Both platforms facilitate their developers with IDEs, but once again, iOS wins the battle. 

Though Android Studio (IDE for Android) is released, most of the developers still make use of Eclipse. However both Android Studio and Eclipse collectively stands far behind than Xcode (IDE for iOS). Some of the reasons behind this lagging are poor debugging and refactoring capabilities of Android IDEs. Programmers still need to search between hundreds of lines of log file to fix the bug, while in Xcode, they are straight ahead taken to the root cause (particularly when it is memory leakage issue). Also, simulators in Xcode are fast and auto configured, while in Eclipse, simulators are slow and programmer need to configure them (Android being used as OS by a variety of devices). 

UX

    With the introduction of Storyboard in Xcode, developers efforts in designing the UI of application have reduced to a great extent (linking views using segues can be considered as an example). Now there is no need to toggle between XML nibs which in turn, makes the code less error prone. 
While in Android, you still need to keep a track of XML files for all the activities. Moreover there exist no provision of linking the UI elements directly to the code using any drag drop feature. In contrast to this, Xcode allow you to link UI elements with the controllers and code in a very easy manner.   

Easy UI design using Storyboard

Moving the App from IDE to Store

    One must agree that publishing of application to the store is far easier in Android, as compared to iOS. Moving the app to Apple Store takes much efforts than to move it at Google Play Stores. This is because of complex and tedious testing process of app by Apple. Prior to this, getting the application signed, getting certificates and distribution profile is also a breath taking job. Moreover, iOS apps can only be published at Apple Stores, while there are n number of options for Android apps including Google Play Store, Amazon Store, various websites etc. Thus, Android leads iOS here.

Money Matters

    At the end of the day, it is revenue which is taken into the consideration. Though number of downloads in Android are 60% higher then iOS, but according the report of App Annie, revenue generated by iOS is 60% higher than Android. One of the reasons behind this is, iOS being a closed system. This mean that pirating an iOS app is much harder than Android app, and hence stealing of applications do not cause much effect on revenue. Moreover, a higher percentage of Apple users make in-app purchase. This percentage is much lower in case of Android, effecting revenue. And at last, fragmentation. Android apps are fragmented and available to users through different channels, causing a fake rating and decrease in revenue. 

    Thus, both the platforms have their own pros and cons. Geeks who are about to start the app development might see this as a dilemma, but in my view, I find iOS slightly better over Android.  


Friday, 24 July 2015

Cloud Computing in Online Project Development

Paper published in International Journal of Computer and Communication System Engineering (IJCCSE), Vol 2, June 2015.





Thursday, 2 July 2015

Node JS At A Glance

Instant notifications, lighting fast loading of web pages, seamless streaming, flawless buffering and what not. Web was not like this before the invention of node js. If we turn back the clock, we would find that websites weighed heavy, flooding with the codes of flash and applet resulting in not only slow responses but poor reliability too. However Java Script and JASON together on a stack had immense capabilities, yet node js proved more efficient. In 2009, Ryan Dahl invented node with the hope to see it as a tool for making websites with push notification capability like Facebook and Gmail which indeed came true. Node.js is not only an open source runtime environment for server side and networking applications but also an efficient framework capable of handling real time applications which process intensive data, distributed across devices. Its applications are written in java script which in turns uses V8 parser by Google. Node.js provides non blocking event driven I/O paradigm which eventually facilitates two way communication i.e. both client and server can initiate communication.
Node JS

Unlike conventional techniques, which make use of separate thread for each connection, node.js manages thousands of concurrent connection on a single thread. This saves both RAM usage and cost of context switching between the threads. Such features of node.js were the reasons, that it prevailed and become pioneer in web technologies. Today, most of the sites make use of node.js, while web applications facilitating chat and data streaming can be very easily developed by implementing it. 

Apart from this, applications for automation or Internet of Things are also written in node.js. Thus it can be concluded that near future of web is solely dependent on node than any other technology. 

Wednesday, 10 September 2014

TCS Interview Experience

Got Placed in TCS, and here's the experience.

My TCS Experience...
Verbal ability test ---> Wrote short and simple mail on the given topic. Completed it in 6 mins and then checked it twice. Especially the spellings, and whether all the phrases are included or not..

Analytiacal Ability-----> Attempted only 16-17 questions. Took risk. But all of them were correct. There was no scope for negative marks.

It was expected that result will be declared by the night, waited till 3 for it, but it didnt.
With full confidence, reached college next day (in formals, didnt thought that what if my name will not be in the results). At 9:30, I checked the mail id, saw the the result... I was scrolling slowly, didnt used Ctrl+F.. and almost at the bottom of the list, I saw, Pallav Trivedi... and a sudden reaction.. "ab to ho jaega.."
Started preparing for interviews.. bit of DBMS, OS, DS, Java (Multithreading, exception etc).

My resume was called by the interviewer sitting in the room no. 10, but he went to take lunch and I was interviewed by the panel sitting in room no. 3
Around 3, I was called for TR..
I entered the room, two persons were sitting..
Me: May I come in sir
Interviewers: Please come in, have a seat. (I sat)

Q1. Give your resume..
Ans. Sir, I gave it to sir sitting in room no 10. as he was supposed to....(they stopped me and said no issues)

Q2. Tell us about yourself.
Ans. Good afternoon sir, I am Pallav Trivedi. I am pursuing my Bachelors of Enginnering in Computer Science. I am from Mandsaur, a city at border of Madhya Pradesh and Rajasthan. My father Mr G.P.Trivedi is lecturer in English at School of Excellence Mandsaur. I am having learning attitude because of him. My mother, Mrs Sangeeta Trived is a clerk at Women and child welfare department Mandsaur. She taught me how to manage the things. Apart from them, I have a brother, Saurabh Trivedi, he too is an engineer and serving for Bhaskar Denims, Bhopal. He got married last year, and my Bhabhi Mrs Monika Trivedi is Msc in Computer Science. As I belong to computer science fraternity, I love to do programming, but apart from it, I also keep interest in playing guitar, chess and literary stuffs.

Q3. What was your minor project.
Ans.Sir, I always had a craze to do something live, something creative. Thus, I and my room mate took the responsibility to develop the official webiste of college tech fest MTM. We did it for 2 consecutive years. First year, on java and second year on .net. As we were beginners, faced lot of problems on deploying it and learned alot. Apart from them, I made to desktop applications on Java J2EE i.e. My Word Web (Customizable Dictionary) and Packet Sniffer (a Packet Capturing application).

Q4. What is this MTM.
Ans. Sir, it is our college fest, Mech Tech Meet, organized by Mechanical Engineering Department of our college, and we were given the responsibility to develop its official website.

Q5. What programming languages do you know.
Ans. C/C++/Java

Q6. You said that you developed site on .net. You dont know .net...?
Ans. Sir, I dont know about C#. We wanted to work in a manner as industry do. So we divided teams. One of designing and other of programming. Programming part was taken by my room mate, as he knows C#, and I took designing part, HTML, Jquery, JavaScript, Photoshop etc.

Q7. Pallav, can you write a short program for me.
Ans Sure sir, which technology.

Q8. In c, write a program to find largest of three numbers. (I was so happy, as this was too much easy for me).
Ans. Sure sir, (I made the program, and used turnary operator, wherever I can)

Q9. Tell me the logic of swapping the values of two variables, without using third variable
(Again a laddu question, I answered it perfectly).

Q10. Can you write the code for swapping, using pointers.
Ans. (Damn easy for me, as pointers are my strength. I wrote).

Q11. Can you explain us, what are pointers ?
Ans. (What I wanted.. I was feeling like Super hero). Explained on paper, in a brilliant manner.

Q12. Write a program to find string length.
An    Sir which technology....  (they said C++)
                Sir, should I make separate function or in the main.... (make separate function)
                Sir, can I assume a string, or user will insert. .....(user will insert)
                Sir, how will the input come, Command Line or...    (they were smiling and asked me to leave it)
(by now, they were very happy)

Q13. How are you analytical ability.
Ans. I am weak at it sir, but I am working on it, and very soon, I'll be good at it.

Q14. How are you at innovations.
Ans. I am good at it sir, as my field of interest includes, playing guitar i.e. generating music, literature, also I chose designing field in project..

Q15. Tell us something related to your interests, poem or whatever u like.
Ans I recited a beautiful poem,
"Rahe re ubalta rakt nirantar, shira shira me aag rahe,
Sanso me sankalp ghule ho, aankho me saubhagya rahe..
Yuddh hamara, chale re nirantar, chuppi aur andhiyaro se..
Isse jyada aur kahe kya, in gum sum angaro se...!!!"

Q16. What are your dreams.
Ans. Short Term: to get selected in TCS, it has been my dream company.
          Long Term, or where I see myself after 10-15 years, I want a stable job with work-life balance, handsome salary, both of my parents living with me, a sweet heart and two little kids.
( They smiled and said, you have decided for two.. (i smiled in response).)

Q17. Any questions for us..?
Ans. I asked a question regarding Java Certification, and they answered it.
(Ok Pallav, it was nice to meet you..  thank you)

After some time, I was called for HR, it was nothing more than a formality.


Q1. Why should TCS hire you?
Ans. Mam, First of all I am good at programming, and it is a core need of TCS, as TCS provides IT Services.

Q2. Why not any other organization, all of them require programmers ?
Ans, Mam, TCS is a family. It is an institute to me, rest are organizations. From my childhood, TCS has always been with me. From Salt to Nano, Eye Plus to fast track.. every where...

Q3. Prove that you can work in team.
Ans. Mam, all the projects I made, were in team, teams were divided in a way as industry do, designers and programmers. I have been a part of volley ball team which representd the school at cluster level, and volley ball is a team game.

Q4. Tell us a quality of yours which 3 lac employees of TCS do not have..
Ans. (Though for a while )Sorry mam.... I cant say that I have any such quality which 3,05,421 employees are not having. Its such a huge number.

Q5. Ok, tell a quality which 100 students of your college are not having like you
Ans. Linguistic Capabilities.. I observed this, in speeches, debates, discussions etc.

Q6. Any Backlogs ?
Ans. For the first time in 6 semeters, I got back, it was a bolt form blue to me. I applied for reval, yesteday, the result of reval came, and it has been cleared. No backs.
(Ok pallav, all the best)




After few hours, results were announced, I was sure that my name would be there, and god didnt proved me wrong...  

Wednesday, 13 August 2014

Introduction to PL/SQL.

Let us know something about PL/SQL.

Procedural Language/Structured Query Language or PL/SQL is that part of RDBMS at which we do not pay much attention while studying. However, when it comes to develop project, it is the most important part and cannot be ignored. Using PL/SQL while designing database reduces the programmer's effort exponentially. Question arises, how? And the simple answer is, 'A major portion of programming dealing with DB is finished in the database designing phase.'
Let us consider a scenario, through which we can understand the importance of using PL/SQL.

Consider an example related to accounting, in which tax on salary is to be calculated. There exists a table named employee (in which the account details are stored, say, emp_id,name and salary). Now, on using conventional programming approach, the programmer will need to make a cursor (for which, JDBC-ODBC bridge,DSN etc), through which records of employee table would be extracted, necessary calculation would be performed on extracted data and the generated result i.e. tax would be inserted back in some table say Tax. And all this will be done by programmer.
Now let us have a look at approach in which PL/SQL is involved.While designing DB, few procedures would be made(say, calculateTax and populateTax), in which necessary calculations would be done and later, simply procedures would be called. Here the point to be observed is, making procedures and implementing necessary calculations in them, calling them, all these activities are being performed at DBMS and the programmer is far away from this.

Here's the code for above example.(according to MySQL)

Now let us look at few program units of PL/SQL
  • Procedures
  • Functions
  • Triggers
First program unit is Procedure. It is similar to functions (one which we use in programming) and are used for computations, however the difference between procedure and function is
  1. Function returns a value while procedure do not.
  2. Function can be used in SQL statements while procedures cannot.
Triggers. Basically they are stored procedures which get automatically invoked on occurrence of some specific event. For example, when the values of attribute Current Balance is to be altered on the occurrence of credit/debit events, Trigger is something which would be used. A procedure (more specifically, trigger) would be wired up with insert or delete event and as soon as the events would occur, the wired up stored procedure would be triggered. 

This was a brief introduction about PL/SQL. 

Please correct me if I got something wrong.

Friday, 8 August 2014

Lets have a look at Session Tracking.


Here we would be discussing about how to track session in java.
But before moving on to Session Tracking, we must know something about Servlets. Here are some key points. With the request to servlet,

·         4 Objects are made, HttpServletRequest, HttpServletResponse, Document and  PrintWriter (one of             each, at the time of request to servlet)
·         Name/Value pair, which is extracted from request is kept in object of HttpServletRequest  .
·         Specified Servlet is searched. Here story may end (if class is not found), Error message will be kept in           response.
·         Pointer of HttpServlet is taken, Object of specified servlet is made, and its address is assigned to pointer.       Again, story may end (if class do not extend HttpServlet or it is not public)
·         Now doGet(HttpServletRequest,HttpServletResponse) method is called using that pointer. For execution of doPost method, explicit call need to be placed, by default, doGet is called.

After execution of doGet, whatever kept in object of document will be sent to client( browser).

Here's an example for download (lets say one.com)
https://docs.google.com/uc?export=download&id=0B0p0u1WTbGiRV0l1ZWxmMXpSbFE

Need of Session Tracking..???

ü        Problem: Data received in first request will not be available in second response.
Solution: Session Tracking i.e. If the data in the previous request is also available in current request, then it is said that session is being tracked.

How to Track Session...???

 Here we will be discussing on the following ways of Session Tracking.

  • Hidden Form Feed
  • URL Rewriting
  • Cookies
  • Session Object

1. Hidden Form Feed: 
        Data received in first request will be sent along with the response, but in a hidden manner. For doing so, we will keep the value of type attribute as hidden in input tag.
<input type="hidden" name='XYZ' value='Previous Data'>

Here's an example of Hidden Form Feed for download. (lets say two.com)
https://docs.google.com/uc?export=download&id=0B0p0u1WTbGiRQmk4WW5TYTBnb1E

2.URL Rewriting
      To make the data available in second request, we will keep it in query string. For this, we will have to programatically generate query string. But values in query string are encoded according to Http Protocols. Thus, we will be using encode method of class URLEncoder in the java.net package.
     Lets say, 'name' is the variable which is to be encoded.
name=URLEncoder.encode(name);

Here's an example of URL Rewriting for download. (lets say three.com)
https://docs.google.com/uc?export=download&id=0B0p0u1WTbGiROXBoQXZqdkQ0WDg

3. Cookies

  • Cookie is a particular type of object, in which name/value pair is stored.
  • Cookie is made at server side, and then kept in response so as to be transferred to browser
  • Browser will store the cookie at disk, and will also keep a track that from which site, the cookie came.
  • Next time when the request will be sent to that particular site, its cookies will also be sent along with the request.
    Cookie c1=new Cookie(“name”,java.net.URLEncoder.encode(name,”utf-8”));
    c1.setMaxAge(60*10); 
    c1.setPath("/");            

     When cookie is to be given to a particular resource, setPath() will be used 
     SetMaxAge() is used to specify life span of cookie.
     
    response.addCookie(c1);

    And at receiving end,
    c=request.getCookies();
    name=c[0].getValues();

Here's an example of Session Tracking through cookies for download. (lets say four.com)

4. Session Object
      Above listed all ways of tracking session are less reliable than session object. In this way,

   ü  Data in first request will be kept in a Session Object (which will be in RAM), and the second servlet             will get it from there.
   ü  Session Object will be requested from server, which will look that whether the object exists for this               connection or not.
   ü  If not, then address of a newly created session object will be given.
   ü  Session Object will not be shared by other connections and will not be destroyed after response.
   ü  By default, Max Time Interval: 30 min
   
             HttpSession hs=request.getSession();       à requested for session object.
      HttpSession s=request.getSession(false); àReference of existing object will be given, new                                                                                         will not be created( in case it do not exists).
     
       hs.setAttribute(“name”,name);
                                  name=(String)hs.getAttribute(“name”);   à At receiving end

              Here's an example of Session Tracking through Session Object for download (lets say five.com)

       Please leave comments.!!!