Tuna Töre

> IOC Advocate, Coder

Good example/document for Correlated subquery


You can check the following page for Correlated Subqueries

Especially update query

https://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fsqlp%2Frbafyexsub4.htm

basic syntax

UPDATE TABLE_NAME X
SET FIELD=(SELECT Y.ANYFIELD
FROM ANOTHERTABLE Y
WHERE X.ID= Y.FID)
WHERE X.ID IN (SELECT FID
FROM ANOTHERTABLE)

UPDATE EMPLOYEE X
SET NEWSALARY=( SELECT Y.NEWSALARY
FROM SALARIES Y
WHERE X.EMPID = Y.EMPID)
WHERE X.EMPID IN ( SELECT EMPID
FROM SALARIES)

29/01/2014 Posted by | Oracle, Oracle SQL | Leave a comment

Android Development Tools for Eclipse book review (packt publishing)


Today, I finished reading ADT for Eclipse book;

In my opinion, if you are new for the Android Mobile Dev. Platform, you should consider reading this book.

In total, this book includes 144 pages so it is very easy to read. Authors did very good job by summarizing important subjects into one small sized book.

You will find essential details regarding ADT and this will enables you to code and publish your mobile apps.

Pros Regarding the book;

+Concise and clear explanations
+Including screenshots
+Relevant content

Cons

+Could include more chapters regarding Android Virtual Device optimization
+Some screenshots are based on Windows others for Linux

You can review the chapters of the book by clicking the following link;

 Reading Android Development Tools for Eclipse Book  Reading Android Development Tools for Eclipse Book

17/10/2013 Posted by | Android | Leave a comment

What happens if JAVA is terminated


17/10/2013 Posted by | Java | Leave a comment

Android FREE PhotoSync App (Facebook&Dropbox)


Hi bloggers,

Here you can find a FREE Android App developed by me;

PhotoSync

Click on this link to download

https://play.google.com/store/apps/details?id=air.com.ttore.AutoPhotoPublisher&hl=en

Product Description;
Using this app you won’t worry publishing your photos to Facebook and/or DropBox together.
This mobile app will publish your photos based on your interaction(manual publishing mode) or automatically (auto publishing mode) to Facebook and/or DropBox.Auto publishing Mode will give you the power of syncing your photos on two different platforms (Facebook and DropBox) at the same time. In order to do that you just only need to connect your accounts to this app and publishing will be handled automatically. This way for example while you are travelling and taking some nice cool photos, social publishing will be done on Facebook and one copy is also saved in DropBox.

Functions;
Facebook/DropBox connection
Auto Photo Publishing to Facebook&DropBox
Manual Photo Publishing to Facebook&DropBox

Connecting DropBox;
Please select remember me in order to prevent connection problems.

09/10/2013 Posted by | Android | , | Leave a comment

How to speed up Android Emulator on Eclipse (emulator: Failed to open the HAX device! solution)


This tutorial will guide you to speed up Android Emulator by installing Intel Hardware Accelerated Execution Manager (HAXM)

Problems;
–Slow Emulator speed on Eclipse (actually very very slow for debugging)
–emulator: Failed to open the HAX device! HAX is not working and emulator runs in emulation mode,  emulator: Open HAX device failed solution

In order to use x86 Android Intel Emulator, first of all download the image using Android SDK Manager

Open Eclipse click on SDK Manager Button

asdkm

Choose Intel x86 Atom System Image and press install

androidx86intel

After this you need to install HAXM as well;

haxm

After installing Intel x86 Emulator Accelerator, you need to go installation folder and execute manually  HAXM executable (Install Package is actually here misleading, you can think it as downloading) alternate download link;

http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager

Go to the following folder (replace your username on your computer)

andhaxmfolder

Run IntelHaxm.exe

haxm1

Press Next

haxm2

Set RAM size, you can choose default value and click yes

After the installation, you should open command prompt for testing whether HAXM is running on computer try the following command
if you see RUNNING state, HAXM installation is successful.

haxmfinal

So in order to use the fastest Intel x86 Emulator, you should define a new emulator in Eclipse by opening Android Virtual Device Manager
and setting the following parameters;

First open it  by clicking  avdmbut

AVDM

Under Device Definitions, choose Nexus S and press create AVD
In this section, choose Intel Atom (x86) for CPU/ABI and this will activate HAXM
and your emulator will be faster

eavdm

