Monday, 1 June 2009

Drupal sandbox creator shell script

Hi Readers,

I'm a really bad blogger. First, I never write. Secondly, I never write about new stuffs. I have my reason and to be honest, I've seen too many very good article so I had to realise, it's not going to be a tech blog. I'm really curious about how my coming MacBook affects to my reading habit. I've got a lot of hope in it. And another big news for me. I'll be a proud cat holder? Call me crazy but she will be my first child. (Besides that if her teacher says she is the smartest in the class - I won't believe it:) Anyway. To restart this stuff I intend to share a small Drupal site generator script with you.

What is the problem?
I'm a Drupal developer. I need to test modules before using it on production sites. I need to try out a lot of things. And the best for doing that is a Drupal sandbox. But it takes 1 or 2 minutes to create one. (At least for me.) ((It should be a Drupal install contest - yeah:))

Solution?
Create a sandbox once and pre-populate it when needs a new one.

Prepaire:
  1. Download the latest Drupal install: http://drupal.org/
  2. Install it in a directory called: drupal_sandbox
  3. Install all the modules you want by default (contrib ones as well)
  4. Use the database name of: drupal_sandbox in the settings.php
  5. Tar the drupal_sandbox directory: tar -cvzf drupal_sandbox.tar.gz drupal_sandbox
  6. Create an sql dump: mysqldump -u YOURUSER --password=YOURPASS drupal_sandbox > drupal_sandbox.sql


The script:

#!/usr/bin/env bash

# Directory where the tar.gz and sql file lies
package_dir=~/download
# Base file name for the tar.gz and sql files
package_name=drupal_sandbox
# Your web root
www_dir=~/www
# Your MySQL user
mysql_pwd=YOURMYSQLUSER
mysql_user=YOURMYSQLPASSWORD

cd $www_dir
tar -xvzf $package_dir/$package_name.tar.gz
mv $package_name $1
cd $1/sites/default
mv settings.php settings.php.bckup
sed "s/$package_name/$1/g" settings.php.bckup > settings.php

mysql -u $mysql_user --password=$mysql_pwd -e "create database $1"
mysql -u $mysql_user --password=$mysql_pwd $1 < $package_dir/$package_name.sql


Usage:
Call the script with a parameter (the name of the new drupal site (directory & sql))
sh ./drupal_creator.sh drupal_site_for_testing


Thats it. I hope it works for you. On my environment its fine.

Good luck,
Peter

Saturday, 28 March 2009

HTML element related data storage

Hi Folks,

I'm working on a voting widget generator Drupal module. Arbitrary voting widgets can be defined through a hook, and my module renders them to the node page. At the final phase the forms are converted to an ajaxian style and this needs a lot of information related to elements. The good old (quick and dirty) way to do this is the custom attributes. For example:

<img src="http://www.blogger.com/..." class="..." weight="..." type="..." key="..." nid="..." />

As far as I know, it works in most browser, however, I bet it fails on any xhtml validation. (And so ugly.) My idea is a common data storage. You create a new element with a unique ID that can be a key as well in a javascript object, which would contain data. Let's see an example:
<script type="text/javascript>
var data = {};
$('div.class').append('<img id="i1" src="pic1.png" />');
// save data
data['i1'] = {weight:__, type:__, key:__, nid:__, names:[__, __, __]};
// retrieve data
var necessary_name = data['i1'].names[2];
</script>


That's all. This example is just a schema. It can help if you generate lots of elements or you want to attach data elements in runtime.

Cheers,
Peter

Friday, 13 March 2009

Drupal module finder Flex - AIR application

Hi,

Recently I began learning Flex. The idea was from my boss and a girl who linked an adobe site with a LOT flex video on it. (Thanks @SquirrelMaster) http://www.adobe.com/devnet/flex/videotraining/ - check it

In the Drupal world there are two important buzzwords related to Flash: Druplash and Druplex. In a nutshell, these words cover the intelligent way that a Drupal application and a Flash application can communicate between each other. The basic idea behind this is the usage of Drupal as a back-end (information source) and the Flash as a better way to visualize the datas. To embed a flash game, video or a file/image uploader is not communication at all. As far as I know, it is very new field, however, there are quite a lot interesting idea there isn't any world changing way to implement it. If you interested in it, here you are some links to dig:

SWFObject provide a better way to add flash content to your HTML. It checks the client's flash player and browser capabilities. And if the environment unable to render your SWF appropriately, it displays an alternative content -> in the SEO side, makes your page readable for robots.
http://code.google.com/p/swfobject/

With SWFAddress your flash object can communicate with the JavaScript on the same page. Thus JavaScript can send a state (like the url) about the site (and from the url the flash can restore some action or timeline state - for example if the url is www.mywebshop.com/#shoes, it loads the shoes page). And of course vica-versa. Flash can send it's state to javascript and with that the javascript can modify the url for example. If its seems useless just think about sending a url for your friend. If the flash site can't handle the url, it always shows the home page.
http://www.asual.com/swfaddress/

Drupal has a module called Services. It defines a bunch of services (user services, node services, ...etc) and supports several layers to communicate (HTTP, RPC, XML-RPC, SOAP). The work-flow abstraction is quite simple. You send a request to the Drupal site, it does something (get data) and send back to the caller. The real power that you can create any custom services easily and with it you can retrieve any the information you want from Drupal.
http://drupal.org/project/services

AMF is a message format Flash use in transactions. It's binary, so mush more smaller than an XML message format. AMFPHP is a converter from AMF to PHP native format.
http://www.amfphp.org/

AMFPHP porting to Drupal.
http://drupal.org/project/amfphp

There are some slides about Druplash and Druplex:


Anyway. I fell in love with Flex. The reason I'm writing this post I developed a small application that helps searching Drupal modules on your desktop. How? With AIR. Unfortunately you have to install the desktop flash interpreter tool: called AIR player. It's more or less the same as Flash Player with a minor difference, it have the flash ran on desktop. Another interesting development: http://www.openscreenproject.org/ Adobe put the SWF and FLV/F4L technology to free license and strives to ease running flash applications on different devices. You know, now it's not the best on a unix based distro. But, ... at least you have the option for it.

So, back to my Flex app. If you want to try, you can download from here:
http://www.bison.hu/public/drupal_module_search_v01.air

Adobe AIR player is available at here:
http://get.adobe.com/air/

I can imagine a lot Flex application which can help the Drupal development. Making this was't more than 2 hours. Well, I know, it doesn't do too much as well.

If you have a creative idea that would be great to implement with Flex, please tell me. I'd be pleased to hear any feedback.

Thanks,
Peter

Saturday, 21 February 2009

Drupal Timetracker Screencast

Hi All,

This week I made my first screencast. It's about my new Drupal module called Timetracker. I have never ever thought how hard to make a video introduction. As my colleagues said, I speak in Hunglish, some kind of mixing with English and Hungarian. I sware I'm working on to imporve it. But you know. I'm not a rocket scientist. Anyway. That video took me 2 days and a lot of struggling. The module the video about is a tool for tracking your personal activities in the Drupal sphere. You can find several similar pages on the net, like www.bubbletimer.com. Actually it's a pretty useful application.
My module is still under developing, although it's working fine. But it has some performance and usability issue I want to make better. I sent my application for a CVS account to drupal.org, I hope they'll answer me soon.
So, here is the brief introduction about Timetracker:



I used Camtasia Studio to record that stuff and to be honest, I amazed how cool is this tool. Unfortunately the free version is time limited but I suggest everybody to try it if thinking about screencasting.

Cheers,

Sunday, 15 February 2009

10 practice how to improve your productivity

I keep myself as a workaholic guy. In the last few years I strove to be more and more productive. There are a couple of practices which save time for you a day. I want to share some of them with you. (DANGER! If you do exactly what is written, you can easily become to antisocial.:)

1 - do your household works rarely
When you washing dishes or clean your room there is a huge overhead to prepare for the process and after that it takes time to work again. If you buy 7 dinner sets or 40 pair of socks your costs are cleared in a few weeks. Do you know the activity scattering theory? If you have N jobs and the i. job takes Ti time than:
T1 + T2 + ... + TN = SUM(Ti)i=1..N * SQRT(N) * 1.2
So it takes more than the total time because you can't change tasks in a moment.
win ~ 3.5 hours a week

2 - walk fast
Be quick whatever you have to do if its not your work. Walk fast to your work and home. An average human walks with 3-5 km/h. When you fast you reach even 10-13 km/h. Anyway, you don't have do window shopping or sightseeing. Products are expensive and the city is boring.
win ~ 2 hours a week

3 - use a mindmap
Thinking on things you don't remember eats time. Nobody can hold everything in his or her head. With a mindmap you can maintain all the things you are going to do. There are bunch of free mindmap applications on the internet. Freemind, MindMeister, MindOMO... If you don't know the GTD methodology, I suggest you to read about it.
win ~ 2.5 hours a week

4 - create the best desktop environment
You can save a lot of time with a well configured desktop. There are some of the best practices:
  • fast dial icons everywhere (frequently visited bookmarks, most used program icons...)
  • scripts for frequent processes (remote connection, generate things, version tracking practices...)
  • use online tools: email, rss reader, mindmap, storage, server works (thus you can work everywhere)
  • make a unix setup script with your custom configuration files, commands and installation profiles (reduce os installation time)
  • use 2 monitors instead of 1 large
win ~ 3 hours a week

5 - listen power metal a lot
If you are listening dynamic music (power metal, speed metal) you feel yourself to be forced to work faster. And it gives you energy as well.
win ~ 1 hour a week

6 - you have to deal with tiredness
Mature human needs about 6 hours of sleeping a day. But even if you sleep 6 hours, you could be tired. I know coffee is popular, but fruits and vegetables are important as well. And also you can organize your works. For example if you are tired, let's do some boring administration stuff. And thus you can do the hard work when you can concentrate.
win ~ 2 hours a week

7 - buy books instead of reading PDFs (but keep those too)
Books are cheap if you think how they can help your job. And you can read faster real pages than the screen. You can add comments and highlight parts easily as well. But PDF documents are really useful when you want to search on a certain keywords.
win ~ 1.5 hours a week

8 - don't have lunch at home
Making your own food takes a lot of time. Buying ingredients. Preparing. Cooking. Eating. Cleaning. And in this case you have to find out what do you want to eat. And to get healthy ingredients cost a lot. Restaurants are cheaper and more efficient.
win ~ 3 hours a week

9 - buy more RAM and use faster internet connection
Everybody hates waiting for programs to start or give feedbacks. Even if it takes a few minutes it happens a hundred or thousand times a day during your work, so let's multiply it: few seconds x 1000 = few 1000 seconds ~ 1 hour . Don't forget a major rule! If you can get things faster, you get things faster, thus you do get more of them. More = better.
win ~ 1 hour a week

10 - never try to guess how many tips you've got before you write a 'TOP X' article
I wasted about an hour with thinking about the 10th practice. But I haven't got any other really efficient idea. Don't waste your own time with useless things.
win ~ 1 hour

Total - you win ~20.5 hours a week! Not bad. If you get 40$ for an hour it is 820$ a week. So a new MacBook is 1299$ and you can buy one in 12 days:) OMG that's beautiful:)

Be agile, be enthusiastic, be efficient. That's it. Thanks for reading it.
Cheers,

Friday, 13 February 2009

I'm back to sum up the last three weeks

Hi,

Long time no see. First, I'm happy that now I'm working on Pronovix. My new colleagues are awesome. They are really lifehackers:) This company works with Drupal and made several cool stuffs. Until a month ago I'd never participated in any Drupal project. When I began learning from Pro Drupal Development I felt myself strong and energetic and agile. But when I got my first mission, it changed a little bit:) Thinking in a Drupal way is REALLY hard at the first time. You know. Everybody can make a full fledged Ajax site with a strong PHP back-end. But when your hands are tight, it could be a huge pain. And the point. In English. Yeah. That's cool. But I love challenges. Learning is fun. Drupal fun. English fun. Working fun. Thats I guess equal to FUN^4. Not bad.
The other interesting happenings was the installing war. God knows how many times I sad malicious words. Anyway. Its all because my old Asus laptop. There are 4 types of Linux distributions:
1 - not well supported, pain (60%)
2 - deprecated kernel, softwares (10%)
3 - cant detect properly my SiS videocard (10%)
4 - cant detect my Broadcom wifi card (20%)
I know. Every geek is saying that you can always configure your unix based distro. Yes. But I can't. My favorite screenplay:
1 - I need network access
2 - To enable the network I had to fire up my wifi
3 - To fire up my wifi i had to download the firmwares and stuffs from the network
Yes, thats recursive. Maybe some parts of my brain still on running. That cause me a big headache. But I couldn't have a rest because on windows the web development really slow. I tried the follow distros:
Ubuntu (4 version), Mint, SuSE, Debian, Arch, PCLinuxOS, Fedora, Slackware, FreeBSD, PcBSD.
But 2 days ago miracle happened. Just browsed www.distrowatch.com and stumbled upon of Mepis Linux. I've never heard about it. But found quite a lot update, so thought it worth a try. And then ... First it asked me what resolution I want during installation. WOW! Kick ass. Next, it discovered my wifi card and made enable networking. Crazy. Then it can connected to the Debian Lenny repository, so really up to date. Thanks God it uses KDE 3.5.10. Only one defect it has, cant render monochrome fonts. But the default way isn't so bad. I can handle it.
So, I suggest you trying it. At least once. Oh, I forgot the candy:) My webcam is working under Mepis. (Even XP is incapable to do this.) Run and download - http://www.mepis.org/
Last I want to share with you, I found a very delicious gummy candy:) And If I mentioned delicious, I registered on http://delicious.com/. I don't know why I did't take that before. To be honest, I feel shame. You know my bookmarking site idea in my former post. You can follow me there: http://delicious.com/itarato
And one thing at the end. I watched anime. This is a huge step to me. And I get used to drinking coffee in the weekends. Maybe once I'll become to a real geek:)
So. I'm hungry thus this post is over. I hope I could give you at least a small information (use Mepis).
Tomorrow I plan writing a blogpost about 'Top 10 thing which makes you more productive'. Because I'm always striving to be the most productive I can. Now is really bad.
And I wrote a small article about unit/functional testing (Selenium, PHPUnit...), but I need a little time to correct it. Maybe on Sunday.

Cheers,