Skip to main content

Posts

Showing posts from 2014

zipalign tool not found in SDK - Eclipse

While exporting Android signed application package through Eclipse you get this warning The zipalign tool was not found in the SDK. Please update to the latest SDK and re-export your application or run zipalign manually After getting this warning I started looking for zipalign tool. After searching in SDK folder I found zipalign.exe under copy_tools folder. This folder is used by Android SDK update to keep copy of old tools. What is zipalign tool ? From Android documentation zipalign is an archive alignment tool that provides important optimization to Android application (.apk) files. The purpose is to ensure that all uncompressed data starts with a particular alignment relative to the start of the file. How to make Eclipse find this zipalign tool To make eclipse use this zipalign.exe you have to copy it in a proper SDK folder. You can find SDK folder in %android-sdk-path% / build_tools / {sdkfolder} After copying zipalign.exe to this folder when you run Eclipse to s

Resizing image in Blackberry 10 Cascades

In this post we will learn how to re-size an image stored on file or in memory. Cascades provide Image class to perform loading of images but it do not have any support for manipulating the image especially re-sizing of image. But we have a class QImage from Qt that support re-sizing of images. So first lets see how we can load image through QImage class Loading image QImage has many overloaded constructors for loading images from different sources or just create an empty QImage of given height and width. We will cover two constructors here, one for loading image from file and other to load image from image data in memory. Loading from file We will use a constructor that takes file name (QString) as a parameter. We can optionally pass format as a char* parameter but its better to skip that so QImage will detect format from the filename QImage img("asset:///testimage.jpg"); Loading from in memory data QImage provides another constructor to load image data stored

How to change JVM for Eclipse

I have following JDKs installed 1) JDK7 64 bit 2) JDK6 64 bit 3) JDK6 32 bit Also I have multiple Eclipse installed. They run on different JVM. For example Eclipse for Blackberry runs on 32 bit JDK and Eclipse for Android runs on 64 bit JDK. You can put only one JDK to PATH in Environment variable or JAVA_HOME environment variable. To configure Eclipse to use specific JVM you have to modify configuration file for your eclipse (usually eclipse.ini). Add following lines just before the line which says “-vmargs”. -vm D:\TOOLS\Java\JDK6-32bit\bin\javaw.exe {this should be the path to your desired JDK bin\javaw.exe }

15 Mistakes to Avoid When Traveling Solo (IndependentTraveler.com)

This blog posts contain excerpts from advice given by Ed Hewitt on IndependentTraveler.com  . View original article here What hostels and guesthouses are great for is meeting other folks doing the same thing that you are -- true fellow travelers. But you don't have to commit to them unrelentingly; your choice of lodging is just another tool in your solo traveler bag. When in need of comfort, safety and convenience, choose a reputable hotel; when in need of companionship, think about hostels and other alternative lodging options. Don't feel obligated to stay in hostels. On these nights, take it easy on yourself; you might stay near the airport or train station, or splurge on a well-known hotel, or take a cab when you might otherwise save money by taking public transit. Don't get too ambitious at the beginning or end of a trip. Having no money in your pocket and no way to get any is a problem for any traveler, but even more so when traveling solo.  Don'

Implementing OAuth2 consumer in C#

Recently I worked on a project that involved integrating with social networking and jobs websites like Elance. These days almost all major services that allow applications to access users' data, perform authorization/authentication using OAuth1.0 or OAuth2. OAuth2 compared to OAuth1 is very easy to implement. OAuth1 involves generating nonce,timestamp,signaturebase and signing the request with any algorithm like HMAC-SHA1 and appending data to query string of URL and passing in Authorization header of HTTP. OAuth2 removed all these requirements. Following is OAuth2 process in a nutshell 1) Redirect user to Authorization url passing client_id and redirect_url in query parameters 2) If user authenticates successfully through service provider it will redirect user to the redirect_url passed with authorization access code in query parameters. 3) After getting authorization access code you exchange this to receive access token. You make a POST HTTP request to a URL passing client_id

