How to create rotating wallpapers in Gnome
Posted by Saša Bodiroža | Filed under Linux, Programming, Scripting, Software, Ubuntu
Few days ago I found artwork suggestions for Fedora 10. I really like the wallpapers in Solar theme. They should change based on the time of the day. As I don’t think that is supported in Gnome, I wrote this little script that does the job.
To run it, a directory with wallpapers needs to be passed.
./rotate-wallpapers /path/to/wallpaper/directory/
If you want it to run in the background, you can press Alt+F2 in Gnome, and run it.
/path/to/rotate-wallpapers /path/to/wallpaper/directory/
Once it’s run, it will count the number of wallpapers in the directory (files ending in jpg, jpeg, gif, png or svg), divide 1440 by that number and use the result as a period of time on which wallpapers will be rotated. It will set the first wallpaper, and sleep until the wallpaper needs to be changed.
So, this script is pretty much specific. It will work best with the series of wallpapers that have subtle changes, such as the Solar wallpapers. But, you’re free to use it in every way you want. Good luck :)…
If you find any bugs, please post it in the comments. Thanks.
Tags: gnome, Linux, Programming, script, Scripting, Ubuntu, wallpaper
Adapting Joomla database to UTF8
Posted by Saša Bodiroža | Filed under Programming, SQL, internet
Few days ago I was searching for an easy way to adapt MySQL database used by Joomla from latin1 to UTF8 character set. I haven’t found anything, so I wrote this little script.
It’s easy to make a database which uses UTF8 character set when you’re installing Joomla by hand. Though, sometimes your hosting provider doesn’t give you the right to create new databases, so the only way is to install it using some software (cPanel, for example). It will usually set DB to use latin1 encoding. So, after it’s installed we have to modify database and its tables using SQL. This script should do the job, at least for Joomla 1.5, since it’s modifying tables used in Joomla 1.5.
Update: I’m not sure, but altering table jos_users seems to break the passwords. I think you can safely skip it…
ALTER DATABASE CHARACTER SET `utf8` COLLATE `utf8_general_ci`;
ALTER TABLE jos_banner CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_bannerclient CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_bannertrack CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_categories CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_components CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_contact_details CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_content CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_content_frontpage CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_content_rating CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_acl_aro CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_acl_aro_groups CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_acl_aro_map CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_acl_aro_sections CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_acl_groups_aro_map CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_log_items CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_core_log_searches CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_groups CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_menu CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_menu_types CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_messages CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_messages_cfg CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_migration_backlinks CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_modules CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_modules_menu CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_newsfeeds CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_plugins CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_poll_data CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_poll_date CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_poll_menu CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_polls CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_sections CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_session CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_stats_agents CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_templates_menu CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_users CONVERT TO CHARACTER SET `utf8`;
ALTER TABLE jos_weblinks CONVERT TO CHARACTER SET `utf8`;
This script assumes that the prefix of your tables is “jos_”. In case it’s not, just change it in the script. This script can also be applied to any other database. Just open it, and use the names of your tables, instead of these.
In case there is an easier way, I would be thankful if it gets posted in the comments.
Little disclaimer: I’m in no way responsible if something goes wrong. Be careful when you start doing this.
Tags: internet, joomla, latin1, mysql, Programming, SQL, tables, utf8
Assembling … done
Posted by Saša Bodiroža | Filed under Misc, Personal, Programming
Well, I finished the assembler project for school. It was fun writing it and breaking the assembler into separate parts, for each specific task. I have also learned a lot about the way assembler works.
It is a basic assembler for 8086 processor with 2-byte words, and 1 byte long addressable unit.
It isn’t full with instructions, but it covers the basics. There are four segments: dat, txt, bss and stack. dat and txt, as data and code segments, are represented in the object file. There is the directive DW which is used to reserve a word, END for marking the end of the input. Seven instructions are available:
- mov dst, src
- add dst, src
- push src
- pop dst
- int src
- jz src
- jmp src
Eight registers are accessible: AX, BX, CX, DX, SI, DI, BP, SP. There are four addressing modes: immediate, direct, register direct and register indirect with displacement. The coded instruction is one word long, if both operands are addressed with register direct addressing, or two words long, if one of the operands is addressed in some other mode.
So far, the assembler is case-insensitive, but I think I’ll reprogram it, so it is case-sensitive for user-defined symbols. That would be nice :).
Since I don’t think I should publicly post the project code for now (there are still other people writing it), I’m gonna post a simple assembler program and the output. The program is not doing anything meaningful. It is just presenting the assembler possibilities. Read the rest of this entry »
Tags: assembler, Personal, Programming, project, school, system
getString/getFormattedString in JS and XUL
Posted by Saša Bodiroža | Filed under Programming
I’ve been working on one Firefox extension lately. As with most of the them, there was a need to work with strings :). It had the stringbundleset, with defined stringbundles. We also needed a getString and getFormattedString (gS/gFS) functions for the class. Well, it seemed easy enough: try to fetch from the first bundle, check if the string is null, if it is, try to fetch from the second bundle (got used to C++ :))…
I’ve looked up on the Internet to see what does stringbundle’s gS/gFS returns. Their definition can be found at MDC’s page on stringbundles. Unluckily, there’s no info what happens if a string is not found. Luckily, MDC’s tutorial on property file says that gS/gFS returns null in that case. I tried that and it didn’t work. It would just throw an exception.
So, I searched through the code to see if there’s some other gS/gFS (which I should have done in the start). There was one other class that had them. No “if (!string)” testing, but catching an exception :). If you bumped upon this problem, here’s an example of the solution:
[sourcecode language='jscript']var result;
try {
result = document.getElementById(stringBundleFirst).getString(key);
}
catch (e) {
result = document.getElementById(stringBundleSecond).getString(key);
}
return result;[/sourcecode]
Happy coding :).
Tags: getFormattedString, getString, javascript, mozilla, Programming, xul




