Powered by Cellfex RSS Follow me on Spotify

Archive for April, 2010

I had to enter couple of millions of dummy text entries (with titles and contents) in a database so i created this small PHP script that takes latin letters and sort them out in words. It has some properties to adjust and also a definition of letters and punctuation used. I KNOW, its not perfect but I just wanted to make something automatic, not perfect tool and still it will suite you fine if you want to generate vast amounts of dummy text or just are tired of loripsuming.
function generateDummyText($textLength, $sentenceMinLength, $sentenceMaxLength, $wordMinLength, $wordMaxLength) {
$textOutput = '';
$textCounter = 0;
$letters = 'abcdefghijklmnoprstuvwxyz';
$punctuation = '.!?';
while ($textCounter<$textLength) { $sentenceLength = rand($sentenceMinLength, $sentenceMaxLength); $firstWord = true; $firstLetter = true; for ($sentenceCounter = $sentenceLength; $sentenceCounter>0; $sentenceCounter--) {
if ($firstWord==false) {
$textOutput .= (rand(0,10)==0) ? ', ' : ' ';
}
$wordLength = rand($wordMinLength, $wordMaxLength);
for ($wordCounter = $wordLength; $wordCounter>0; $wordCounter--) {
$letter = $letters[rand(0,(strlen($letters)-1))];
if ($firstLetter==false) {
$textOutput .= $letter;
} else {
$textOutput .= strtoupper($letter);
$firstLetter = false;
}
$textCounter++;
}
$firstWord=false;
}
$textOutput .= $punctuation[rand(0,(strlen($punctuation)-1))].' ';
}
return trim($textOutput);
}

Attributes are pretty selfexplainable, but anyway, here is an example.
$textLength=3000;
$wordMinLength = 3;
$wordMaxLength = 7;
$sentenceMinLength = 20;
$sentenceMaxLength = 100;

feel free to update, change, upgrade, improve or whatever. cheers!

23 Apr 2010

PHP dummy text generator

Author: Edgars | Filed under: Web Development, php

How to avoid bots (and not to use caption plugins which suck)… there is a trick that works almost always (well, It uses javascript and they work for me always and i never seen a bot avoiding it). Of course there are users disabling javascript but thats soooo ’90.
Better is to use plain javascript but with jQuery it will be faster [for me to write this]. So install jQuery.

So when creating a block for forms plugin, make it go elsewhere like <form id=”frmGuestbook” action=”http://go/away“>
MAYBE there are still users from ’90ties which use IE5.5 or Netscape Navigator and really have disabled javascript so maybe its a good idea to put a warnign too like <div id=”msgCantWriteGuestbookWithoutJS”>Sorry, you must have javascript to write enabled to write in guestbook</div>

Then, in the html header put this code.
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('#msgCantWriteGuestbookWithoutJS').hide();
$('frmGuestbook').attr('action', './put/the/real/link/here');
}
</script>

so what it does – with help of jquery it removes a warning and sets normal action attribute for form. Voila. Spam bot walks in, fills out data and gets redirected to http://go/away. Farewell!

there are other tricks but i will tell a bit later (if you dont figure out yourself). For example CSS and empty field trick – Make a 1×1 pixel  transparent input field and name it “name” so bot will 1000% fill it in. And then when you put the posted data in database, just check for value in “name”. If it is filled in, then it was written by nonhuman (or really small miniperson who sees 1×1 pixel text field as normal text field). So, just ignore the post if “name” is not empty.

Anyway, captions are soooooo 2000….

22 Apr 2010

Avoid spambots and spam in HTML forms.

Author: Edgars | Filed under: HTML, Javascript, jQuery

Since i am sitting on Madeira island and cant get home, i was browsing ways to kill time and found this article via CNN.com. Most is rubbish. some are good:

Invent new sport

Invent new vodka flavours…

19 Apr 2010

10 ways to kill ash-cloud time

Author: Edgars | Filed under: DailyStuff

I don’t work often with Photoshop in terms of web design, but as Snow Leopard has cracked something in Fireworks and also for my great pity seems like Adobe bought Macromedia to let some great products for natural extinction, i might have to stick to Photoshop. Of course there is an easier way to get images out of photoshop (hide unwanted layers and crop to guides), but what if i want to move back and change the layer exported. Read the rest of this entry »

12 Apr 2010

Slice your layout and export images using Photoshop

Author: Edgars | Filed under: Web Development

I spilled beer over my mac aluminum keyboard. While i get new one, had tu plug in regular PC keyboard and for my huge dissapointment Cmd wasnt working at all. Of ocurse it is possible to switch keys in keyboard properties, but i it still doesn’t recognize Windows key and anyway – i am used (blind typing) to Cmd where it was (where regular keyboard has Alt) Read the rest of this entry »

9 Apr 2010

How to map keys for “regular” keyboard on Mac OS X

Author: Edgars | Filed under: Mac

If you get annoyed by xHTML opening NEW windows on JavaScript’s window.open even if you call it to _SELF:


then know, that some browsers (safari, chrome, IE, but not FF) get distracted by uppercase _SELF. Rename it to _self and it’s gonna be ok. Kinda stupid, but moving no xHTML strict isn’t as easy as it was ment to be.

5 Apr 2010

JavaScript’s window.open target and _SELF

Author: Edgars | Filed under: Javascript, Web Development

Well, this one of those cases, where “bug” is called “feature“. Or in this case “documented limitation“.

Problem is – MySQL Datetime field does not accept default NOW(). Which should be logic and selbstverstandlich. Read the rest of this entry »

2 Apr 2010

MySQL Datetime field does not accept default NOW()

Author: Edgars | Filed under: MySQL

Billy Corgan had many interesting names for songs. He said this about coming up with titles: “Say you write a song about a chandelier, and the chandelier gives off light. And the light is the color red and red reminds you of the color your not supposed to wear around a bull. So you name the song ‘Cow.’

From here.

1 Apr 2010

Billy Corgan and his naming convention :)

Author: Edgars | Filed under: DailyStuff

There are few common (I’m not talking about all o them, just frequently used) types of data storage in MySQL – texts for texts, integers for integers and blobs for binary data.

So of course, you can always use the largest available, but speaking in terms of efficiency, how do you decide which one of them to use? By max size of content stored there. Read the rest of this entry »

1 Apr 2010

How to select correct storage data type in MySQL

Author: Edgars | Filed under: MySQL, Web Development