Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, June 27, 2010

Exhausted ResultSet

Hi, if you ever encounter this kind of error

java.sql.SQLException: Exhausted Resultset
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.prepare_for_new_get(OracleStatement.java:3195)
at oracle.jdbc.driver.OracleStatement.getIntValue(OracleStatement.java:4264)
at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:510)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1528)



you might guessed that this error happen when you trying to access a resultset which already being closed or never been advanced to the first record, but you very certain that the statement is never been closed or always advanced to the first record and still these kind of error spitting out in your log or console, you might wanna check if the same statement object had been re-executed. In my case another thread executing the same statement object, thus the previous resultset is reset.
  1. thread A is executing the statement and get the resultset X
  2. thread A advance the resultset X by calling X.next()
  3. thread B is executing the statement and get the resultset Y
  4. thread A try to call X.getString("some_field") => spit the error
  5. thread B advance the resultset Y by calling Y.next()
  6. thread B try to call Y.getString("some_field") => working fine

took me whole night figure this one out, should have read the spec earlier, stupid me...

Tuesday, February 10, 2009

User Input From Vim to Python script

hi, ever wondering how to prompt a user for some input from python script within vim, but first make sure you have imported the vim module

def python_input(message = 'input'):
vim.command("call inputsave()")
vim.command("let user_input = input('" + message + " : ')")
vim.command("call inputrestore()")
return vim.eval('user_input')

now everytime you wanna prompt user, in your python script do something like

input = python_input('input something')

it will prompt the user to input something with 'input something' as the caption of the prompt, in the command-line

for more detail

:help input()

hope, this would help.

Monday, January 05, 2009

Easy Remote PHP Debugging with VIM and Firefox

Happy new year !

I've write a post bout how you can setup debugging environment for PHP using xdebug, so now assuming you have xdebug setup and loaded, I'm going to write bout how you actually debug your PHP code.

Basically there are 2 type of debugging, local or remote debugging, the difference is that whether or not the debug engine separated with the debug client. If you debug a desktop Java code using IDE like Eclipse, most likely you are doing local debugging, where as the debug engine comunicate directly to the eclipse interface (there is no need of debug client). XDebug is a remote debug engine, which mean to actually debug some code we need a debug client to send command to and receive debugging information from the debug engine. From XDebug page we can get alot information bout how this can work, and some option of debug client that you can use (this page should be your first reference).

