SQL King
1219312821|%e %B %Y
Are you an SQL King?
I once met a person that used to write SQL queries more sophisticated than this:
select * from category where category_id IN (select cat1 as category_id from (select min(category_id) as cat1, max(category_id) as cat2, name, site_id, count(*) from category group by name, site_id having count(*) > 1 ) as c1 union select cat2 as category_id from (select min(category_id) as cat1, max(category_id) as cat2, name, site_id, count(*) from category group by name, site_id having count(*) > 1 ) as c2 );
This one is to check duplicated categories in sites from Wikidot. It's not optimal, but it works. Of course the situation when there exist duplicated categories is a bug, but it seems a really rare one, because from the beginning of Wikidot, there are only 20 such categories, all of them being forum, so this probably means a small bug in create a forum thing as well.
Comments: 1, Rating: 0
Badge
tags: badge blog reflection rules wikidot
1218904233|%e %B %Y
Wonder why blog on Wikidot, not on Wordpress?
With Wikidot, you can give your badges a reflection:
(this one was created with Cooltext)
Welcome on Wikidot. Where dreams come true.
Comments: 0, Rating: 2
Object Database In Python - Day 2
1218903129|%e %B %Y
Hello again,
as pointed in the previous day comment, there is another IDE for developing in Python, which is BoaConstructor. As a matter of fact, I haven't taken that into consideration, because it was told it is a IDE for GUI development. As I was not about creating a GUI, this was completely skipped.
My impressions of the IDEs:
- pida, geany, drpython — interesting, but not worth a try for me
- eric — good overall, but raises many dialog boxes with information of exceptions. These are fatal and are about the GUI, so you have to click OK and continue working
I tried the Eric first, because it was written as a really good program. I like it, but it is not polished and would never be bought (if commercial) by anyone:
- the support for SVN is really tricky
- the GUI is really not intuitive — no "delete a file" or "new file (here)" in the navigator context menu
- the code completion is there, but not really so clever
for example, having the following code:
class aClass: def method(self, param): assert isinstance(param, list) param.
the IDE should know, that the param is a list and complete the list methods! I believe the PyDev plugin for Eclipse already did it when I last used it.
After trying all the listed IDEs I got back to Eric as one of two best Python IDEs tried by me (the second is PyDev).
Happy Pythoning
Your Piotr
Comments: 0, Rating: 0
Starting Work On Object Database In Python
1218794915|%e %B %Y
Good morning everyone,
today I start working on object database to be implemented in Python. This is my individual project for my classes.
During the study-year I was taught how to parse sophisticated grammar with PLY (Python Lex and Yacc library). I've then learned how to then process the parsed queries, to get the results.
The database query language is similar to the SQL language. The difference is, we don't have definitions of tables and fields. Any object (row in table) can have fields other that other objects with the same name (of the same table).
This seems quite hard, but it has its pros.
Moreover we've analyzed the following query using the simple parsing and processing:
SELECT employee.salary WHERE employee.salary > AVG(employee.salary);
now, having as much as 10000 employees, using the standard processing, this would mean calculating the average (AVG) from ALL salaries for EACH of the 10000 employees.
So the teacher proposed to use tree decoration, to mark the branches of the query syntax tree, that can be run once (i.e. their value does not depend on the rest of the query).
I proposed to do it other way: to don't analyze the tree to much, but instead implement a sort of caching. Each time we try to get the AVG(employee.salary) we check whether this was already calculated, if not (only the first time we get the AVG), we calculate this and populates the cache with the value.
This has the following pros:
- we can use the cache in successive queries
- we don't have to decorate query trees — it's not Christmas here
Today work I start with selecting a Python IDE to work with. During the classes I used PyDev — the Python plugin for Eclipse IDE, but I believe there any many new choices out there now — after a few months:
- eric
- pida
- geany
- drpython
(all from Ubuntu default repository)
More IDEs I found with Google:
- TruStudio: http://sourceforge.net/projects/trustudio/
- only windows(?): pyscripter — http://code.google.com/p/pyscripter/downloads/list
- commercial: Wing, Komodo, BlackAdder
Comments: 1, Rating: 0
More Juice
1218118347|%e %B %Y
Hi, today we've put more juice to Wikidot.
Here is automatic reflection generation:

