Simple element blocker with and without jQuery

If you’re using jQuery the best (the only reasonable?), in my opinion, way to block an element or entire page (for example for updating it contents) is to use blockUI plugin. But, if you only have to block one or two small elements then you may consider writing your own, very simple blocker instad of using blockUI. And if you’re using jQuery only for that purpose (really small project or task), the you may try to do the same without jQuery at all.

Read More “Simple element blocker with and without jQuery”

Test page for Markdown on Save Improved plugin

This is a dummy example post body, that can be used for testing Markdown rendering in any WordPress post or in any Markdown supporting page at all. I wrote it months ago and started using it for testing Markdown on Save Improved plugin. But then in turned out, that this quick sheet can be used virtually everwhere, where Markdown can be used. Just paste everything or selected part to test and verify Markdown in your blog, website, service etc.

Read More “Test page for Markdown on Save Improved plugin”

Print correct date in languages other than English

Unlike in English, full date written in many other languages (i.e. in Polish) has month written in genitive case. Neither WordPress (the_time()) nor PHP itself (date() on which the_time() is built on) supports writing dates in such format, so you’ve got to help yourself. This isn’t a hard task and there are many approaches to solve this problem across Internet. Here, I present on of the solution, ready to be used both in one, single theme or across entire WordPress Network.

Read More “Print correct date in languages other than English”

Hiding blog from guests or setting up ‘Under Construction’ site

WPRecipes has a quick and clean example of using shortcodes in WordPress in general and a particular example of restricting part of post (text, media or anything) to be visible only to registered users. This is quite nice example of doing so, without need of extra plugin for this purpose. You could also learn from here an overall knowledge of using shortcodes in WordPress, if you’re not familiar with that.

Keep in mind that this tips is for hiding part of post from guests. If you want to hide entire post, simply publish it as Private (all posts and pages are published as Public by default) — look in post or page settings.

Read More “Hiding blog from guests or setting up ‘Under Construction’ site”

My favorite AI Factory’s Chess Free games

I’m playing Chess Free by AI Factory Limited on my mobile devices. Games has an option to export gameplays in PGN format. Though I’m pretty weak player, I wanted to write down myself most interesting games I played. If you’re anything more than beginner in chess, you probably won’t find anything interesting in this post. Sorry! :]

Human-like playing?

It is said, that this game uses a bit different chess engine (AI Factory’s Chess Treebeard). Which is able to play in more like human style. It is so good at it (again, as they say), that Microsoft decided to buy license for this engine to incorporate it into own chess games.

I can say one thing — it certainly plays as human. On lower levels it occasionally makes stupid, human-like, errors, but overall gameplay is at moderate level and style. While in all other chess engines I checked, lower levels always mean overall low quality play, very chaotic and not much equal to a human, even a weak player.

I must say about one exception to above rule. At lowest level computer opponent strategy is sometime awfuly obvious and predictable. For example, a situation after Napoleon Opening and blocked attempt to give Scholar’s mate (in four moves), where:

  • pawns from e2 and d7 are captured,
  • white has moved its Queen to f3,
  • black has his Queen at d5 and Knight at f6,
  • all other figures and pawns remains at starting positions,

When it is black’s move, computer opponent will always capture white Queen, for the price of loosing own. Since I adore Napoleon Opening (lame, I know! :]), I run into this situation quite often and I haven’t ever seen a different solution, when playing against Chess Free by AI Factory. This looks more like hardcoded pattern, than a strategy and a bit of AI.

I was also very surprised, to see, that on lowest level, chess engine is unable to win game, having two Queens (second after pawn’s promotion) and a bunch of other figures against lonely King! Instead of making 2-3 quick moves with one of that Queens, it decides to block white King and goes with another pawn for promotion to third Queen.

This situation has repeated in another game, with CPU opponent having two Queens and King against again lonely King and not being able to win the game, leading to a stalemate instead. So, it clearly proves, that endings are not the stronges part of this chess engine at lowest levels.

My favorite chess games

And here are my most interesting plays on Chess Free by AI Factory Limited.

Checkmate by a Pawn

