Git Workflow

April 27, 2014 Leave a comment

This is probably one of the greatest blogs I have read about Git so just wanted to share it. Here is the picture that summarizes the whole thing for me.

 

cN5oZ9Kq4sk1-C8bEg4nbTl72eJkfbmt4t8yenImKBVvK0kTmF0xjctABnaLJIm9

Categories: Uncategorized

Oracle 11g PL/SQL: Getting Turkish name for a month

March 20, 2014 Leave a comment

Use this very handy argument to your ‘TO_CHAR’ function in order to get the Turkish name of a month.

(TO_CHAR (SYSDATE,  'MONTH',  'NLS_DATE_LANGUAGE = TURKISH')))

EDIT: Just realized that this actually does not work well (I am not sure if it is due to my regional settings) but it fails to convert some of the months names correctly.

For example, it returns ŞUBAT correctly while it will return HAZIRAN instead of HAZİRAN so be careful with it.

Categories: Uncategorized Tags: , , ,

Website for looking up various Software Licenses

February 28, 2014 Leave a comment

This website will provide you summarized information about various software licenses used in the industry. Comes handy especially for open source project licenses.

https://tldrlegal.com/

Categories: Uncategorized

Setting up an Android device for debugging (with an IDE)

December 29, 2013 Leave a comment

1) Enable usb debuggin mode (if it is hidden tap 7 times)

For Windows:

If it still doesn’t work go to device manager and look for ”other devices”. In my case I had a sony xperia tipo and there was just Android. Right click on that and select ”Update Driver Software”

If automatic update does not work, select the browse my computer option and see if there is one located under:

<Your Android SDK location>\extras\google\usb_driver

Otherwise try:

Browse my computer for driver software -> Let me pick from a list of device drivers on my computer -> Android Phone/Google Inc -> Some ADB driver version. This should solve the problem.

After all these, if, in debugging options, you still see a warning sign nest to your (now supposed-to-be-recognized) phone, you may have done something wrong in one of these steps or you may need to try an alternative step to the one you have done initially.

References: Stackoverflow

Categories: Uncategorized

Play Framework – eclipsify problem

December 29, 2013 Leave a comment

After you create a play project, you can easily convert it to an eclipse project by running “play eclipse” (which was “play eclipsify” in the older versions). However, when you get a legacy play project you may run into issues when doing this. Kinds of errors you may get are:

You can give these a try in order to solve the problem:

  1. Make sure you have the latest version of play framework
  2. Check if your project contains a “project” folder. If not, just create a new play project and copy that folder to your project. If there is one, make sure that the sbt version is up-to-date and plugin path definition is correct in respective files (build.properties & plugins.sbt)
Categories: Uncategorized

Xcode : lipo-error-cant-open-input-file

August 19, 2013 Leave a comment

If you get this error in Xcode for some reason (although there can be many solutions), try doing this which worked for me:

Project target-> Build setting-> Build Active Architecture only and set this Build Active Architecture only to “YES”

References: http://stackoverflow.com/questions/17348912/lipo-error-cant-open-input-file

Categories: Uncategorized

Creating a RadioLog Listener in Android

