Thursday, June 16, 2011

Optimize your website

At work as programmer i need to optimize page load time.

So here is some tweaks which you can use for your own web sites.

1. Optimizing your CSS and JS ( Javascript, Jquery and so on... ).
All pages uses css and js. Most of time they are huge. like 50-500 kb for css and same for JS.

Most of time i use the tool to see how fast my page is loading:

http://tools.pingdom.com

Best way to optimize CSS is:
Explode CSS files by parts and use only required ones for pages you are using. After compress it with such tools as http://www.cssdrive.com/index.php/main/csscompressor. And in same time combine these ones together into one single load ( search google for CSS.php combiner ).


Best way to optimize JS is:
Explode by files and use only required code you are using. Compress these files with tools like this: http://www.compress-javascript.com/ ( Some codes don't work after compress, you can try to find another good compressor which will compress better than this one. Let me know if you find anything.. )
In same time combine them with combiners into one file. ( search google for JS.php combiner ).

2. Cache! Best way to optimize website is to use cache.
There also some good tweaks about cache. For example using GZIP cache.
Most of time gzip compressed code with 80% success. For example if you code is 100kb, gzip will compress into 20kb and load it into user browser.
To check gzip compression im using such tools as this one: http://www.whatsmyip.org/http_compression/

3. Images! Less images - better. But as you know, logos and so on.. are important for web sites.
Big web sites as facebook using very nice technique - one big image with all images: http://static.ak.fbcdn.net/rsrc.php/v1/zi/r/uVYVvAILt0K.png

4. HTML, PHP code optimization gives some results too. Spaces, tabs, else { } and so on are pretty good on lowering some kbs...
but each kb less will be some gigabytes less for server load per day-week-month if your web site is big!.

5. Javascript lazyloading - it is very nice tool for loading images. It will load image only if user sees the image. If the image is not in visible spot, it will not be loaded.
Source: http://www.appelsiini.net/projects/lazyload

And remember, that visitor is important of all web sites!

Sunday, May 29, 2011

PHP remove all characters and leave only numbers

function which will remove all but leave only numbers for php:
$string = preg_replace('#[^0-9]#','',strip_tags($string));

p.s. If you are looking for function to delete all except chars and numbers look here:
http://pilotaz.blogspot.com/2011/08/php-string-replace-all-except-numbers.html 

Friday, May 27, 2011

Broken image. Failed to load images fix with JQuery

Today i was solving problem with failed to load images. There was 2 solutions for this - 1) php with getimagesize and 2) JQuery check.

getimagesize showed me warnings so my choice was JQuery.

And it was great choice, because using jquery is always fun.

Code i used for all img ( CSS attribute ):

$(window).load(function() {
$('img').each(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
// image was broken, replace with your new image
this.src = 'http://www.example.com/replace_no_image.jpg';
}
});
});

Tuesday, May 24, 2011

MYSQL - Deleting duplicated entries huge DB

The problem occurred when i had to delete duplicated entries

like this:

id name value
502 john null
503 john null
1000 john smith

solution for this was to group by name and export them to other table

so here is mysql codes:

1. Exporting to new table
CREATE TABLE new-table-name as
SELECT * FROM old-table-name WHERE 1 GROUP BY [column by which to group];

2. Renaming old and new tables ( 'different-new-table-name' , not new-table-name )
RENAME TABLE old-table-name TO different-new-table-name;

3. And finaly renaming new table to old table's name
RENAME TABLE new-table-name TO old-table-name;

Monday, May 16, 2011

Google chrome Program too big to fit in memory [ Solution ]


Today for first time i meet the problem.

I was browsing as always... many tabs - like 10. Most of them are text. Suddenly my pc showed BSOD. After restart google chrome want start. And shows cmd windows for a second.

With cmd.exe ( start > cmd.exe ) , you can run same google chrome to see error message. It was - "Program too big to fit in memory".