Overall quality of the game is quite low, with many stupid mistakes on both sides. And with lame, beginner-level, opening to try to get Scholar’s mate in four moves (Napoleon Opening). But my finish was interesting. At least to me! :]

1. e2e4 e7e5
2. Bf1c4 Qd8f6
3. Qd1f3 Qf6xf3
4. Ng1xf3 b7b5
5. Bc4xb5 h7h5 
6. Nf3xe5 Bf8e7
7. Nb1c3 Be7f6
8. Ne5c4 a7a5
9. e4e5 Ra8a7
10. e5xf6 Nb8c6 
11. O-O Ke8f8
12. b2b3 g7xf6
13. Bc1b2 Kf8g7
14. Nc3e4 Ra7a8
15. Rf1e1 Rh8h6 
16. Re1e3 Nc6e7
17. Re3f3 Ra8a7
18. Nc4e5 f6xe5
19. Bb2xe5+ Kg7f8
20. Bb5c4 f7f5 
21. Be5f4 f5xe4
22. Bf4xh6+ Kf8e8
23. Rf3f7 Ng8xh6
24. Rf7f6 Nh6f5
25. Bc4f7+ Ke8d8 
26. Bf7xh5 d7d5
27. Ra1e1 Ra7a6
28. Rf6f8+ Kd8d7
29. Bh5e8+ Kd7d6
30. c2c4 Bc8e6 
31. c4xd5 Be6xd5
32. Rf8f6+ Bd5e6
33. Be8f7 Kd6e5
34. Bf7xe6 Ke5xf6
35. Be6xf5 Kf6xf5 
36. f2f3 Ra6e6
37. d2d3 e4xd3
38. Re1xe6 Kf5xe6
39. Kg1f1 d3d2
40. Kf1e2 d2d1=N 
41. Ke2xd1 Ke6f5
42. Kd1e2 c7c5
43. g2g4+ Kf5g6
44. Ke2e3 Ne7d5+
45. Ke3e4 Nd5f6+ 
46. Ke4f4 Nf6d5+
47. Kf4g3 Nd5b4
48. Kg3f4 Nb4xa2
49. g4g5 Kg6g7
50. Kf4f5 Na2c3 
51. f3f4 Nc3d1
52. h2h4 Nd1e3+
53. Kf5e4 Ne3c2
54. h4h5 Nc2b4
55. h5h6+ Kg7h7 
56. f4f5 Nb4c6
57. f5f6 Nc6d4
58. Ke4e5 Nd4xb3
59. Ke5f5 Nb3d2
60. g5g6+ Kh7xh6 
61. g6g7 Kh6h7
62. Kf5g5 Kh7g8
63. Kg5g6 Nd2f3
64. f6f7#  1-0 

A mate called “fuckup”

Here is an example of something nearly impossible (I had no idea, I’m such a lame player!). It shows, how to get two Queens in fairly beginning of the game (due to really stupid mistakes done by computer opponent) and even so (loosing only one of them), loose entire match due to unexpected mate.

1. e2e4 e7e5
2. Qd1f3 Ng8f6
3. Ng1h3 d7d5
4. e4xd5 Qd8xd5
5. Nb1c3 Qd5d4 
6. Nc3b5 Qd4d8
7. Bf1c4 Nb8c6
8. c2c3 Bc8e6
9. b2b3 Bf8a3
10. Bc1xa3 h7h6 
11. d2d4 Rh8h7
12. d4xe5 Qd8d7
13. e5xf6 Qd7d8
14. f6xg7 Be6g4
15. g7g8=Q+ Ke8d7 
16. Qg8xd8+ Ra8xd8
17. Qf3e3 a7a6
18. Bc4d5 b7b6
19. Bd5xc6+ Kd7c8
20. Qe3e7 a6a5 
21. Nb5xc7 Rh7g7
22. Ra1d1 Rd8xd1#  0-1 

After playing this game, I convinced myself, that I should return to building sand castles, not play chess!

Mate with a Queen

This is an unusual situation, I think. The opponent looses his Queen in a stupid exchange for my Queen at a very early stage of the game. Then, near the end, he promotes one of its pawns to another Queen and… looses the game. He isn’t even able to move that Queen to much.

