Tuesday, June 14, 2011

me and my monkey...

no monkey. just "me and my code" concept, because of course there is a sense of (intellectual) property over the code a programmer writes. for those who even heard (not necessarely to read) of Hackers and Painter, by Paul Graham this post might sound very funny. of course, programming is a craft, and programmers are crafters, but still.


I am somehow intrigued by the voracity of marketing over the quality. I admit it is a mentality of a whole society. If you are born in a society where the individual rights are not strengthened by the higher state hierarchies, where the law of intellectual copyright is imported from foreign economies and societies without any effort to adapt it to "cruel reality", it is funny and perceived as a huge arrogance the simple fact I am about to describe in my next paragraph.

I am looking through a project which seems to be written by a single person (over 1500 files of PHP + HTML + CSS + JS code). I had different contradictory feelings: first I thought I am going to spend a whole day to make it work on localhost. Well...besides the 3 different configuration files with functions with same name and the comment of lines which made redirects to exactly the same link but with https instead of http - of course, no check if the request already comes from a secure url - nothing "spooky" yet. Then I find a class file (yeah...a class...who would have thought of that?). 'til line 137 we have the definition of private variables. 'til line 250 or so we have the constructor which initialize each variable with values (like '' or 0). then, 'til line 1200+ we have getters and setters for each variable:). I scroll down the file with over 3500 lines. Guess what? NO COMMENTS! none! zip! zilch! nada! until...the last lines which contain a copyright note, the author's name (for god's sake, at least don't put your real name there!!!) and of course the magic lines:
// This code may not be copied, sold, or used as a derivative work
// without the express written permission XXX
and here I am, wondering...who on earth would want to copy your code? I swear and cross my heart I will never be able to sell that code (I think the author of it actually had that problem). I would never say making that code to work that I am using it as a derived work. And no one should say that too. I am fixing it, improving it, make it run properly, use common sense and basic logic on a bumble-mumble product which, funny or not, is the INTELLECTUAL PROPERTY of another human being. Now I am the arrogant one, but I am forced to it, and I hate it. And believe me or not, but this kind of people have all the chances to rule the world.

Isn't it sad?

P.S.

Thursday, June 9, 2011

Timthumb and filenames with spaces issue

It is known that some of older timthumb.php versions have an issue with displaying pictures with spaces in their file names.
Altering the timthumb.php file:
1. just because I am paranoid, before the call of clean_source($src); (around line 40) function I added
$src = urldecode($src);
On front side I generate the pictures sources from jQuery + jquery.urldecoder.min.js and use $.url.encode(picture_source)
2. comment line (about 672) containing the code:
$src = str_replace (' ', '%20', $src);

Or best thing to do: update the timthumb.php file to last version!

Tuesday, April 19, 2011

Create dynamic images in php

Simple task: user input as string to be applied with a custom font on a given image.


You can view a demo here.

Features:
  • the font size is calculated depending on image's height;
  • the number of characters displayed on a row is calculated depending on image's width and calculated font size;
  • the text is split to pe displayed on multiple lines;
  • user can pick the text color on image;
  • the text has transparency;
  • the resulting picture is provided for download.
If you have suggestions or need the code, feel free to email me (write a suggestive email subject)

Friday, April 15, 2011

me and my facebook(s) - part 2

Friday evening, at the office, waiting for a server to "get real"...it won't
Anyway, the last weeks I had to do some stuff with the new Facebook API (which is really ok, I suppose...only it is not documented in a very efficient manner, so I end up spending hours for some simple tasks).

So, 2 easy hints if you want to upload a picture with the API (you will find tones of examples of code of how-to, the actual algorithm, using a PHP library which wraps the requests in a more elegant way, or directly with CURL):
1.For upload need special permissions - main permissions: read_stream, publish_stream, photo_upload, user_photos
2. Before the upload code you need to set the upload file support
$facebook->setFileUploadSupport(true); 
Now, some other things I had to do were 1. to save a picture (from the disk) to a Facebook user Profile album and 2. eventually open it so the user has the possibility to set it as his/her Profile Picture. The first thing is possible if the user already has a Profile Picture album. Otherwise you can not create from API that type of album (with type = 'profile' ). If the user did not have a profile picture yet it will be saved in an album with the application name.
The second part is alittle tricky, because Facebook would not allow an application to mess around with stuff which is part of user's privacy - such as the profile picture, so all you can do is open a new window with the saved picture in Facebook and let the user decide if he/she wants that picture to be his/her profile picture. How to do that? The action of saving a picture to profile/or_not_profile_yet album will return you the ID of the picture (in the Facebook graph), say it's $pid. The url where the user can see the picture and take the decision I've talked above looks something like this:

http://www.facebook.com/photo.php?fbid=$pid&makeprofile=1

Sunday, March 20, 2011

me and my facebook(s)