After completing these steps; by running your application you will see a console like as below;

[2013-09-02 19:51:12 - Hello] ——————————
[2013-09-02 19:51:12 - Hello] Android Launch!
[2013-09-02 19:51:12 - Hello] adb is running normally.
[2013-09-02 19:51:12 - Hello] Performing com.example.hello.MainActivity activity launch
[2013-09-02 19:51:13 - Hello] Automatic Target Mode: Preferred AVD ‘AVD_for_Nexus_S_by_Google_With_x86′ is not available. Launching new emulator.
[2013-09-02 19:51:13 - Hello] Launching a new emulator with Virtual Device ‘AVD_for_Nexus_S_by_Google_With_x86′
[2013-09-02 19:51:14 - Emulator] emulator: device fd:1268
[2013-09-02 19:51:14 - Emulator]
[2013-09-02 19:51:14 - Emulator] HAX is working and emulator runs in fast virt mode
[2013-09-02 19:51:15 - Emulator] creating window 0 0 438 729
[2013-09-02 19:51:15 - Hello] New emulator found: emulator-5554
[2013-09-02 19:51:15 - Hello] Waiting for HOME (‘android.process.acore’) to be launched…
[2013-09-02 19:51:52 - Hello] HOME is up on device ‘emulator-5554′
[2013-09-02 19:51:52 - Hello] Uploading Hello.apk onto device ‘emulator-5554′
[2013-09-02 19:51:54 - Hello] Installing Hello.apk…
[2013-09-02 19:52:47 - Hello] Success!
[2013-09-02 19:52:47 - Hello] Starting activity com.example.hello.MainActivity on device emulator-5554
[2013-09-02 19:52:48 - Hello] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.hello/.MainActivity }

References;

http://software.intel.com/en-us/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-microsoft
http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager

02/09/2013 Posted by | Android | , | 1 Comment

How to install Android Eclipse Plugin and start coding immediately (Android Virtual Device Definition- Android SDK)


Hi, in this short tutorial, we are going to install Android Development Plugin (which is called ADT (Android Development Tools)) on Eclipse briefly.

First of all, to do that please download Eclipse from the following location;

1. http://www.eclipse.org/downloads/

2. When you start Eclipse choose

install_new_soft

Copy and paste Work With location

https://dl-ssl.google.com/android/eclipse/

and press add like this;

adt_lib_select

Click Next for downloading and accept license agreement. After the installation, you need to restart your eclipse in order to start programming Android apps.

3. You need to define the location of Android SDK Tools inside eclipse to start coding, for that reason, you need to download Software Development Kit including the main functionalities, libraries of Android, for doing that go to http://developer.android.com/sdk/index.html
under use existing IDE menu choose download the sdk tools for windows

4. After the download, click on the exe file choose a sdk installation location (we will use this location later inside eclipse)

and_sdk_loc

Click next and on SDK Manager click install all (in my case 11 packages)

Please note SDK Path will be used inside Eclipse so it is better to note somewhere for me it is under C:\Users\tunato\AppData\Local\Android\android-sdk

AND_SDK_MAN

This will take some time so be patient. Press close after all downloads are completed.

5. Before coding Android apps using Eclipse, you need to set the location of Android SDK on Eclipse for that;

Window>Preference>Android

inside SDK Location choose your sdk installation directory for me C:\Users\tunato\AppData\Local\Android\android-sdk

press apply and ok and now you are ready to code Android

android_sdk_loc_eclipse

6. For testing the android SDK installation, we will now  define a AVD which is called as Android Virtual Device and this device will use Android API

Click on Window > Android Virtual Device Manager or Android DM button on the left

AVD

Select the following values by setting AVD Name, Device, Target and CPU click ok and this will create our virtual Android Device and we will use this device for testing our apps

avdconf

To test our configuration including SDK installation and AVD definition click on

File>New>Other and choose Android Sample Project
Select HellowEffects sample android project from list;

ps

Click on Finish;

Right click on HelloEffects sample app

sampleapp

Click on Run as Android Application and this will open Android Virtual Device, (if it fails try to decrease AVD ram values by decreasing RAM values)

You have to be patient while the initialization of AVD. This will take some time for the first time,

On Android Virtual Device app menu  click on FX HelloEffects 

vd

And after clicking you will see a screen like that so the application works!!

vd2

Emulator Console log will be similar to this one;