1. d2d4 e7e6
2. g2g4 Qd8f6
3. f2f3 Bf8d6
4. c2c4 e6e5
5. Bc1e3 e5e4 
6. Nb1a3 e4xf3
7. Ng1xf3 Ng8e7
8. Ra1c1 Ne7g6
9. Qd1b3 Nb8c6
10. d4d5 Nc6a5 
11. Rc1c3 Na5xb3
12. Rc3xb3 c7c6
13. Be3d4 c6xd5
14. h2h4 Bd6e5
15. e2e3 Be5xd4 
16. Na3b1 Bd4xe3
17. Nf3d2 Qf6f2+
18. Ke1d1 Be3xd2
19. Rb3b5 Qf2f3+
20. Kd1xd2 Qf3xh1 
21. Bf1d3 Qh1xb1
22. Bd3xb1 a7a6
23. Rb5xd5 Ng6f4
24. Rd5e5+ Ke8d8
25. Kd2c3 Rh8e8 
26. Re5c5 d7d6
27. Rc5a5 Bc8xg4
28. Bb1xh7 Re8e3+
29. Kc3d4 Nf4g2
30. Bh7e4 Re3e1 
31. Be4xg2 Re1d1+
32. Kd4e4 Kd8d7
33. Bg2f3 Bg4e6
34. Bf3xd1 Ra8c8
35. b2b3 Rc8h8 
36. h4h5 g7g6
37. h5xg6 f7xg6
38. Ra5g5 Rh8h4+
39. Ke4e3 Rh4h3+
40. Bd1f3 Be6f7 
41. Ke3f4 Rh3h2
42. Bf3xb7 Rh2xa2
43. Bb7e4 Ra2b2
44. Be4xg6 Bf7e6
45. Rg5g3 Kd7e7 
46. Bg6f5 Ke7f6
47. Bf5e4 Be6f5
48. Be4xf5 Rb2f2+
49. Rg3f3 Rf2a2
50. Rf3e3 a6a5 
51. Re3e1 a5a4
52. b3b4 a4a3
53. b4b5 Ra2f2+
54. Kf4e4 Rf2xf5
55. b5b6 a3a2 
56. b6b7 Rf5e5+
57. Ke4d4 Re5xe1
58. b7b8=Q a2a1=Q+
59. Kd4d5 Qa1e5+
60. Kd5c6 Qe5c5+ 
61. Kc6b7 Re1e7+
62. Kb7a8 Qc5a5+
63. Qb8a7 Qa5xa7#  0-1 

I’ve heard, that it is fairly hard to loose, when you still have your Queen.

Six Queens

Now, that’s good. I’ve heard about “Seven Queens” example, when I was very, very young (middle of primary school), but I never thought, that I’m going to play a very similar game. Of course, this one was only possible due to stupid mistakes made by the opponent, set to a very low gameplay level.

But, I’ve also gained a new experience… It is fairly hard to not give the opponents mate (or stealmate), if you have too many Queens! :]