July 24, 2013 Leave a comment
public class RadioLogListener
{
	public static void start() 
	{
		
	    final Handler radioLogHandler = new Handler();
		
	    new Thread(new Runnable() 
	    {
	    	
	    	public void run() 	        
	        {

	            Process process = null;
	            try {
	                // Clear the log first
	                String clearRadioLog[]= {"logcat","-b", "radio", "-c"};
	                String getRadioLog[]= {"logcat","-b", "radio"};

	                Runtime.getRuntime().exec(clearRadioLog);	
	                process = Runtime.getRuntime().exec(getRadioLog);
	                
	                Log.e("RadioLog", "RadioLogProc: " + process);
	
	                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
	                while (true) {
	                    final String line = bufferedReader.readLine();
	                    if (line != null) {
	                        if (line.contains("disconnectCauseFromCode") || line.contains("LAST_CALL_FAIL_CAUSE {")) {
	                            Log.d("RadioLog", "RadioLog: " + line);
	                            radioLogHandler.post(new Runnable() {
	                                public void run() 
	                                {
	                                    //Save the line to a file 
	                            		try 
	                            		{
		                                	FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory() +"/"+ "TTG_RADIO_LOG.txt", true);
		                                	DataOutputStream out = new DataOutputStream(fos);
	                            			out.writeUTF(new String(line + "\n\n"));
	                            		} catch (FileNotFoundException e1) {
	                            			e1.printStackTrace();
	                            		}
	                            		 catch (IOException e1) {
	                            			e1.printStackTrace();
	                            		}
	                            		
	                            		// Parse the cause code 
	                            		int causeCode = -1;
	                            		
	                            		try
	                            		{
	                            			String[] result = line.split(" ");
	                            		
	                            			String rawCauseCode = result[result.length-1].trim();
	                            		
	                            			rawCauseCode = rawCauseCode.substring(1, rawCauseCode.length() - 1);
	                            			
	                            			causeCode = Integer.parseInt(rawCauseCode); 
	                            			
	                            		}
	                            		catch(Exception e)
	                            		{
	                            			Log.d("RADIO_LOG", "PARSE_ERROR");
	                            			System.out.println(e.getMessage());	                            			
	                            		}
	                            		
	                            		//and log accordingly
	                            		logFailCause(causeCode);
	                                }
	                            });
	                        }
	                    }
	                }
	            } catch (IOException e) {
	                Log.e("RadioLog", "Can't get radio log", e);
	            } finally {
	                if (process != null) {
	                    process.destroy();
	                }
	            }	     	
	        }	    		
	    }).start();	
	}

	private static void logFailCause(int causeCode) 
	{
		// Normal call end
		if(causeCode == CallFailCause.NORMAL_CLEARING)
		{
			new Event("CALL_DISCONNECTED", "Calling party hung-up");
		}
		
		if(causeCode == CallFailCause.ERROR_UNSPECIFIED)
		{
			new Event("CALL_ERROR_GENERAL");
			new Event("CALL_DISCONNECTED");
		}
		
		if(causeCode == CallFailCause.TEMPORARY_FAILURE)
		{
			new Event("CALL_ERROR_GENERAL");
			new Event("CALL_DISCONNECTED");
		}
		
		if(causeCode == CallFailCause.NO_CIRCUIT_AVAIL)
		{
			new Event("CALL_ERROR_CONGESTION");
			new Event("CALL_DISCONNECTED");
		}
		
		if(causeCode == CallFailCause.SWITCHING_CONGESTION)
		{
			new Event("CALL_ERROR_CONGESTION");
			new Event("CALL_DISCONNECTED");
		}
		
		if(causeCode == CallFailCause.CHANNEL_NOT_AVAIL)
		{
			new Event("CALL_ERROR_CONGESTION");
			new Event("CALL_DISCONNECTED");
		}
		
		if(causeCode == CallFailCause.QOS_NOT_AVAIL)
		{
			new Event("CALL_ERROR_CONGESTION");
			new Event("CALL_DISCONNECTED");
		}
		
		if(causeCode == CallFailCause.BEARER_NOT_AVAIL)
		{
			new Event("CALL_ERROR_CONGESTION");
			new Event("CALL_DISCONNECTED");
		}

Categories: Uncategorized

cx_Oracle module for Python

July 23, 2013 Leave a comment

cx_Oracle is a Python extension module that allows access to Oracle databases and conforms to the Python database API specification. To my experience, it’s a bit challenging to install on Ubuntu (since there is no installer provided, and you have to download the source code and build it yourself. However, for Windows there shouldn’t be any problems. Below is a wrapper class I wrote to make it more convenient to use:


class DbHandle(object):

    """
    A class for handling db operations
    """

    def __init__(self, constring):
        self.constring = constring.strip()
        self.db_connection = cx_Oracle.connect(constring)
        self.cursor = self.db_connection.cursor()

    def execute(self, sqlstr):
        """
        Use for anything other than select statements
        such as insert
        """

        self.cursor.execute(sqlstr)
        self.db_connection.commit()

    def select(self, sqlstr):
        """
        Use only for select statement
        """

        self.cursor.execute(sqlstr)

        return self.cursor.fetchall()

    def close_connection(self):
        """
        Closes the db connection
        """

        self.cursor.close()


Categories: Uncategorized

xlrd package for Python

July 23, 2013 Leave a comment

xlrd is a nice library for python which can be used to read (extract data from) excel (.xls and .xlsx) files. Below is a wrapper class (which I used for a parser project) to make it more convenient to use:

class ExcelFile(object):

    """
    A class that uses the xlrd library to read an excel file with provided
    methods. By default it will read the sheet at index zero.

    Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank
    """

    ignore = []

    @classmethod
    def clean_cell_data(cls, cell_data):
        """
        Clear whitespace and convert to utf-8
        if possible
        """

        try:

            cell_data = cell_data.encode('utf-8')
            cell_data = cell_data.strip()

        except AttributeError:
            pass

        return cell_data

    def __init__(self, file_name, sheet_index = 0):

        self.workbook = xlrd.open_workbook(file_name)
        self.worksheet = self.workbook.sheet_by_index(sheet_index)
        self.num_rows = self.worksheet.nrows - 1
        self.num_cells = self.worksheet.ncols - 1

    def get_all_cells(self):
        """
        Returns all cells in the excel file
        """
        result = []
        curr_row = -1
        while curr_row < self.num_rows:
            curr_row += 1

            curr_cell = -1
            while curr_cell < self.num_cells:
                curr_cell += 1

                # cell_type = self.worksheet.cell_type(curr_row, curr_cell)

                cell_value = self.worksheet.cell_value(curr_row, curr_cell)

                # if cell_value not in self.ignore:

                result.append(cell_value)

        # print result

        return result

    def get_all_rows(self):
        """
        Returns all rows in the excel file
        """

        result = []

        curr_row = -1

        while curr_row < self.num_rows:
            curr_row += 1
            row = self.worksheet.row(curr_row)
            row = [cell.value for cell in row]

            encoded_row = []

            for cell in row:

                cell = self.clean_cell_data(cell)

                encoded_row.append(cell)

            result.append(encoded_row)

        return result

    def get_column(self, index):
        """
        Given the index, return the column of the excel file
        """
        column = self.worksheet.col(index)

        column = [cell.value for cell in column]

        encoded_result = []

        for cell in column:

            cell = self.clean_cell_data(cell)

            encoded_result.append(cell)

        return encoded_result
Categories: Uncategorized

Checking if a file name is valid in C#

July 19, 2013 Leave a comment

C# provides a nice feature for checking if a file name is valid. You can use the method below to check if a file name is valid:

        private bool IsValidFilename(string testName)
        {
            string strTheseAreInvalidFileNameChars = new string(System.IO.Path.GetInvalidFileNameChars()); 
            Regex regInvalidFileName = new Regex("[" + Regex.Escape(strTheseAreInvalidFileNameChars) + "]");

            if (regInvalidFileName.IsMatch(testName)) { return false; };

            return true;
        }
Categories: Uncategorized
Design a site like this with WordPress.com
Get started