Now lets get to the chase, I'll write about how to have a remote debugging session with Vim (with plugin) and firefox to debug your PHP code easily.
  1. After you have successfully load xDebug module into php, enable remote debugging in your php configuration (php.ini) by adding
    xdebug.remote_enable = "1"
  2. download the debugger plugin (or watch my blog for an update)
  3. extract the file (debugger.vim and debugger.py) to your home vim plugin directory
    $ unzip debugger.zip
    $ cp plugin/debugger.* ~/.vim/plugin/
  4. fire up Vim!, make sure your build equiped with signs and python support or the plugin won't work!, I'm using ubuntu and a Vim-full package for this, no hush, no mush..
  5. if vim loaded without any error it means the plugin already loaded correctly, if not check your vim build, make sure the +signs and +python is there when you type in vim command
    :version
  6. open firefox, and install this addon
  7. open the PHP application you wish to debug using firefox, make sure the source code is accessible. for example if the source is in (assume you are using xampp)
    /opt/lampp/htdocs/testdebug/index.php
    then you can type in firefox url
    http://localhost/testdebug/index.php
  8. click the xdebug helper icon (the one you've just add) on firefox status bar (default on lower right corner), now the icon should flash green
  9. switch to your vim window and press F5 (the message window would say waiting for connection...)
  10. switch to your firefox window and reload by pressing F5,
  11. now switch to your vim window (again) and there you have it, a debugging interface of your application in vim.
let me explain a few of those steps a little bit (step 1 to 7 should be clear enough), step 8 means you have start a debugging session for the next http request, it is the same as if you append the url with XDEBUG_SESSION_START=1 so the url would be
http://localhost/testdebug/index.php?XDEBUG_SESSION_START=1
ofcourse clickin on xdebug helper icon is alot more convenience than appending the url each time we start a debugging session.

now for step 9 we prepare our beloved Vim to wait a connection from the debug engine at this point vim will kind of hang (waiting mode), the script default timeout is 5 second, if within that there are no debugging session requested, vim will return to normal mode. This means than we have to quckly run step 10, switch to firefox and reload, but again make sure the xdebug helper icon is already flash green (activated/clicked). After you have reload the page if you notice the loading status of the page is keep on spinning, the page wont finish loading until the debugging session stopped or vim is closed or request timeout

Now if we switch back to Vim, our debugging interface should up and running there are source, watch, help, stack and trace window. From this interface you can trace the code using F2 (step into), F3 (step over), F4 (step out). To end a session you can press F6. One of most common task is to put a breakpoint in our code, to do that open the file you wish to debug, position your cursor on a line you wish to stop and type :Bp in vim command window, now everytime the debugging session start, just press F5 to run until execution point reach the breakpoint. You can see other debugging command from the help window.

one thing about this vim plugin, there aren't that much debugging command available, either from the plugin or xdebug itself, from what I can tell it is more than enough to do my daily-debugging-basis. There are some lacks though, but I'll address this issue later on, considering this post is already bloated enough to make people sick from reading it :p

happy vimming (and debugging) !

keyword: ubuntu, vim, firefox, xdebug, php

Saturday, November 01, 2008

Vim Easy Folding Tip

for me the most easiest way to use folding in vim is to use
:set foldmethod=indent
intuitive and simple.

when you use foldmethod=indent the folding will be based on indent (why of course :p), meaning the fold start and fold end is marked by line indentation (can be a tab, spaces, etc..)
and these are the command I use the most.
  • zm : reduce fold level
  • zM : fold level to zero, aka fold'em all !
  • zr : increase fold level
  • zR : fold level to the max, aka remove all fold
  • za : toogle fold open/close on current cursor
  • zA : same as above, but recursively
  • zX : undo previous fold command
what is a fold level ?
the higher fold level means less folded text, the lower fold level means more folded text. Consider this snippet of code
when i used indent as foldmethod, indentation level is a fold level. The higher indentation level would have more foldlevel available on that window, when i type zm, foldlevel are reduce to 1, the line start from
$account->publish($... 
is folded, when I type zm again foldlevel are reduce to 0(this is minimum value), then the line
$docs = new... 
is folded, and so on. And viceversa, when I type zr foldlevel are increased, and the line in coresponding foldlevel is unfolded or opened

what if I dont use indentation in my files ?
u can use manual (the default foldmethod) or marker
:set foldmethod=manual
:set foldmethod=marker
note: that when you tried to open a fold recursively (using zA on a closed fold), it work like the way you expected, but when you tried to close a fold recursively it doesnt(well at least I didn't get it at first). It because zA on open fold, close a fold starting from the cursor as the bottom! not the top!, so how to close fold from the cursor to the bottom/deepest foldlevel, my current workaround is to visually select those region an use zC

find out more bout vim's folding feature..
:help folding
happy vimming !!

Tuesday, October 21, 2008

VIM

Since my migration to linux I've set myself on a quest to find the ultimate text editor (haiiah, lebay :p). well anyway I have my own requirement for such a tool
  • lightweight and fast
  • syntax highlighting and formatting
  • tab-editing
  • auto-complete
  • flexible and configurable (support custom script)
when I'm still using windows, I didnt really pay attention on those criterias, coz most of the time I'm stuck with an IDE(not just a text editor). Komodo, eclipse to name a few. and just lately I realized that most of the tool those IDE provided is less usefull for me(well mostly because some of em isn't free :D), I just need the editor, and yes syntax highlight and formatting is a tempting feature for sure. So I started to googling, to find a good editor which presumably free, been trying this and that, and there it is VIM !.

VIM (Vi IMproved) is a console based / command line editor a charityware wrote by Bram Moolenaar, and available as default in most of linux distro (the silly part is that the whole time the one I'm looking for is right under my own nose yet I'm searching or downloading from various places). With a default plugin gVim (gnome version of vim) load up less than a second in my 1420 inspiron box, whoossh.... It support syntax highlight and formatting for most of programming/scripting language, and my favorite is the omni completion feature, its an auto-complete feature with a dozen of option and preferences to suit my need, it can use a dictionary file or just simply scan a whole directory to find the completion words.

Highly configurable, vim support custom script called vimscript (beside it's support on phyton, perl, and other script), which make it a lot more usefull for many editing purpose, theres a lot of ready made script from it's main site, some of the script I've been using are
  • NerdCommenter, this plugin helps to do any function of commenting and uncommenting, and it support comment for huge number of programming language and script,
  • snippets_emu, this is a wonderfull one, just type few letter and shift+tab(my mapping keys) and boom!the whole snippet of code is there! save a lot of time of typing, you could define your own snippet especially for something you'd type frequently
  • NerdTree, its like an explorer built in the editor, you can browse file and directory from it
  • TagList, you can tag a file of code or a whole directory ( in *nix u can use ctags), and jump between various tag in a file, this is a lot faster than using pageup-pagedown, or scrolling your mouse up and down to go to different section in your file
  • VimTip, for any of you that just start learning vim this plugin is a must!, every day it pops a tip bout what you can do with vim, contributed from various user all over the world.
  • and a lot of any other I cant mention here, I cant thx enough to every of you that develop these vimscript and plugins !
One unique thing about it, is that VIM is a modal-based editor, which means it responds input differently based on its mode(state), for example vim has (from several other modes) input-mode and command-mode, when in input-mode vim behave like any other editor, everything I type is considered as text input, but when in command-mode the typing goes as command, I love it so much coz it allows me to use most of vim's editing function without have to move my finger off my keyboard home keys !!, it makes editing process a lot more efficient!

Gosh, theres a lot of feature and advantage I just wont have enough time and space to tell em all, and yes, every day I always learn something new bout this editor, not so much different with most of you, I'm still a newbie vimmer.

Well, I have admit there are some drawback. The first maybe because of the learning curve, it takes some amount of brain power to at least start editing efficiently, and for me, it kind of hogging my short term memory the first time I learned it(but trust me, its a worthy investment)

until the day I post this, vim development is still going active (thx Bram!!), the last stable version was Vim 7.2, unfortunately it seems ubuntu wont put these updates in the main repo for at least another release cycle, well we can always download the source and compile it for ourself cant we :p

happy vimming !!

Friday, June 06, 2008

java 6 + applet + firefox 2 = hang

fyuuuh...

finally I can get my applet working in firefox,

I'm writing an applet application in my ubuntu box, and here's the first configuration
  • eclipse 3.3
  • jdk1.6.0_03
  • firefox 2.0.0.14
  • sun java plugin 6
I can write, compile and run the applet using applet-viewer built in eclipse, but some how everytime I try to deploy the applet to a web page, and view it with firefox, it crash! even until now I dont know why it crashed, been searching on forum and googling, I didnt find anything sufficient to solve my problem(or just me being dumb).. I was thinking maybe theres something wrong with java6 especially with applets, because not only my applet wont work, applet from another site doesn't work either(I've tried with realapplets).

so, I tried my luck with java5, and here's the second configuration
  • eclipse 3.3
  • java-1.5.0-sun-1.5.0.13
  • firefox 2.00.14
  • sun java plugin 5
I've flush everything related with java6 in my laptop away, and replace it with java5, and ofcourse change the default java build path on my eclipse. I can write it compile it, but can't run it!!, it says

java.lang.UnsupportedClassVersionError: Bad version number in .class

oops, forgot to change the JDK compliance setting on my eclipse from 6.0 to 5.0 (window->preferences->java->compiler), voila, it run :)

if any of you wondering whats the error above, basically because you've build a java program using newer compiler, but running it under older jre. For example you've compiled your program using JDK 1.6, on eclipse, and when you tried to run it with your default jre set to 1.5, then you'll get those error throw at you.

And yes, with java5 I was also able to run applet from another site..
so for now my conclusion is,
don't use java6, if you want to write, or run applet application
I hope they'll fixed it soon..

and just a tip:
when you deploy your applet on web page, if you've put your .class file(s) under a directory inside your web root, don't prefix the code properties of applet tag with "./", or browser will say applet loading failed.
dont use :
<applet code="./control/HelloWorld.class" height="400" width="400"></applet>
instead use :
<applet code="control/HelloWorld.class" height="400" width="400"></applet>

keyword : applet, firefox, java 6 plugin, ubuntu, hang, crashed

Monday, June 02, 2008

NameSpace on PHP 5.3

Yippeeeeeeeeeeeeeeeeeeeeee...

I'm so enormously glad knowing that they going to add complete support of NAMESPACE in php engine !!!

I'm very an organized code kind a guy, and all this time, one of my difficulties on writing application with PHP is because it doesnt support namespace, which in turn giving me a hard time just for thinking their names

what's namespace for ?
my simple view its one way for a programmer to have structured built into application component logically, without have to enforced the code structure phisically (eg. prefixing class name).

for example conventional way to implement code structure in PHP is by using directories and prefix,
I would have such structure

/www
index.php
/protected
/controls
/engine
/manager =>manager related code
mgr_mod.php
mgr_priv.php
/user => user related code
usr_mod.php
usr_priv.php

whats up with the structure above ?
u see, to avoid name conflict I have no other way beside prefixing the class name, and this is annoying me because sometime I really want the same name for those classes(eg. mgr_mod.php and usr_mod.php should just be mod.php), because actually they doing the same thing but on different domain, --apart from Generality/specialties design concept because some time I'd like to "break the rules" :p --

why so, they are in different directories right ?
yes, that doesnt mean their logically in different places(this where namespace concept come up), because the whole application is a single namespace(well, actually there are no namespace at all) so even I've put those classes on different directories, their name musn't be the same, or PHP will throw an exception that said you have declared xx class more than once...

with namespace i could simplify my class naming (this is what i thought)

/www
index.php
/protected
/controls
/engine
/manager
mod.php
priv.php
/user
mod.php
priv.php

in mod.php for manager i would have
namespace Manager;
class mod {
...
}

and in mod.php for user I would have
namespace User;
class mod {
...
}

in modern Object Oriented Language, we have package for java, and namespace for .net (is it just me, or .net is "inspiring" php alot ??)
ofcourse, this isnt the only improvement that comes with 5.3 engine, but this is what thrill me the most..

well, actually I dont have time to test it, just got this info from http://ilia.ws, and theres a big probability that I've miss :p,
another reason is PHP 5.3 isnt in stable release yet, still you can get it from http://snaps.php.net/


cant wait till it stable..

Sunday, April 27, 2008

MVC

one of the most popular architecture to be used in web development is MVC, yes because the simplicity of it's design which concentrate on how to separate responsibility between each logical part of the system, makes it easy to develop a system in the scale of enterprises. There are three main part of the system that implement MVC design.

Model, why didnt they call it VCM, or CVM, or VMC, etc.. why model first? in my perspective its because the whole thing that make our application work as expected is in the Model, this is our business logic lies, most people prefer it as domain model, this is where we'd play so many entity/business objects based on it's business rules in conjunction to the model functionality. A good model is a coherent one, which concentrate on specific functionality of system. MVC doesn't say much bout statefullnes of model, but in my experiences almost all of my model is statefull, meaning that it store information about what its doing now, what it have done before, and (probably) where it'll going.. -CMIIW-

Controller, most of the time controller is smaller than model or view, why? because its sole responsibility is to do simple validation on the request, determine what model should serve that request, load up the model, and hand off everything to the presentation layer(view) to render the result. Even though, it doesn't mean it will be simpler than any other part, and if you just start learning, theres a big probability that you'll mixed up with controller concept in event-driven-programming(I'll write about it later..), this part doesnt have logic in them, but depends on its design it may have to acquire some knowledge bout list of available views and models. There are several pattern to implement a Controller, some of them are Front Controller pattern, and Page controller pattern, Front controller is widely used by most of GUI framework these days where theres only a single controller to handle every request. And Page controller is a basic concept of controller in most of web application even those that didn't use MVC architecture.

VIEW, finally this is the part where all eyes will look(literally). it can be simple, but it can be even more complicated than model, depends on what kind of application we're tryin to make. personally i get frustated with this part a lot, well I'm no designer :). The idea is factor out gui-unrelated code as much as possible from it, so the change from the view will hardly effecting the model/business model, but the change from model may still affecting the view(think about it..).

well, thats about 13minutes typing on the fly, and I'm sure there are lot of typo there. Its based on what I've done before and frankly I'm still in learning, just writing it down as is, and in the future I'd know what i've been missing :)

Wednesday, March 05, 2008

Missing days..


Did you know that there are dates that didnt exist ?


For example, there are no dates in year 1752 between Wednesday september 2nd and Thursday 14th in britain. People call this the cutover, it happen when a country decide to switch from Julian to Gregorian calendar, and they have to discard at least 10 days. The first switch happen in 1952, below is the October's calendar of that year











mondaytuesdaywednesdaythursdayfridaysaturdaymonday
1234151617
18192021222324
25262728293031

actually days never missing, its just dates (cant stop thinking bout the people born in those day).The interesting part is, if more than one country switch calendar at the same time, the more days were lost o.O For Indonesia we already use Gregorian Calendar since the proclamation.


You must be thinking i got this info from some website like wiki, or just googling it. Nope! I just read Mysql manual! (lho kok jadi nyambung ke database? Kapan seh gw iseng sengaja nyari info beginian^^)


Yup, mysql engine uses calendar called Proleptic Gregorian Calendar for their DATE or DATETIME values, which assume there are no such event called cutover, for this reason every dates prior the original cutover must ajjusted ie. for russian minus 13 days.


Correct me if i'm wrong, havent read any other reference regarding this, just got really stuck with my insertable view T_T (someone please show me how to work with these brats!)


Sunday, February 24, 2008

Object Oriented Programming Language, java?

Berdasarkan tulisan temen, bahwa java bukan bahasa pemrograman yang mendukung object oriented murni, jadi gw nulis ini.
Klo dilihat dari kata-katanya 'mendukung object oriented murni', sebenernya g salah klo kita bilang java 'mendukung' object oriented murni. Karena klo kita mau, bisa saja kita menggunakan konsep OO murni untuk program kita, misal tidak menggunakan tipe2 primitif melainkan menggunakan kelas, atau tidak menggunakan operator-operator dasar melainkan method-method dari operand-nya.
Tapi setelah ditelaah lebih dalam, dan dari hasil googling, gw tiba pada suatu kesimpulan, dimana yang dimaksud object oriented murni adalah, suatu bahasa yang tidak memperkenankan adanya 'pencemaran' terhadap konsep 'everything is object', sementara java masih memperkenankan hal tersebut seperti penggunaan tipe-tipe dasar tadi.

Sekedar gambaran, dalam java :


/*convert to string*/

System.out.println(-1.toString());




jadi compile-error, soalnya java mengevaluasi -1 sebagai nilai literal, bukan object, tapi klo dalam ruby:


#convert to string

puts -1.to_s()



g jadi masalah karena, -1 dievaluasi sebagai instance dari kelas Integer

ok, coba gw break down, dari level dukungannya terhadap OOP, bahasa pemrograman bisa dikategorikan:
  1. Pure support, dimana seperti yang telah disebutkan tadi, bahasa-bahasa yang tidak memperkenankan pencemaran, bahasa ini antara lain adalah SmalTalk, Ruby, walaupun gw blm pernah nyoba ampe dalem, bahasa tersebut(cuma sebates helloworld ^^), tapi seh kata om google begitu...
  2. Full/Complete support, nah ini bahasa yang paling populer jaman sekarang, khusus didesain untuk OOP, seperti java, c#, dll. bahasa ini bisa menerapkan semua konsep dan karakteristik OOP(kalau si-programmer yang bersangkutan mau) Namun masih menyediakan dukungan terhadap paradigma konvensional.
  3. partiall support, untuk kategori ketiga ini sebenernya masih bisa dibreak down lagi, but for me they all look the same ;). umumnya bahasa-bahasa yang terkenal dalam paradigma prosedural, namun seiring dengan perkembangan teknologi, bahasa ini dikembangkan untuk bisa mendukung OOP, seperti C++, PHP, Fortran, Perl dll
  4. No support, yup, ini adalah bahasa pemrogaman yang bener-bener g bisa dipake OOP, umumnya bahasa seperti ini masih populer dikalangan akademik untuk dijadikan materi pembelajaran. yg bisa gw pikirin sekarang cuma pascal, dan assembly

hmm, kira-kira gitu, skali lagi klasifikasi diatas itu based on my perspective, klo misal ada yg mo nambah ato ngoreksi, i'm open :)