1. e2e4 e7e6
2. Bf1c4 Qd8f6
3. Qd1f3 Qf6xf3
4. Ng1xf3 b7b6
5. Nf3d4 Nb8c6 
6. Nd4b5 Ng8f6
7. Nb5xc7+ Ke8d8
8. Nc7xa8 Bf8e7
9. d2d3 d7d5
10. Bc4b5 Kd8d7 
11. Bc1f4 h7h6
12. c2c4 d5xe4
13. d3xe4 Be7d6
14. g2g3 Bd6e7
15. Ke1e2 Be7b4 
16. Rh1d1+ Kd7e7
17. Bb5xc6 Rh8f8
18. a2a3 Rf8d8
19. a3xb4 g7g5
20. Bf4e3 Rd8d6 
21. b4b5 e6e5
22. Be3xb6 a7xb6
23. Na8xb6 Rd6xd1
24. Ke2xd1 Bc8g4+
25. Kd1c2 Ke7e6 
26. Nb1c3 Bg4f3
27. Bc6d5+ Ke6d6
28. Bd5xf7 Nf6xe4
29. Nc3xe4+ Bf3xe4+
30. Kc2b3 Kd6c5 
31. Nb6d7+ Kc5d4
32. Nd7xe5 Kd4xe5
33. Ra1d1 Be4h7
34. c4c5 g5g4
35. Rd1d6 Bh7f5 
36. Rd6xh6 Ke5e4
37. Bf7e6 Ke4e5
38. Be6xf5 Ke5xf5
39. Rh6h5+ Kf5e4
40. Rh5g5 Ke4f3 
41. Rg5xg4 Kf3xg4
42. c5c6 Kg4g5
43. c6c7 Kg5g4
44. c7c8=Q+ Kg4g5
45. b5b6 Kg5h5 
46. b6b7 Kh5g5
47. b7b8=Q Kg5h5
48. Kb3c3 Kh5g5
49. b2b3 Kg5h5
50. b3b4 Kh5g5 
51. b4b5 Kg5h5
52. b5b6 Kh5g5
53. b6b7 Kg5h5
54. Qb8c7 Kh5g5
55. b7b8=Q Kg5h5 
56. h2h3 Kh5g5
57. Qc8h8 Kg5g6
58. Qc7g7+ Kg6f5
59. Qh8g8 Kf5e4
60. Qg7g6+ Ke4f3 
61. Qg6f5+ Kf3g2
62. f2f3 Kg2h2
63. h3h4 Kh2g2
64. g3g4 Kg2h3
65. h4h5 Kh3h4 
66. Qb8f8 Kh4h3
67. h5h6 Kh3h4
68. h6h7 Kh4h3
69. g4g5+ Kh3h4
70. g5g6 Kh4g3 
71. g6g7 Kg3h4
72. Qf5c8 Kh4h5
73. f3f4 Kh5h6
74. f4f5 Kh6g5
75. f5f6 Kg5g6 
76. f6f7 Kg6h6
77. Qf8a3 Kh6g6
78. h7h8=Q Kg6f6
79. f7f8=Q+ Kf6g6
80. Qg8h7+ Kg6g5 
81. Qf8b4 Kg5f6
82. Qh7h1 Kf6g6
83. Kc3b2 Kg6f6
84. Qb4b3 Kf6g6
85. Qh1d5 Kg6f6 
86. Qd5d3 Kf6g5
87. Qc8c3 Kg5g4
88. g7g8=Q+ Kg4f4
89. Qg8e8 Kf4g5
90. Qh8f8 Kg5h4 
91. Qe8e3 Kh4h5
92. Qf8f3+ Kh5h4
93. Qe3e4+ Kh4g5
94. Qd3d5+ Kg5h6
95. Qc3c6+ Kh6g7 
96. Qb3b7+ Kg7h8
97. Qa3a8#  1-0 

Of course, it was a fun & show at the end. I had a dozens of possibilities to end this game at much earlier stage.

Quite nice Mate

As for human-like playing of this chess engine. I noticed, that as long as I was using Napoleon’s Opening, CPU opponent become stronger and stronger and I started to loose game after game, though game’s difficulty level hasn’t changed a bit. But, when I changed my opening strategy, chess engine become completely wako.

It started to do very dumb errors like not capturing unsecured pawn, which was designed by me to kill one opponent’s figure and die, while actually was killing three or four and nearly reaching promotion line. Or letting me to capture Queen with a Knight in a clear, simple, very predictable attack pattern. Making such dumb mistake after mistake lead me to one of my most beautiful mates in my entire (yet short) chess history.

1. Nb1c3 e7e5
2. b2b3 d7d5
3. Bc1b2 Qd8g5
4. Nc3xd5 a7a5
5. Bb2a3 Bf8xa3 
6. Nd5xc7+ Ke8d8
7. Nc7xa8 Qg5f5
8. Na8b6 Kd8e8
9. d2d4 h7h6
10. d4xe5 Qf5g4 
11. Qd1d2 Ke8e7
12. Qd2c3 Qg4g6
13. Qc3xc8 f7f5
14. Qc8xb8 Ke7e6
15. Qb8xb7 h6h5 
16. Qb7d5+ Ke6e7
17. Qd5xa5 Qg6c6
18. Qa5xa3+ Qc6d6
19. e5xd6+ Ke7f7
20. d6d7 Ng8f6 
21. e2e3 Kf7e6
22. Bf1c4+ Ke6e5
23. Ra1d1 Nf6e4
24. Rd1d5+ Ke5f6
25. f2f3 Ne4c3 
26. Qa3d6+ Kf6g5
27. Qd6f4+ Kg5g6
28. Qf4xf5+ Kg6h6
29. Qf5xh5#  1-0 

