altctrl 0.7

Posted in javascript on April 29th, 2009 by gmunteanu

in this version [update: latest here], you can be on any page, and if you see the product model number, you can select it, right click, and click on the ALTCTRL item. it will search for the prices on the romanian stores.

also, now i have separated the data from the main code, and it is downloaded from my domain e-forum.ro, evaledinsandbox, and processed. this way, if i add another store, you won’t need to download the extension again. below you can see a screenshot of it in action.

also, some minor bug fixes, especially for esal. good, back to work.

altctrl 0.6

Posted in javascript on April 24th, 2009 by gmunteanu

UPDATE: if you took it from mozilla website, updates won’t work, you should manually uninstall it and install it again from https://addons.mozilla.org/en-US/firefox/addon/11290.altctrl is still experimental addon, and it needs reviews on the mozilla website in order to go to public state. so if you like it, you can add some review there. [11 have 0.3, 8 have 0.4, 12 have 0.5] and now comes 0.6 version. so please mind this detail when installing.

version 0.6.

you can get the latest here [update: latest here], or you can wait to get it through the addons.mozzila.com website on monday i hope.

done:

  1. added esal.ro
  2. added newegg reviews

to do:
1. sort the rows so that cheapest is at the top, and the not found ones at the bottom
2. fix errors with escape url characters like space and others, especially for esal.
3. add sigmanet.ro
4. move from vbox to XHR, but i doubt it will work.
5. improve caching on the server.
6. make the anonymously cached product info available on a website.
7. move store specific data from client to server, and make it updatable in the xpi.

altctrl detailed description

Posted in javascript on April 3rd, 2009 by gmunteanu

UPDATE: if you took it from mozilla website, updates won’t work, you should manually uninstall it and install it again from https://addons.mozilla.org/en-US/firefox/addon/11290.altctrl is still experimental addon, and it needs reviews on the mozilla website in order to go to public state. so if you like it, you can add some review there.

so, you want to get the best deal on products from romanian online stores. install the extension from the link shown in the previous post, and then the magic happens.

User guide: after you install it, there should be a statusItem at the right bottom of firefox , on the status bar. it should read altctrl. go to any of the 5 .ro online stores, and get to a product detailed page. then if you are not happy with the price, or you just want to check the other prices, click on the altctrl statusItem, and a popup will appear. it will go to the other stores and get the prices if it finds them. if not, “##” is shown. if an error occurs “**” occurs. The color of the row where each store is shown also has a meaning: green for “in stock” and red/brown for “out of stock”. if you wait too much for a store to show the price, you can cancel it from the right-most button.

Hacker guide: the internal of the extension is  simple. in a XUL iframe, i placed 5 browser objects with images and js disabled. upon click event, the product code on the page is taken , and a search is initiated on the other websites in the browsers we have already. the result pages is parsed with Sizzle and shown in the popup. in order not to stress the store web servers too much i also cache the results on my server at http://www.e-forum.ro:8080/altctrl . more info you can get by studying the code. it is released as gnu-gpl version 3. have fun!

firefox extension for comparing prices for romanian online stores

Posted in java, javascript on December 24th, 2008 by gmunteanu

UPDATE: if you took it from mozilla website, updates won’t work, you should manually uninstall it and install it again from https://addons.mozilla.org/en-US/firefox/addon/11290.altctrl is still experimental addon, and it needs reviews on the mozilla website in order to go to public state. so if you like it, you can add some review there.

you can take it from here:

altCtrl [if you have mozilla account] or from my server here [update: latest here]

info: i have included 4 ,5 stores untill now: emag.ro,pcgarage.ro, evomag.ro, marketonline.ro, dc-shop.ro  , more will come as time permits. after you install it, you go to a store, browse to a product page, and click on altctrl statusBarItem you see on the right of your status bar. a div will appear with the prices from the other stores. if the row is green, then the product is available, red means otherwise. it is still in alpha stage, but it is usable. anyway nobody reads this blog , and i will tell only my friends about this post, so this release should be called friendly beta.

enjoy and save some money with this economic crisis .

bomberman javascript multiplayer

Posted in javascript on October 22nd, 2008 by gmunteanu

this post is a documentation briefing about the project that runs here:
http://www.e-forum.ro:8080/dynagame/index

In order to provide the platform for users to play against users bomberman online, we have to :
1. create the possibility that a user can create a game, or join a game created by others
2. we must let the user choose the variant of the game he wants to play, or let him customize the game
3. the game can be customized in different ways: max number of players, filter the users that can play the game, arrangement of the rocks , with or without monsters, time limit or not, with powerups or not, etc …

Architecture::
we have a GamesContainer that hold all the games.
when a user cretes a game, you add it to the GamesContainer.
you can retrieve a game from it by providing the id of the game.
you can also obtain a list of all games on the server.
a game is represented by the Game class.
it has an id, which is a number autogenerated, and incremented by 1 , and starts from 1 upon every restart of the servlet container.
a game has a status, it has a creator, players, viewers.
it also has a map, with rocks and walls, and powerups, and monsters.
the game class must be able to transmit that to the browser, so that the js code can paint the map.