I just read an article about the new scams that moved on Facebook. One of the comments was that it is actually impossible to delete your account on Facebook so I wanted to give it a try. By the way, about 2 weeks ago I activated the option so that no one can comment on my wall and there was 1 person who seized talking to me any more and another who really felt like asking me if I am mad on her or not (which is hilarious...I am sorry, I still can't believe there are people out there who take social networks so seriously).
Anyway, two years ago I had to develop some applications for Facebook and I made like 14-15 users (because I needed to activate the pagination on friends list) so I picked one of them that I still remembered the credentials and tried to delete it. No, you can't delete the account, but you can "Deactivate" it from the Account Settings. Clicking on that option gets you to a very pathetic page with a list of the "friends" that will miss you if you do that (!!!!). Then they ask you the reason, which is ok...then, and that kinda freaked me out (just for 2 seconds, I am still sick so my mind doesn't react properly, or the way it used to) I read this:

Note: Even after you deactivate, your friends can still invite you to events, tag you in photos, or ask you to join groups. If you opt out, you will NOT receive these email invitations and notifications from your friends.

After 2 seconds I made a search on Google on "permanently delete your Facebook account" and I found some info here. So they have an application that deletes accounts for good. They give you an interval of 14 days to come back and cancel the deletion: Your account has been deactivated from the site and will be permanently deleted within 14 days. If you log into your account within the next 14 days, you will have the option to cancel your request.

P.S. I just deleted the account I made on the name of "Sandra Bullock"...after 13-14 sign ins I was totally out of inspiration

Tuesday, March 15, 2011

Când am încetat să mai fiu un zeu

Când am încetat să mai fiu un zeu?

Neuronii'ţi sincopau în 
 ritmul respiraţiei mele
Frunzele veştede toamna cădeau în 
cadenţa paşilor mei
Stelele apăreau pe cer după 
extrasistolele inimii mele.

În zvâcniri nevinovate
Ne dădeam cu capul de pereţii 
imaculaţi de sticlă
Ai propriei noastre voinţe.

Când am încetat să mai fiu un zeu?...
Nici că mai contează
În umanitatea-mi sieşi însăşi atot-suficientă.

Nu...acest text nu a fost generat de un script...dar ar fi putut fi.

Wednesday, February 9, 2011

WordPress plugin - Domains Update

I dared a few days ago to share a plugin I made with my work mates. It took me about 10 days to decide to do it (the sharing part). Last night my boss called me to ask me how to use it and in the end his conclusion was that it was not doing what I said it would...but, as usual, I had the "revelation" in the morning - meaning like 10 minutes ago.

So, I decided to put it here and see what kind of problems other people might have with it(omg...I am so evil).

What I pretend this plugin to do: updates values in database.

When you should use it: when you move your Wordpress site from one domain to another and you want to keep the database consistent.


Let's imagine the scenario when you move your Wordpress site from location A to B.

Options description:
1. Old domain - in our case would be A
2. New domain - in our case would be B
3. URL format - uncheck it if any of the domains does not have an URL format (e.g. localhost)
4. Select custom table(s) - when you press this button a list of the Wordpress' database tables is shown. When you select a table, a list of its columns is shown. Use this to update the values of old to new domain in other tables than wp_posts and other columns than wp_posts.guid and wp_posts.post_content (these are the default location of the update).
5.Update only custom tables - if this option is selected the default locations are skipped.
6. Run changes - runs the database updates.

Note 1: you can run this plugin multiple times.
Note 2: if you need to make updates in custom tables make sure you selected at least one table and for each table at least one column (otherwise it will tell you that there was no data to update).
Note 3: you might wonder why the plugin's name is Domains Switcher and in administrator's dashboard the name is Update Domains. Because I like to screw users' mind.

One more thing. The steps I follow when I need to move a Wordpress site from domain A to domain B and on domain A there is already content that needs to pe kept on domain B:
  1. Copy all needed files from A to B
  2. Export-import database from A to B
  3. On B, go to database and in table wp_options where column option_name has value siteurl and home the column option_value should have value A. Change it to B.
  4. On B, open file wp_config.php and update the information for database connection on B
  5. Enter wordpress admin on B (now you should be able to do that) and install and activate the Domains Switcher aka Update Domains plugin
  6. If all you need to update are posts and pages, run it with simplest configuration (without custom tables). The files uploaded and inserted into posts now will be taken from B, instead of A.
  7. If you used plugins which create their own tables, run the plugin against tables and columns that you know might contain URLs (e.g. for a slideshow plugin, it might keep in a custom table the links to images it uses)
  8. Sometimes plugins which do not create their own tables might insert links in column wp_postmeta.meta_value

You can download the plugin from here.

Known issue: Don't use it to update the information in cformsII plugin. It will alter the serialized string containing the cforms settings (and the plugin will stop from working). If you need to move cformsII to another domain, my suggestion is to install the plugin to the new locationa and backup-restore the forms from the old domain to the new one. If you have more than one form created with cformsII, just add new forms and backup-restore them. The global forms settings need to be update "manually" though.