Tuesday, June 17, 2014

Blog is closed

This blog is closed.

I have no spare time to update it.

Saturday, May 10, 2014

White to transparent in Photoshop

How to replace white color with transparency in Photoshop?

There is no way you can make this by built-in Photoshop tools. There is a number of solutions, but none provide with an ideal result.

And thanks God we have plugins. Filter Kill White does exactly what I need.

Unfortunately, it works only on earlier PS versions, not on CC. But it is better than nothing.

Thursday, December 19, 2013

Double character to single with regex

How to unescape string, that is escaped doubling some character?

For example, CSV files format doubles double quotes, and wraps entire value with double quotes, so the string

My "fat" string!

becomes

"My ""fat"" string!"

To unescape that, I have to replace doubled double quotes with single double quotes, and remove single double quotes.

" ->
"" -> "

This is regex I need to use:
/"("{0,1})/
and replace with content of capturing group.

Example code for PHP:


// Ansi 
$s = preg_replace('/"("{0,1})/', '$1', '"My ""fat"" string!"');
 
// Unicode 
mb_regex_encoding('UTF-8');  
$s = mb_ereg_replace('/"("{0,1})/', '\\1', '"My ""fat"" string!"');

Saturday, June 18, 2011

PHP cut string properly

Common problem with PHP development is when you cut a non-latin string, it has strange symol at the end, looking like "�".

It's all because string is in Unicode format(mainly utf-8), however a substr function only works with single-byte encodings.

Instead of using substr, you must use mb_substr.

substr($string, $length, $count)
replace to
mb_substr($string, $length, $count, 'utf-8')

Wednesday, May 18, 2011

Convert time between timezones

What to do if we want convert time between two timezones?

For example, an event occured at 15-00 by Moscow time(UTC+4). By that time, in Omsk(UTC+7) there is 18-00, three hours "more". We want to show time of event using local Omsk time.

How to do that in C++?

Fill tmDateExternal structure of type tm, with source event time(15-00). Save timezone shift of Moscow to in nSrcTZ, it is obviously 4.
__time64_t t64date = _mkgmtime64(&tmDateExternal) - nSrcTZ*60*60;
tm tmDateLocal;
_localtime64_s( &tmDateLocal, &t64date );

Now you have local Omsk time for that event in tmDateLocal structure.

Wednesday, December 8, 2010

Android: put ListView in a ScrollView

When I need to use ListView with other controls on the same screen, and it doesn't fit the screen vertically, I wish to get ScrollView over all controls, to scroll entire screen. But, that's the point when "shit happens".

Android core developers say you "must not put ListView inside ScrollView", because of many reasons, one of them - ListView has it's own scroll.

When you try just do it, ListView collapses, and you wish it not to be collapsed at all.

To accomplish that, I use a "hack", measuring and setting the height directly:

Sunday, May 30, 2010

Link in module title: Jumi + Articles Anywhere

How to set link in Joomla module title?
For example, let's show an article in module, with link to this article in module title.

1. Install Jumi, if you haven't done that already - it's incredibly useful component.

2. Install Articles Anywhere, plugin that displays article in any content.

3. Create Jumi module, publish it to position you choose, set any title, select option "Show title: Yes".

4. In "Code" field (on the right of module properties), write this code, with article_id changed to id of your article:

<?php $module->title="{article article_id}<a href=\"{url}\">{title}</a>{/article}"; ?>
{article article_id}{text}{/article}

Done!

First row will set module title to {article article_id}<a href="{url}">{title}</a>{/article}, and second will set module body.

Articles Anywhere plugin will parse tags in braces before display, changing it to corresponding html-code.