Communication done to assure the game can be played by users across the internet.
the philosophy:
the first client sends a request to the server in order to create the game.
then, the other players will just join the game, so their first request will be to join the game.
this is done by providing 2 links:
1. create new game and
2: a page with all active games existing on the server and a small status on those games: how many number of players are in that game.
upon first request they must tell the server the following info:
- username
- gameid : null if the game is to be created, or an int X the gameid already existing on the server.
- in case game is to be created, properties of the game are to be sent if the user wants to customize the game
- number of cols and rows, monsters yes or no, powerups yes or no, etc … , arrangement of fake walls
The server does the following upon getting the initial request:
- it locates the game / creates a new one
- adds a new player to the game -
it positions the new player so that in doesn’t stands on a wall, and safely away from the other players.
The server responds upon initial request with: – the game arrangement: walls, powerups, players’ positions and attributes, etc…


Game ideas:
1. a game map huge, where anybody can join and kill other real players.
2. players can team up, and teams can play against players or other teams.
Technical observations:
1. the http header the browser and the server are sending must be reduced drastically, in order to have a packet sent through the wire as small as possible, like in the tcp socket based games.
2. there will be 2 connections: one long polling connection , that will wait for the server to send some info based on an event generated by the other players and another one that will go with a request to the server informing that this player just generated an event. the events here are 6, all keyboard type:
4 arrows [keydown event]
keyup event [meaning stop any movement]
and space – bomb launch.
these key events generate game events and act on the character and through the server on the character on the other web pages related to this game.
3. the client code will adjust the positions of the other players and other state variables [fakewall destroyed, speed increased for player X] according to the server. the server sends state [ex: x,y of players] + the state counter, and the client game takes that info into account if and only if server state counter > last server state counter applied. the real process should be like this: any client page, has a game with 1 character [its hero] controlled by the user and X other characters controlled by the server [actually other players]. the code on this page is master reference for the hero, and the server listens to this code about the hero; and the other code on other client’s pages listen to the server about this hero state. the game running on every page has a stateCounter, and the server game object has one too. when an user generates an event , the eventCode [ keyCode in my implementation] is sent to the server + the hero’s state [x,y for now]. this info, generates an event on the server, and all other requests that are suspended by jetty’s continuation mechanism are resumed, and the hero’s info is sent to the other players’ browsers. this way , the eventCode reaches all web pages linked to the game, and the js code takes care of acting on characters. if the state is not the same as the one on the server, then the js code adjust it. this usually happens not only because of network delays but mainly by the fact that setInterval doesn’t execute the same on all machines , unfortunately.
4. when one sends messages too fast [fast arrows changing in the game] , the others do not have time to reconnect to get subsequent messages. for this, a stack of events for these things will be created on the server, and the whole series of events gets sent upon reconnection of the interested parts.

my first gnu/gpl project – a game in javascript

Posted in javascript on July 4th, 2008 by gmunteanu

it is a clone of bomberman, or dyna blaster if you know the game by that name and you can find the latest developments here:
http://code.google.com/p/js-blaster/

i welcome members that can help me make this game return in glory :) .

struts and continuations in jetty

Posted in java on May 25th, 2008 by gmunteanu

we have a web application at work, that updates a web page comet style.

it is running on tomcat.

the update is done based on some events from a backend application, and the connections are kept open for a long time, untill the event triggers the update.

we had the 1 thread per connection situation and as the traffic grew, we had to make a change.

tomcat had an event based comet model, and i couldn’t make it work.

so i switched to jetty and its continuation thing.
in jetty, the principle is that an Exception is thrown, and then the connector catches it and frees the thread, retruning it to the pool so it can be reused for other requests.

But, my application was a struts one, and i had the suspend() call inside an Action.
after many tries, all my efforts made the examples i found on the net work perfectly, but my app didn’t.
all it did was to spit the retryrequest runtime exception in the web page.
finally , the trick was that ProcessRequest class in the struts stack was throwing all exceptions that occured in the Actions like this:
throw new ServletException(exception) , and the SelectChannelConnector in the jetty stack couldn’t get its hand on its retryRequest exception.
so i changed the ProcessRequest class, so that RetryRequest exception is skipped, and all was great.
so, in order to make jetty’s continuations work with struts stack you have to be aware of this RetryRequest  runtime exception to be thrown exactly as it is in the struts stack and not wrapped in the ServletException.

gftp and gvim as the editor

Posted in sysadmin on January 24th, 2008 by gmunteanu

i set gvim as the editor in the preferences of gftp.
the problem was that, when saving and exiting gvim, the file was removed from the temp folder, but was not uploaded back on the server.
this used to work with gedit.
a search on google took me to a post where a guy had the same problem as me, but no answer.
a man vim solved it.
it says there that gvim detaches itself from the shell , so gftp won’t see any exit code when you close gvim.
all i did was putting /usr/bin/gvim –nofork in the editor field.
voila!

get rid of class information from logging

Posted in java on July 8th, 2007 by gmunteanu

if you want to remove class and method information line when you do logging with java.util.logging , then you have 2 choices:
1. subClass your handler and make your own publish method
or
2. subClass the formatter you pass to the handler and modify the format(LogRecord record) method.

i did the second one.
here it is:
public String format(LogRecord lr){
                           return lr.getMessage()+"\n";
                   }

using vim instead of sed

Posted in Bash on February 2nd, 2007 by gmunteanu

in order to process a text file in any sense, and being used with vim, and not with sed
i use the following for deleting googlebot lines from a web log.

vim -e -c ":d/googlebot/g" -c :wq website.YYYYMMDD.log
-e doesn’t put vim in interactive mode, so you can script it and put it in crontab.

or if you need to pipe it:

cat website.YYYYMMDD.log | vim – -e –c ":d/googlebot/g" -c :wq

maybe i will add more vim issues as comments to this post.