JEE File Upload - Handling Multipart requests in Servlets 3.0

Prior to Servlets 3.0 developers have to use 3rd party libraries to process complex multipart request that is sent when file is uploaded by user. Starting from Servlets 3.0 JEE provides a better way to handle file uploads (multipart requests) without using any 3rd party library. Making your Servlet ready to handle Multipart requests All you have to do is to add  @MultipartConfig annotation on your servlet class and it is ready to handle Multipart requests. @MultipartConfig   public class FileUploadServlet extends HttpServlet { Our example HTML form <form method="POST" enctype=" multipart/form-data "> <input type="file" name="ufile" /> <input type="submit" value="Submit" /> </form> Handling the POST in processRequest method of Servlet protected void processRequest (HttpServletRequest request,         HttpServletResponse response)         throws ServletException, IOException { Gettin

Truncate/Ignore time part of DateTime column in Entity Framework

There are times when you want to perform query on only date part of the column that has type DateTime in database. Entity framework does not support DateTime.Date property but provides a helper class EntityFunctions . EntityFunctions has a method TruncateTime that can be called in Linq2Entities query and truncates the time part from datetime. Here is how to use it using (AccountEntities dal = new AccountEntities ()) {               DateTime dtStart=DateTime.Now.AddDays(-20).Date;               DateTime dtEnd=DateTime.Now.Date;     transactions = (from t in dal.Transactions                             where                             EntityFunctions.TruncateTime (t.TransactionDate.Value)                             >= dtStart                             &&                             EntityFunctions.TruncateTime (t.TransactionDate.Value)                             <= dtEnd                            orderby t.TransactionDate descending                          

Android pull down to refresh implementation

There are many apps that allow you to refresh content by simply pulling down the list. I had a similar requirement in one of my projects. I decided to write a blog post that how easily I implemented this feature. For simplicity I will remove code of setting Adapter to ListView etc.I will only show code to detect pull down on ListView First lets see the layout of my screen <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >       <!-- this linear layout will contain our content which we will show -->     <!-- to user while refreshing -->     <LinearLayout android:id="@+id/layoutRefresh"         android:orientation="vertical"         android:layout_height="wrap_content"         andr

Multithreaded C# TCP server to handle multiple clients

I decided to write a minimal multithreaded TCP based server as a blog post. Following class can serve as a skeleton for any small or large scale multithreaded TCP socket server. It do not contain much error handling , it is only to give an idea that how multithreaded server works and how it can process multiple clients using threading. using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.Collections.Generic; namespace RandomStuffMine { public class MTServer {     public int Port{get;set;}     public Socket ServerSocket{get;set;}     private List<Client> Clients=new List<Client>();     private bool runServer=true;     public MTServer(int port)     {         Port=port;         ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);     }     public void Start()     {         Thread thr=new Thread(new ThreadStart(StartServer));         thr.IsBackground=t

Playing with Date and Time in MySQL

Manipulating date and time in database is an important task in any database driven application. MySQL is the most popular open source database deployed widely. Here are some tasks that you can perform on date and time using MySQL built in functions. Adding interval to a date DATE_ADD function allows adding/subtracting(using - sign) any interval to date/datetime. The usage of this function is as follows DATE_ADD(date,INTERVAL  [expression] [unit] ) unit can be one of the following MICROSECOND,SECOND,MINUTE,HOUR,DAY,WEEK,MONTH,QUARTER,YEAR,SECOND_MICROSECOND,MINUTE_MICROSECOND,MINUTE_SECOND,HOUR_MICROSECOND,HOUR_SECOND,HOUR_MINUTE,DAY_MICROSECOND,DAY_SECOND,DAY_MINUTE,DAY_HOUR,YEAR_MONTH expression  depends upon the unit. We will explore some units and respected expressions in this post. Note: All example queries use column name "column_dt" for a column of type datetime. Adding SECOND(s) to DATETIME Following query will add 1 second to the value of column_dt

Cannot find RIMIDEWin32Util.dll in Eclipse for Blackberry development

I switched to Windows 7 64 bit few months back and I upgraded all my tools/SDKs to 64 bit versions including JDK. Suddenly after I updated JDK to 64bit my Eclipse plugin that I use to develop Blackberry applications started giving this error on every start Cannot find RIMIDEWin32Util.dll. This is a required component of the IDE.  Solution to this problem is that install both JDK and Eclipse 32bit versions. And set the following environment variables in Windows JAVAHOME=path to the folder where JDK(32bit) is installed PATH=add path to bin folder of your JDK(32bit)

Android - receiving result from another activity

Its a common operation in Android application to launch new activity all the time. There are times when you want to receive the result from new activity started. For example in one of my recent projects I have to launch settings activity ( SettingsActivity ) to set the mode of application and when this activity is closed it should return the selected mode to the caller activity ( MainActivity ). How child Activity returns result Activity class has a method setResult  which sets the result code to be returned to parent activity. Another overload of setResult  allows you to pass Intent also for any extra data to be sent. In my SettingsActivity I have code like this if (settingsSavedByUser()){     Intent i=new Intent();     i.putExtra("mode","selectedApplicationMode");     setResult(RESULT_OK,i); //RESULT_OK and Intent(i) will be returned to parent }else{     setResult(RESULT_CANCELLED); //RESULT_CANCELLED will be returned to parent } How parent Activity

HTTP POST request in Java

In one blog post I wrote about how we can make HTTP requests and receive response in Java. That post was only about sending GET request. This time we will learn how to make POST (submitting form etc) request in Java.  This post assumes that you are familiar with  HttpURLConnection  found in  java.net  package. If you are not please read this blog post http://random-stuff-mine.blogspot.com/2013/06/http-request-and-response-java.html HTTP POST request Lets say you entered username/password in a website and pressed "Login" button. Most probably the web browser makes a HTTP POST request containing your username/password. A simple POST request would look like this POST /path/to/script HTTP/1.1 User-Agent: RemzyHttpBot Content-Type: application/x-www-form-urlencoded Content-Length: 32   username=rameez&password=test In the above request you see that username and password are sent inside the request body and content-type of request is set to application/x-www-form-

Smart pointers in C++

Using pointers in a program increases the risk of memory and resource leaks. Programmers have to make sure that they always free memory (acquired by new operator) using delete operator. Bare pointers in C++ are not exception safe , they do not get destroyed (release memory) if there is an exception in your program. Smart pointers are helpful to avoid all the problems mentioned above. There are many kinds of smart pointers but in this blog post we will discuss 2 types of smart pointers: unique_ptr and  shared_ptr. What are smart pointers ? Smart pointers are wrapper over a normal C++ pointer. They are objects that store pointer to dynamically allocated objects. They conceptually own the object pointed to, they delete the object as soon as object is no longer required and goes out of scope. Difference between normal and smart pointer The main difference between a normal and smart pointer is that normal pointer do not get deleted unless delete operator is called. On other hand

Java SDK not found under Android's SDK Locations settings in Xamarin

To work with Android under Xamarin you have to set up Android SDK and JDK path under Tools->Options->Projects->SDK Locations->Android I faced a problem after setting all SDK locations it says "SDK not found" for JDK despite giving the correct path for JDK installed on my system. After few hit and trials I figured out that the problem is 64-bit version of JDK installed . Xamarin works with 32 bit JDK. So I downloaded the 32-bit version of JDK from http://download.xamarin.com/Installer/MonoForAndroid/jdk-6u39-windows-i586.exe After installing this JDK I set up the options for SDK locations and now Xamarin works fine.

Blackberry 10 cascades - client side socket programming

Blackberry 10 has full support for BSD Sockets API . All the routines one can expect from BSD Sockets are available in Blackberry 10. But cascades make socket programming much easier. In this post we will discuss client side socket programming in Blackberry 10 using cascades . You can study about BSD Sockets API support in Blackberry 10 here . Before starting to use Cascades socket API you have to add this line to your .pro file QT+= network Cascades API provide a high level class QTcpSocket  which makes writing client side socket code very easy. Include following files in your cpp file #include <QtNetwork/QAbstractSocket> #include <QtNetwork/QTcpSocket> Any client side socket app performs following operations 1) Connect to server 2) Send / Receive data 3) Close connection Connecting to server QTcpSocket provides a function connectToHost which takes IP Address/Hostname (QString) , port (quint16) and OpenMode (default value is ReadWrite) as parameters.

Getting location in Blackberry 10

Location awareness is a required feature in most of the mobile phone applications today. Blackberry 10 API provides very easy way of accessing user's current location. In this blog post we will see how applications can access user location through native blackberry 10 API. Before using Location API you must add following to your .pro file LIBS += -lQtLocationSubset To enable your app to obtain the current position or last known position of the device, you must add the access_location_services permission to your bar-descriptor.xml file like this <permission>access_location_services</permission> Note that Location services must be enabled on device to get the location. We use QGeoPositionInfoSource class to find the location of a device and get updates about its position. To use QGeoPositionInfoSource you must include it like this <QtLocationSubset/QGeoPositionInfoSource> First we must initialize position source. which can be done through  createDe

Decoding JPEG image file using libavcodec

I got a chance to work on a video encoding application that decodes series of jpeg files and convert them into ogg theora video file. I used the infamous libavcodec library that is used in FFMPEG . I decided to write blog posts explaining how I decode jpeg images and convert them into ogg video file. This is the first part and in this I will explain how to decode jpeg images using libavcodec. To learn how to write decoded images as a ogg video file please read http://random-stuff-mine.blogspot.com/2017/07/encoding-raw-images-to-ogg-theora-video.html Before reading this blog post you must be aware of using and setting up libavcodec. I highly recommend this tutorial to get basics of using libavcodec http://www.ffmpeg.org/doxygen/0.6/api-example_8c-source.html Allocating input format context We will first allocate input format for reading the file. We will use avformat_open_input function that will allocate AVFormatContext structure passed to it , the function detects input typ

Understanding pointers in C Part1 - Basics of Pointer

Pointers are one of the most difficult concepts in C language to grasp. Many programmers get confused in pointers.I am one of them. I decided to write series of blog posts covering basic to advance concepts of pointers. This is the first part to understand very basic of pointer that what pointer actually is and how we can store/access data through pointers. Put simply A pointer is a variable that contains the address of a variable Lets try to understand pointers using some code. int x=3; int *ptrToX; ptrToX=&x;  In above code we simply took a variable x of type int . Then we define a pointer ( * denotes that variable is a pointer and it is known as indirection or dereferencing operator ) ptrToX  of type int and assigned address of x to ptrToX . Now ptrToX points to x . Note that ptrToX do not contain value of x ( i.e 3 ) instead it contains memory address of x . Now we can access and manipulate value of x using ptrToX . Accessing value of a variable that is p

Change Blackberry 10 wallpaper programatically

Changing Blackberry 10 wallpaper through code is a fairly easy task. In this blog post we will cover two methods of changing wallpaper of Blackberry 10 programatically. Using Cascades In cascades we can use HomeScreen class defined inside bb::platform namespace. To link against this class you must have following line in your .pro file LIBS += -lbbplatform HomeScreen class has a function setWallpaper which accept object of type QUrl as argument. This function sets the wallpaper to the image pointed by url passed. It returns a bool as status of call. Now we can write code to change the wallpaper. For simplicity, code will set image as wallpaper from assets directory. bb::platform::HomeScreen homeScr; bool wallpaperResult=homeScr.setWallpaper(QUrl("asset:///mywallpaper.png")); Blackberry notes for setWallpaper method The image will be scaled to fit the screen. If the wallpaper image is deleted while it is set as the current wallpaper (say, because the image