28.12.07

Convert CSS layout to RTL - cssrtl.py

Posted in Projects, Python at 11:28 am by Guy

This is a re-release of a script of mine that helps convert CSS layouts to RTL. I originally released it about a year ago but it was lost when I moved to the new blog. The script, cssrtl.py, utilizes a bunch of regular expressions to translate a given CSS layout to RTL.

Read the rest of this entry »

22.12.07

Vim Macros for Wrapping Strings for Gettext

Posted in PHP, vim at 1:52 pm by Guy

I’m working on a website and we decided to localize it using GNU gettext. Soon enough I found it tiring to wrap each string manually in _( and ) and also to do it in Smarty (using {t}string{/t}. So I decided that I need a macro that will let highlight the string that needs translation and the macro will wrap for me.

I ended up writing two macros one for PHP files (but it’s also good for C/C++ etc.) and one for smarty.

:vmap tg di_(<ESC>pa)<ESC>
:vmap ts di{t}<ESC>pa{/t}<ESC>

To use these macros just highlight the string for translation in vim’s visual mode and press tg (or ts), and your string will be wrapped for translation.

04.12.07

Multibyte String Truncate Modifier for Smarty - mb_truncate

Posted in PHP at 3:53 pm by Guy

When working with Smarty, a PHP templating engine, I discovered that while the regular truncate modifier works great on ASCII strings, it doesn’t work with multibyte strings, i.e. UTF-8 encoded strings. This leads to problems in internationalization (i18n), as UTF-8 is the popular encoding for non-Latin alphabets nowdays. The problem can be solved by modifying the built-in truncate modifier and create a new one that takes an additional argument, the charset of the string, and acts accordingly. The new modified modifier, mb_truncate is implemented below.
Read the rest of this entry »

23.11.07

A JavaScript DOS Attack

Posted in JavaScript at 12:30 am by Guy

In this post I will present a way of creating a JavaScript based DOS attack that utilizes the bad implementation of tabs in most (if not all) web-browsers. The attack will make the browser unresponsive and force the user to kill its process. This attack is based on the following JavaScript code:
Read the rest of this entry »

19.11.07

C’s “Goes To” Operator

Posted in C/C++ at 9:24 pm by Guy

Well it isn’t really an operator but this is a nice C code construct I ran into. It doesn’t seem to have any benefit except as a nice way to create a reverse loop:

int count = 100;
while (count-->0) {
        //some work
}

As I said I don’t think I’ll find any performance benefit for using this code snippet. On the other hand it is always fun to see the puzzled face other programmers have the first time they see the code.

07.11.07

Optimizing for Loops: Reverse Loops

Posted in C/C++ at 5:26 pm by Guy

for loops are basic language constructs in many languages. One of the first thing to look at when optimizing code is the loops, as they do considerable amounts of work (like going through a very large amount of data), in very little code.

If you go use for loop, but you don’t really care about the order in which the loop is executed, to be more precise, if you can afford reversing to loop, you can save quite some time. By reversing the loop I mean instead of giving the index values from 0 to 10 for example, you go from 10 downward to zero. This doesn’t seem like a big change, but when being carefully implemented this can easily upgrade the performance of your for loops.
Read the rest of this entry »

29.10.07

Creating Local SVN Repository (Home Repository)

Posted in Linux, Tutorials at 9:39 am by Guy

In this tutorial I will explain how to create a local Subversion (SVN) repository, intended for a single user. I assume that you already know the benefits of keeping track of old revision of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient yet strong method to do so, and the easiest way to do so with Subversion (SVN) is to create a local, home, repository intended for a single user - you.
Read the rest of this entry »

20.10.07

spass - A Secure Password Generator Utility

Posted in Linux, Projects, spass at 9:22 pm by Guy

spass is a secure password generation tool. spass was designed under the assumption that a password generator is as good as its random number generator, so spass uses the Random class, a /dev/random based cryptography strong random number generator class. As always, I tried to make a user-friendly as possible command-line interface (as much as a command-line interface can be friendly).
Read the rest of this entry »

12.10.07

Conditional Expressions in Python 2.4

Posted in Python at 12:52 pm by Guy

Python 2.5 introduced new syntax structure: the conditional expressions. For programmers in languages such as C these structures seem very basic and fundamental but Python lacked them for many years. As I said Python 2.5 introduced such syntax structure, one may use it in the following form:

x =  a if condition else b

As you probably guessed a is assigned to x if condition evaluates to true and b is assigned otherwise. This is pretty much equivalent to the C conditional expressions. But as I said, this structure was only introduced in 2.5. Previous versions of Python are still widely deployed and in use, so how do you achieve the same thing in older version of Python?
Read the rest of this entry »

05.10.07

ssh-keygen Tutorial - Generating RSA and DSA keys

Posted in Linux, Tutorials at 12:32 pm by Guy

In this post I will walk you through generating RSA and DSA keys using ssh-keygen. Public key authentication for SSH sessions are far superior to any password authentication and provide much higher security. ssh-keygen is the basic way for generating keys for such kind of authentication. I will also explain how to maintain those keys by changing their associated comments and more importantly by changing the passphrases using this handy utility.
Read the rest of this entry »

« Previous entries · Next entries »