After some google searches i read nothing interesting but only complains and questions about the problem.

I was not worried about my bookmarks because im using google sync.

1. So i just opened firefox.
2. Went to Google Chrome download page.
3. Downloaded / Ran setup
4. After installation all came back to normal.

Also last session was saved... and i could see pages which was opened before BSOD.

In worst situation you can lose your bookmarks. So its up to you...

Leave a comment if your bookmarks haven't erased after install. If you didn't used google sync. Cheers.

Hope it will help you guys. 

Thursday, May 5, 2011

Input is not proper UTF-8, indicate encoding !

I faced with the error while exporting huge xml.

My solution for this was changing the code:
foreach($adData as $itemData )
{
$xmlData .= "<item><![CDATA[".$itemData."]]></item>";
}


Into this:
foreach($adData as $itemData )
{
$table = array('&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;');
$data = str_replace(array_keys($table), array_values($table), $itemData);
$date = str_replace(" ","",$data); //there is one strange square symbol. after converting into chars //for blogspot it was removed :(
$data = htmlspecialchars(html_entity_decode($data, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES, 'UTF-8');
$xmlData .= "<item><![CDATA[".$itemData."]]></item>";
}

Hope it will help you solving your problem.
Anyways. Good luck!

Friday, April 22, 2011

Video editor online free - JayCfut


I was trying to find freeware which will silent videos audio track and add another one. I tried some of freewares like - wax , windows movie maker, avidemux ( linux video editor on windows ). Maybe they are good and maybe im not so experienced for the freewares but i found better free ware for myself - jaycut.com . It is website which contains java video editor, and so you can edit videos online.
After finishing your project it will generate file and send url to your e-mail.

Website of the project: http://jaycut.com/

A little about JayCut:
Why edit video online?
No need for downloads or installs
Instant access via any web browser
No specific hardware requirements
Access uploaded content anywhere, anytime
Works on all computers and browsers
Use content on the web in movies, e.g. YouTube videos
Collaborative editing, work together with other users from around the world.
Fueled by a passion for web video and creativity, JayCut was founded in 2007 and has since worked with some of world’s leading brands and received several prestigious awards.
In early 2006 we started asking ourselves if web video couldn't be about more than just consumption. We wanted to add creativity into to the equation. Nine months later, in December 2006, we had laid the foundation for what would come to be the world's most advanced technology for online video editing. The company was founded early 2007 and since 2008 we license the video editing tool to other companies and websites.
Today, JayCut is a privately held company based in Stockholm, Sweden. Our customers include some of theworld’s leading brands, and the company and technology has received some of the most prestigious awards in the industry. But our firm belief is that we've just scratched the surface of what web video can be.
Ask yourself what would happen if anyone could edit video, anywhere, with any mobile device, using any media on the web and finally publish the result to any device or website. Join us in starting this creative revolution!

Video i created:

Friday, April 15, 2011

Solution 1030:Got error 139 from storage engine

Today i meet with one big problem while updating MySQL database. The error is 1030:Got error 139 from storage engine.
The problem is that rows has limit.
I was trying to change limit, but there is no need.

Solution for this is very easy. All you need to change ENGINE of your table. While engine almost does nothing, and it will not effect on your values. ( Please read http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html , before doing something ).

I had no time to read this so i executed the query:
ALTER TABLE `table_name` ENGINE = MYISAM

It worked for me. Hope it will work for you too.

Sunday, April 10, 2011

CSS trick to cover with perfect background width and height


There is one cool trick to fill place with background, even if their sizes different. Just use the code for css:
body {
background-image: url(bg.jpg);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

The goal here is a background image on a website that covers the entire browser window at all times. Let's put some specifics on it:

  • Fills entire page with image, no white space
  • Scales image as needed
  • Retains image proportions (aspect ratio)
  • Image is centered on page
  • Does not cause scrollbars
  • As cross-browser compatible as possible
  • Isn't some fancy shenanigans like Flash

We can do this purely through CSS thanks to the background-size property now in CSS3. We'll use the html element (better than body as it's always at least the height of the browser window). We set a fixed and centered background on it, then adjust it's size using background-size set to the cover keyword.

Works in

  • Safari 3+
  • Chrome Whatever+
  • IE 9+
  • Opera 10+ (Opera 9.5 supported background-size but not the keywords)
  • Firefox 3.6+ (Firefox 4 supports non-vendor prefixed version)

Source: http://css-tricks.com/perfect-full-page-background-image/

The article can also mean: css tricks

Saturday, April 2, 2011

htaccess doesnt work on windows of xampp [Solved]


My situation: I have xampp and perfectly working website. And problem is that site does nothing, while changing htaccess.

Here is solutions for this:

  • go to xampp folder and search for httpd.conf in apache/conf folders.
  • open it
  • make sure that LoadModule rewrite_module modules/mod_rewrite.so is uncommented
  • find all AllowOverride and changed None to All. All AllowOverride!!! There should be 3 of them..
It worked for me.. and might help you.

Happy htaccess editing!

Thursday, March 31, 2011

Search folder and subfolders in text files for a string


While developing on new project which was created not by you, the software always is good for searching something..
Big plus of the software is that it is searching in sub directories... and it searches in text files! And most important it works just great!

Searches text files for strings and combination of strings. Has useful or / and / and not search combinations, and can also use regular expressions. New in version 3, is the built-in viewer / editor that highlights the matched strings and lines.

URL: http://www.sadmansoftware.com/

Page speed checker by Google



Here you go... google launched Page speed online analyzer. While it analyzes, it gives you lots of suggestions after completeing them, you website speed will improve!
There is 2 methods of analyzing - Desktop and Mobile. After analyze you will get number from 0 till 100 which describes your result of website speed.

URL: http://pagespeed.googlelabs.com/

Tuesday, March 22, 2011

Ipod touch stack on Replacing Kernel


The problem appeared after i erased my ipod touch completely again. And once again i faced with the problem... So i already knew what to do...

First of all i tried to jailbreak my ipod touch after completely erasing it. Once i saw "Replacing Kernel" loading i put my ipod touch into DFU mode.

Video tutorial how to boot ipod touch or iphone into DFU mode:



Once your iphone or whatever else in DFU mode, you cant do anything...

So just open iTunes and let it restore it for you.

Once it restored, you can jailbreak it again ( with red sn0w. or whatever else you like to do that with.. )

Have fun!

Rounded corners border CSS Problem in IE [ Internet Explorer ] [ Joomla ] [ Solved ]


Here you go.. There is an css code for "good" browsers to change your div's corners to rounded ones. But "bad" browsers such as Internet Explorer ( IE - IE6, IE7 and so on... doesnt works pretty good under this conditions.. ), so here is solution for this problem.


CSS CODE EXAMPLE OF DIV WITH CLASS = "box"
.box {
-moz-border-radius: 15px; /* Firefox */
-webkit-border-radius: 15px; /* Safari and Chrome */
border-radius: 15px; /* Opera 10.5+, future browsers, and now also Internet Explorer 6+ using IE-CSS3 */
-moz-box-shadow: 10px 10px 20px #000; /* Firefox */
-webkit-box-shadow: 10px 10px 20px #000; /* Safari and Chrome */
box-shadow: 10px 10px 20px #000; /* Opera 10.5+, future browsers and IE6+ using IE-CSS3 */
behavior: url(ie-css3.htc); /* This lets IE know to call the script on all elements which get the 'box' class */

}

There should be like this: "behavior: url(path/to/ie-css3.htc);"

Download url of the ie-css3.htc file. Put the file into root and css folder. ( and into other folders in other cases.. ^^ ):
http://uploading.com/files/dm247e4c/pie.zip/

I faced with this problem while doing rounded corners in Joomla template. Also this resources might be helpful

Thursday, March 17, 2011

Last inserted ID of query in MySQL

For example: You just inserted something into database with query, and you need to receive ID of the last insert. You dont need to create another selection with `id` DESC. All you need to do is just receive id with function called - mysql_insert_id().

PHP: $last_id = mysql_insert_id();

Monday, March 14, 2011

Download video of Flowplayer



Today i was faced with problem - Downloading video of flowplayer. All i wanted to do is to download video from one site to my desktop.

It took me not long time for searching google and result is that i fount freeware! You will need to download it and run from your machine. Its virus free and no stupid tool bars are required to install. So don't worry.

Very easy to use and very well done freeware! Great job developers!

Free downloadhttp://www.streamtransport.com 

Friday, February 25, 2011

Hidden new line in string PHP


I guess you seen the problem, or maybe facing with it at the moment. So if you echo the string with pre tags, it will show normally. But without pre tags, it shows ugly... just like a plain text.

The problem is that there is hidden new lines symbols like /r or /n and so on...

Just by replacing the with str_replace is not enough. So here solution for it:

$value = preg_replace('/[\r\n]+/', '\n', $value);
echo htmlentities($value);

Tuesday, February 22, 2011

Real Megatron Tank from Transformers 2

Can you believe it? Real replica of Megatron Tank from Transformers 2 was made by one chinese metal artist. Full weight of the tank is more than 5000 kg.

Here is image of megatron tank made by fan


And here photos from real life
















Monday, February 21, 2011

Do you need to close apps in your multitasking bar?

No you don't says website - http://www.tipb.com/.

I was wondering about this too and i always close applications in my multitasking desk of my ipod touch 2generation.


Thursday, February 17, 2011

How to test your hardware for problems

To find problem in your hardware you need to test everything... But you need to think... I mean, if windows loads up it means that video card, hard disk, rams, and so on works... Possible case - they works not good as "good", but they still works.

Anyways..

Here is some list of programs and other tricks i found while searching internet how to test your hardware parts.

Ram ( Random Access Memory ):
To test your RAM, you can do just by checking your Task Manager ( Performance tab ). Also you can see how many rums installed by going to "my computer"'s properties.
In harder cases people recommend to download these programs:
Most of the information was fount on ehow.com

Hard Disk ( Hard Drive ):
Most of test which you can do for your hard drive is installed in windows. It called "checkdisk" or chkdsk.exe, you can run it from command line. In other case you can do that from your file explorer:
  1. Go to computer, 
  2. Select hard drive
  3. Open properties
  4. Choose tools tab
  5. Press "Check Now" button, in "Error-checking" section
  6. In showed up windows check all possible check boxes and press Start.
  7. Wait until finishes and press Done. 
Also you can test your hard drive with SeaGate tool ( http://www.seagate.com/www/en-us/support/downloads/seatools ). 16,7 MB

Funny part of this, is that you can listen for sounds which hard drives are making ( in case if it is still working ), and check if it matches one of these ones: http://datacent.com/ . If it does,... i guess you need to change it.

More useful freewares such as "Hitachi Drive Fitness Test" or "Samsung HUTIL" and so on... can be fount here: http://pcsupport.about.com/

GPU ( Graphic Process Unit ):
First of all windows has included tool for this - dxdiag . You can run it from Command line.
  1. Press Start 
  2. Run 
  3. Cmd.exe 
  4. dxdiag 
  5. hit Enter
  6. check Dispay tab, for video card information.
Most popular method to test your video card is to install and run one of Benchmarks product 3DMark. http://www.futuremark.com/

Motherboard:
If motherboard is not working properly you will notice it. Some of these facts says about it:
  • Computer does not boot, and instead gives beep sounds.
  • Computer random crashes.
  • Computer randomly reboots.
and so on..


One of great software to test motherboard is Hot CPU Tester.