Of course, I fully understand that I probably wouldn’t be able win such game aganist a real human, even novice player. But even so, I thought this game is worth noting.

A total destruction

I would call that game “A Total Destruction” or “A Queen’s Play”.

1. e2e3 e7e5
2. Qd1e2 d7d5
3. c2c4 d5xc4
4. Qe2xc4 Qd8f6
5. Nb1a3 Ng8h6 
6. Na3b5 Nb8c6
7. Nb5xc7+ Ke8e7
8. Nc7xa8 Qf6d6
9. Ng1f3 Nh6g4
10. Nf3g5 f7f6 
11. Ng5f7 g7g6
12. Nf7xd6 b7b5
13. Qc4c5 Ng4xf2
14. Ke1xf2 Bc8f5
15. Nd6xf5+ Ke7f7 
16. Qc5xc6 Bf8b4
17. Qc6xb5 Rh8xa8
18. Qb5d5+ Kf7f8
19. Qd5xa8+ Kf8f7
20. Qa8b7+ Kf7g8 
21. Qb7xb4 g6xf5
22. Qb4e7 h7h6
23. Qe7xa7 Kg8f8
24. Qa7d7 f5f4
25. e3xf4 e5xf4 
26. Qd7d6+ Kf8g8
27. Qd6xf6 f4f3
28. g2xf3 h6h5
29. Qf6g6+ Kg8f8
30. Qg6xh5 Kf8e7 
31. Rh1g1 Ke7d7
32. Rg1g6 Kd7c8
33. Qh5h7 Kc8b8
34. Rg6g8#  1-0 

Again, this would probably never happen in real world, even when playing against a very weak player.

Dumb CPU

This is third play, after “Quite Nice Mate” and “A Total Destruction“, that caused me to think, how dumb must be the player, that CPU is pretending to be?

1. d2d4 Nb8c6
2. e2e4 g7g6
3. Qd1f3 Nc6xd4
4. Qf3f4 Nd4xc2+
5. Ke1d1 Nc2xa1 
6. Qf4g3 b7b6
7. Qg3d3 Bc8b7
8. Qd3f3 f7f5
9. Qf3g3 f5xe4
10. Nb1a3 e7e6 
11. Ng1h3 Bf8d6
12. Bc1d2 Bd6xg3
13. Na3c2 Na1xc2
14. Bf1e2 e4e3
15. a2a4 e3xd2 
16. f2f4 Bb7xg2
17. Be2f3 Bg2xh1
18. f4f5 Bh1xf3+
19. Kd1xd2 Nc2d4
20. Kd2d3 Nd4e2 
21. h2xg3 Ne2c1+
22. Kd3d4 c7c5+
23. Kd4e5 Nc1d3+
24. Ke5d6 Nd3xb2
25. f5xe6 d7xe6+ 
26. Kd6xe6 Qd8e7#  0-1 

I begin to thing, really seriously, about advancing to level 2 after these three plays! :) I tried level ten (the strongest one) and get my own version of total destruction. But, who know, maybe it is time to get at least +1 in level rank? :]

Mate close to opponent’s one

This one is also good, because I managed to mate my opponent move or two before loosing myself. I ended the game, when my opponent had already have his Queen and Rook next to my King. Again, this wouldn’t be possible, if CPU opponent wouldn’t be that dumb, but hey — it is still nice to look at it, right? :]