[2013-08-30 11:12:55 - SDK Manager] Updated AVD ‘AVDTEST’ based on Android 4.3, Intel Atom (x86) processor,
[2013-08-30 11:12:55 - SDK Manager] with the following hardware config:
[2013-08-30 11:12:55 - SDK Manager] hw.sdCard=no
[2013-08-30 11:12:55 - SDK Manager] hw.device.manufacturer=Google
[2013-08-30 11:12:55 - SDK Manager] hw.mainKeys=no
[2013-08-30 11:12:55 - SDK Manager] hw.lcd.density=320
[2013-08-30 11:12:55 - SDK Manager] hw.accelerometer=yes
[2013-08-30 11:12:55 - SDK Manager] hw.dPad=no
[2013-08-30 11:12:55 - SDK Manager] hw.device.hash=298918422
[2013-08-30 11:12:55 - SDK Manager] hw.trackBall=no
[2013-08-30 11:12:55 - SDK Manager] hw.device.name=Nexus 4
[2013-08-30 11:12:55 - SDK Manager] hw.camera.back=none
[2013-08-30 11:12:55 - SDK Manager] hw.sensors.proximity=yes
[2013-08-30 11:12:55 - SDK Manager] hw.battery=yes
[2013-08-30 11:12:55 - SDK Manager] disk.dataPartition.size=200M
[2013-08-30 11:12:55 - SDK Manager] hw.gpu.enabled=yes
[2013-08-30 11:12:55 - SDK Manager] hw.audioInput=yes
[2013-08-30 11:12:55 - SDK Manager] hw.sensors.orientation=yes
[2013-08-30 11:12:55 - SDK Manager] hw.camera.front=none
[2013-08-30 11:12:55 - SDK Manager] hw.gps=yes
[2013-08-30 11:12:55 - SDK Manager] skin.dynamic=yes
[2013-08-30 11:12:55 - SDK Manager] hw.keyboard=yes
[2013-08-30 11:12:55 - SDK Manager] vm.heapSize=64
[2013-08-30 11:12:55 - SDK Manager] hw.ramSize=768
[2013-08-30 11:13:49 - HelloEffects] ——————————
[2013-08-30 11:13:49 - HelloEffects] Android Launch!
[2013-08-30 11:13:49 - HelloEffects] adb is running normally.
[2013-08-30 11:13:49 - HelloEffects] Performing com.example.android.mediafx.HelloEffects activity launch
[2013-08-30 11:13:49 - HelloEffects] Automatic Target Mode: launching new emulator with compatible AVD ‘AVDTEST’
[2013-08-30 11:13:49 - HelloEffects] Launching a new emulator with Virtual Device ‘AVDTEST’
[2013-08-30 11:13:51 - Emulator] emulator: Failed to open the HAX device!
[2013-08-30 11:13:51 - Emulator] HAX is not working and emulator runs in emulation mode
[2013-08-30 11:13:51 - Emulator]
[2013-08-30 11:13:51 - Emulator] emulator: Open HAX device failed
[2013-08-30 11:13:51 - Emulator]
[2013-08-30 11:13:51 - Emulator] emulator: warning: opening audio input failed
[2013-08-30 11:13:51 - Emulator]
[2013-08-30 11:13:51 - Emulator] creating window 0 0 513 854
[2013-08-30 11:13:51 - HelloEffects] New emulator found: emulator-5554
[2013-08-30 11:13:51 - HelloEffects] Waiting for HOME (‘android.process.acore’) to be launched…
[2013-08-30 11:14:41 - HelloEffects] HOME is up on device ‘emulator-5554′
[2013-08-30 11:14:41 - HelloEffects] Uploading HelloEffects.apk onto device ‘emulator-5554′
[2013-08-30 11:14:42 - HelloEffects] Installing HelloEffects.apk…
[2013-08-30 11:15:13 - HelloEffects] Success!
[2013-08-30 11:15:13 - HelloEffects] Starting activity com.example.android.mediafx.HelloEffects on device emulator-5554
[2013-08-30 11:19:04 - Emulator] Error accepting connection, aborting

So you can continue from now to develop your custom apps with this configuration!!

T.T

30/08/2013 Posted by | Android, Eclipse | , , , | Leave a comment

How to kill processes on Windows backend


taskkill command is what you looking for;

first try with tasklist after

