Git Workflow
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.
Oracle 11g PL/SQL: Getting Turkish name for a month
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.
Website for looking up various Software Licenses
This website will provide you summarized information about various software licenses used in the industry. Comes handy especially for open source project licenses.
Setting up an Android device for debugging (with an IDE)
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
Play Framework – eclipsify problem
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:
- org.scala-sbt#sbt;${{sbt.version}}: not found on existing project (http://stackoverflow.com/questions/16896796/org-scala-sbtsbtsbt-version-not-found-on-existing-project)
- An error like “eclipse is not a valid command”
You can give these a try in order to solve the problem:
- Make sure you have the latest version of play framework
- 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)
Xcode : lipo-error-cant-open-input-file
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
Creating a RadioLog Listener in Android
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");
}
cx_Oracle module for Python
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()
xlrd package for Python
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
Checking if a file name is valid in C#
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;
}