1. e2e3 e7e6
2. Qd1f3 d7d5
3. Ng1h3 Ng8f6
4. Nh3g5 Nb8c6
5. b2b3 a7a5 
6. Bc1b2 e6e5
7. d2d4 e5xd4
8. e3xd4 h7h6
9. Bb2a3 h6xg5
10. Qf3e2+ Nf6e4 
11. Qe2b5 Ra8a7
12. f2f3 Ne4f6
13. c2c4 g5g4
14. c4xd5 Nf6xd5
15. Ba3c5 Rh8h5 
16. Bc5xa7 Rh5h4
17. g2g3 Rh4h7
18. f3xg4 b7b6
19. Bf1g2 Bf8c5
20. d4xc5 Nd5e7 
21. Bg2xc6+ Ne7xc6
22. Qb5xc6+ Qd8d7
23. Qc6g2 Qd7xg4
24. Ke1f2 Rh7h6
25. Rh1e1+ Ke8d8 
26. Re1e4 Qg4d1
27. Qg2f3 Qd1d5
28. Qf3f4 b6xc5
29. Ba7b8 Rh6d6
30. Nb1c3 Qd5h5 
31. Re4e5 Qh5xh2+
32. Kf2f3 Rd6d2
33. Qf4xf7 Rd2g2
34. Re5e8#  1-0 

This game is also interesting, because I managed to capture both opponent’s Rooks, at their initial positions, with my both Bishops and therefore place them in both opponent’s corners. It was possible due to repeated twice the same mistake (quite common thing at level one). In the following game I managed to do exactly the same with my both Knights.

The conclusion

Congratulations, on managing to read this article to the very end! :)

As you can see, human-like playing means dumb-playing on lowest levels. Maybe (due to my lack of experience) because I haven’t played with Chess Free on higher levels narrows my opinion. But, I’m quite skeptical, if Microsoft really purchased a license for chess engine that can play “such” games!

Fixing small but annoying issues in Dashboard in WordPress Network

There are three small, but annoying things in Admin Dashboard that I always encounter, when dealing with WordPress Network installation:

  • My Sites menu items order,
  • slow loading of that menu,
  • WordPress sites’ Dashboards language.

All three issues can be easily fixed. But, you’ll need some deeper knowledge of WordPress and deal with some plugins (both hand-written and downloadable).

Alphabetic order of My Sites menu

First thing is how to sort My Sites menu items alphabetically?

The question, what order is used to sort My Sites menu in WordPress Network Dashboard remains unanswered. Items order in that menu changes as you’re making changes to your sites, but probably even WordPress authors can’t answer what sort order is used there. We only know for sure, that it isn’t alphabetical — the most wise and most obvious.

Here is a simple solution (network plugin) to solve this problem. Just copy this:

 * Plugin Name: Sort My-Sites
 * Description: Sorts the My Sites listing alphabetically.
 * Author: Otto


function sort_my_sites($blogs)
    $f = create_function('$a,$b', 'return strcasecmp($a->blogname, $b->blogname);');

    uasort($blogs, $f);

    return $blogs;

and paste it into text editor.

Save it under any name (sort-my-sites.php for example), put to a subdirectory (sort-my-sites) and ZIP it ( Then install and network enable such plugin. And voila!

This solution is a slight modification of this WordPress StackExchange answer.

My Sites menu items count

If you have many sites in your network and number of My Sites menu grows, you may even face the problem that your entire Dashboard loads visually slower only because Network Admin bar consumes much time and resources to build up My Sites menu.

In this case you may consider Joshua Lynch’s solution.

It utilizes similar approach as above and introduces some new filters, that removes all sites from My Sites menu and places commonly used items to it instead.

Dashboards’ Language

Very irritating (at least to me) is that when you (or your user) sets blogs language to different than English, not only blog is translated, but also is admin’s dashboard. Translations authors are paying much less attention to quality and update of dashboard’s translations, so translated dashboard may not only be confusing, but also improperly translated or with missing strings.

All these problems can be avoided, by forcing each dashboard to English, no matter, what language blogs are using. This can be done with a small and simple plugin called Admin in English.

Note: If you search the web for this plugin name, you may find some sites, outside, that shows some nice examples on how to force all dashboards to use the same, non-default (not English) language. I remember, that I run into article showing how to have all dashboards in Russian, while network blogs were all in Russian, English and German.