C:\Users\tunatore>tasklist

Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 24 K
System 4 Services 0 984 K
smss.exe 428 Services 0 68 K
wininit.exe 656 Services 0 116 K
services.exe 720 Services 0 7,768 K
lsm.exe 792 Services 0 3,136 K
Excel.exe 892 Services 0 93,136 K

After learning the process name just apply the following command
/im stands for image name “*” wildcards are also supported
/f stands for forcing
/t terminates child processes as well

C:\Users\tunatore>taskkill /f /im Excel.exe /t

more details

taskkill /?

26/08/2013 Posted by | Windows | | Leave a comment

Python itertools example source code



'''
Created on Aug 3, 2013

@author: tunatore
'''

#python itertools examples
#Functions creating iterators for efficient looping
#refer to http://python.readthedocs.org/en/v2.7.2/library/itertools.html

from itertools import *

#count 
#counter starting from 1 to infinite 
for i in count(1):
    print (i, " ",  end="")
    if (i==15):
        break        
#1  2  3  4  5  6  7  8  9  10  11  12  13  14  15 
print ("\n")

#counter starting from 1 (increment with 5) to infinite
for i in count(1,5):
    print (i, " ",  end="")
    if (i>=50):
        break    
#1  6  11  16  21  26  31  36  41  46  51  

print ("\n")

#cycle
c = cycle("TUNA")
for i in range(12):
    print (next(c), end="")

#TUNATUNATUNATUNATUNATUNA

print ("\n")

#repeat
for i in repeat('python', 4):
    print (i, end="")

#pythonpythonpythonpython

#chain
print ("\n")
list1 = ['Test1','Goose','Bison','Pelican']
list2 = ['Cat','Dog','Elephant','Bird','Tiger','Lion','Rabbit']
print ([i for i in chain(list1,list2)],"\n")
#['Test1', 'Goose', 'Bison', 'Pelican', 'Cat', 'Dog', 'Elephant', 'Bird', 'Tiger', 'Lion', 'Rabbit']

#compress
print ([i for i in compress('TUNATORE', [1,1,1,1,False,False,False,0])],"\n")
#['T', 'U', 'N', 'A']
#or
print ([i for i in compress('TUNATORE', [0,0,0,0,1,1,1,1])],"\n")
#['T', 'O', 'R', 'E']

#dropwhile (starts when prediction fails)
print ([i for i in dropwhile(lambda z: z>3, [9,5,6,7,2,1,4,5,6])],"\n")
#[2, 1, 4, 5, 6]

#takewhile (starts when as long as prediction true)
print ([i for i in takewhile(lambda z: z>6, [9,8,7,6,5,4,3,2,1])],"\n")
#[9, 8, 7]

#filterfalse (z>3 false items will return)
print ([i for i in filterfalse(lambda z: z>3, [9,5,6,7,2,1,4,5,6])],"\n")
#[2, 1]
#or
#filterfalse (z>3 false items will return)
print ([i for i in filterfalse(lambda z: z<3, [9,5,6,7,2,1,4,5,6])],"\n")
#[9, 5, 6, 7, 4, 5, 6]

#isslice
print([i for i in islice('tuna',2)],"\n")
#['t', 'u']
print([i for i in islice('tuna',2,3)],"\n")
#['n']
print([i for i in islice('tuna',0,None)],"\n")
#['t', 'u', 'n', 'a']

#zip_longest
print([i for i in zip_longest('tntr','uaoe',fillvalue='')],"\n")
#[('t', 'u'), ('n', 'a'), ('t', 'o'), ('r', 'e')]

#product for cartesian
print([i for i in product('tuna','tore')],"\n")
#[('t', 't'), ('t', 'o'), ('t', 'r'), ('t', 'e'), ('u', 't'), ('u', 'o'), ('u', 'r'), ('u', 'e'), ('n', 't'),
#('n', 'o'), ('n', 'r'), ('n', 'e'), ('a', 't'), ('a', 'o'), ('a', 'r'), ('a', 'e')]