Wonder how?
[[embed]]
<script type="text/javascript" src="http://static.wikidot.com/common--misc/reflection.js"></script>
[[/embed]]
[[div style="background: #444; padding: 20px; overflow: auto"]]
[[div style="margin: 0 auto; width: 400px"]]
[[image http://qn.lastlook.pl/~quake/wikidot-grass.png class="reflect rheight32 ropacity40"]]
[[/div]]
[[/div]]
We've also added many new video services to Wikidot (through [[embed]] tag) and more…
Comments: 3, Rating: 0
Why Wikidot Rulez
1217860794|%e %B %Y
Have you ever wondered why Wikidot rulez?
You could say, "hey, there is much more other wiki hosts out there, why should I use Wikidot?"
Wetpaint look quite nice, but has anoying Google Ads everywhere. (I've read, they have $40 million capital).
Wikia has the strange permission thing — if you post anything, it becomes their property.
PbWiki didn't allowed me to upload HTML file like this:
<html> <head> <title></title> </head> <body> abc bac </body> </html>
It claimed, that this is a spam and disabled file upload for 15 minutes for all pbwiki sites!
In the contrary Wikidot has many friendly features1 and have a totally different ads policy. Actually, they let YOU earn with their service. If you wish to display ads on your wiki, you get as much as 80% of what Google pays for them.
Wikidot rules, and has everyday-growing community, with their masterpiece wiki at http://community.wikidot.com/.
Comments: 0, Rating: 0
A Lot!
1217632250|%e %B %Y
- How much do you hate IE?
- A lot!
- That's enough, welcome in our team.
With the news about new team member, new themes and major software improvement it seems, that here, at Wikidot, we work hard. And as a matter of fact, we do.
I've recently created two nice themes for Wikidot:
- Bloo — especially for bloggers and a variant of this Bloo - no sidebar
- Not-yet-named (codename booze) — the one that is used on the http://themes.wikidot.com/
The latter was designed with much help from
Squark — the new team member.
Other interesting facts from the behind of scenes, with the server software upgrade, we've fixed some bugs, including:
- browsing by tags now allows special characters like + in tags
- printer-friendly version of forum was fixed (actually it seems that this had never worked before)
Moreover, we've injected more magic to Wikidot. The greatest improvements are:
- serving user-uploaded files. PHP checks whether you have right to see the file and then instructs the Lighttpd web server to serve the file to the user. We're using X-LIGHTTPD-sendfile for this purpose. Moreover we're now using a totally different domain for this: *.wdfiles.com, which prevents from JavaScripts attacks.
- direct access to any code block inside wikis. Just append /code to the URL
Example codeblock, that is accessible with a custom URL:
http://piotr.gabryjeluk.pl/dev:a-lot/code
Moreover if you set the type of the code to html or css, Wikidot will serve the file with the proper MIME type which makes the codes usable as external style sheets or iframe destinations!
See the following codes:
<html> <head> <title>Wikidot extracts codes from wiki pages!</title> <link rel="stylesheet" type="text/css" href="http://piotr.gabryjeluk.pl/dev:a-lot/code/3"/> </head> <body> <p>HTML live-extracted from page's code with attached live-extracted style!</p> </body> </html>
p { border: dashed #f00 1px; background: #ffa; color: #f00; font-weight: bold; font-size: 40px; }
Now the trick. To access the second (and any other) code block, just supply the URL of the page following by /code/<number>
for example
http://piotr.gabryjeluk.pl/dev:a-lot/code/2
will point you to the second code block in the http://piotr.gabryjeluk.pl/dev:a-lot page.
Now the Live demo:
Cool, huh? No file uploads needed, just save the code at Wikidot page and… access it!
Comments: 2, Rating: 0
New Way Of Dealing With Uploaded Files
1215337311|%e %B %Y
Unfortunately, it seems that our last approach (described here) to finally get the uploaded files right was not exactly possible. As authorization in Wikidot is based on cookies and sessions, they will not pass through cross-domain solution.
Allowing to read session_id from cookie in user uploaded HTMLs in not a good idea because of possible session spoofing.
So we designed an authorization mechanism that allows owner of a particular session browsing files from a certain wiki.
When a request to restricted user uploaded file (on the *.wdupload.wikidotsyndication.com domain) is performed, we will check if the cookie is set, then if it points to a valid session and if the user bound to the session is granted a permission to view the file.
If the auth cookie is not set, we'll redirect the browser to the *.wikidot.com site (which can read the original session-cookies) that will generate a unique key and redirect back to the original domain appending the unique key to the GET request. The original domain will then set the cookie and the access will be granted (or not).
Comments: 1, Rating: 1
Django-like routing in PHP
1215273992|%e %B %Y
As I've recently work with Django, the way it does the URL-based routing seemed really cool for me. I missed that in PHP, so I decided to code something like this.
Here is a class that uses (extends) my Controller class that does the routing:
class Controller_Ajax_Auth extends Controller_Ajax { protected $routes = Array( ':^info$:' => 'info', ':^challenge$:' => 'challenge', ':^login$:' => 'login', ':^logout$:' => 'logout', ); protected function info($url) { $r = Array(); /* something */ $this->ajaxResponse($r); } protected function challenge($url) { /* $q = something */ $this->ajaxResponse($q); } protected function login($url) { /* set $auth to true if logged */ $this->ajaxResponse($auth); } protected function logout($url) { /* logout */ $this->ajaxResponse(null); } }
This mainly routes URLs info, challenge, login and logout to corresponding methods in the same object.
But you can route out of the object to other Controller subclass instance:
protected $routes = Array(
':^auth/(.*)$:' => 'Controller_Ajax_Auth',
);
This gets URL and passes what's after auth/ to the new object of class Controller_Ajax_Auth (see the code above). Generally the first ()s in the left side of each line define what's passed to the method/object on the right side.
The controller has abstract errorHandler and defaultAction methods that need to be overridden. The first is called when a exception is thrown in a performed action. The latter is called, when routing comes to some object and then no routing line matches.