#permutations
print([i for i in permutations('tuna',4)],"\n")
#[('t', 'u', 'n', 'a'), ('t', 'u', 'a', 'n'), ('t', 'n', 'u', 'a'), ('t', 'n', 'a', 'u'), ('t', 'a', 'u', 'n'),
# ('t', 'a', 'n', 'u'), ('u', 't', 'n', 'a'), ('u', 't', 'a', 'n'), ('u', 'n', 't', 'a'), ('u', 'n', 'a', 't'),
#('u', 'a', 't', 'n'), ('u', 'a', 'n', 't'), ('n', 't', 'u', 'a'), ('n', 't', 'a', 'u'), ('n', 'u', 't', 'a'),
#('n', 'u', 'a', 't'), ('n', 'a', 't', 'u'), ('n', 'a', 'u', 't'), ('a', 't', 'u', 'n'), ('a', 't', 'n', 'u'),
#('a', 'u', 't', 'n'), ('a', 'u', 'n', 't'), ('a', 'n', 't', 'u'), ('a', 'n', 'u', 't')]

#groupby
#useful itemgetter import
from operator import itemgetter

salesByDay =  [('20130101', 35), ('20130101', 25) ,('20130102', 35), ('20130101', 40), ('20130103', 66) ,('20130103', 66), ('20130102', 44)]

#keys have to be sorted
sortedSalesByDay = sorted(salesByDay, key=itemgetter(0))
for key, values in groupby(sortedSalesByDay, itemgetter(0)):
    print ("Day:",key)
    for value in values:
        print ("Value ",value[1])

# Day: 20130101
# Value  35
# Value  25
# Value  40
# Day: 20130102
# Value  35
# Value  44
# Day: 20130103
# Value  66
# Value  66

03/08/2013 Posted by | Python | , , , , , , , , , , , , | Leave a comment

Python decorators example source code


Here you can find an example for Python Decorators
summary of content;

built-in decorators
usage of before and after decorator
modifying returning function

'''
Created on Aug 2, 2013

@author: tunatore
'''

#decorators are similar to Aspect Oriented Programming in JAVA 
#They have the ability to run after or before any function 
#decorators are applied with @character
#you can use built-in decorators such as @staticmethod

class Hello():
    @staticmethod
    def f():
        return "Hello"
    
print (Hello.f())

class HelloInstance():
    def f(self):
        return "Hello from Instance"

#the following won't work    
#print (HelloInstance.f())    
#you should try

hwi = HelloInstance()
print (hwi.f())


class User:
    """User class"""
    id = 1234567890
    name = "tuna"

#CHANINED decorators    
def trace(f):
    def newFunc(): #any def method name is allowed such as new,newFunc or wrapper ..
        print ("tracing..")
        f() 
    return newFunc

def storelastlogin(f):
    def newFunc():
        print ("storing..")
        f()
    return newFunc

@trace
@storelastlogin
def login():    
    print ("user ID: " + str(User().id) + " name: " + User().name)

login()

def beforeAndAfter(f):  
    def newFunc(): 
        print ("before.. is called")
        f() 
        print ("after.. is called")
    return newFunc

@beforeAndAfter
def loginSecond():  
    pass #do nothing
    
loginSecond()
    
#CHANGING LOGIC
def changeFunctionLogic(f):
    def newFunc(*args): #any def method name is allowed such as new,newFunc or wrapper ..
        print ("changing output by multiplying function itself")
        return f(*args) * f(*args) 
    return newFunc

@changeFunctionLogic
def multiplyNumbers(arg1,arg2):
    return arg1 * arg2

print ("Result (2*2) * (2*2) =", multiplyNumbers(2, 2))

output

Hello
Hello from Instance
tracing..
storing..
user ID: 1234567890 name: tuna
before.. is called
after.. is called
changing output by multiplying function itself
Result (2*2) * (2*2) = 16

02/08/2013 Posted by | Python | | Leave a comment

Python getting user input and time usage



'''
Created on Aug 1, 2013
Python version > 3
@author: tunatore
'''
import time

#before python 3 please use raw_input() function instead
#refer to http://www.python.org/dev/peps/pep-3111/

#starting clock
startTime = time.clock()

stars = input('I will print stars tell me any number :')

#printing stars
for j in range(int(stars)+1):
    print ('*'*(j))

word = input('Tell me a word :')

#printing word
for j in range(int(len(word)+1)):
    print (word[j-1]*(j))

#stopping clock
stopTime = time.clock()

print ("You have been using this program for {0} seconds".format( stopTime - startTime))

Output

I will print stars tell me any number :10

*
**
***
****
*****
******
*******
********
*********
**********
Tell me a word :tuna

t
uu
nnn
aaaa
You have been using this program for 4.22824467283872 seconds

01/08/2013 Posted by | Python | , , | Leave a comment

Follow

Get every new post delivered to your Inbox.