Tuesday, October 27, 2009

YouTube Subscriptions fix bookmarklet

UPDATE: Apparently the problem is no longer relevant.
Some time ago YouTube changed the links on http://www.youtube.com/my_subscriptions so that they would open in the same window even if you click it with the third button/wheel. As much as I tolerate other YouTube changes since Google acquired it, this is beyond me. Thus here is my modified version of the AdBlock+ bookmarklet that reverts the links to the way they were.

Drag and drop one of these links to your bookmark toolbar:

YTSF 0.2 - Chrome version (tested in Chrome 3.0.195.38)
YTSF 0.2 - Firefox version (tested in Firefox 3.5.3)

The code:

javascript:(
function(){
function R(w){
try{
var d=w.document,i,T,N,r=1,s;
T=d.getElementsByTagName("a");
for(i=T.length-1;(i+1)&&(N=T[i]);--i)
if(N.className=="title" || N.className=="video-thumb-120 no-quicklist"){
N.href=N.onclick.toString().slice(42,62);
N.onclick='';
}
}
catch(E){r=0}
return r
}
R(self);
}
)()

The original AdBlock+ code can be found here or here.


Read more »

Saturday, March 21, 2009

Make your own Photoshop patterns

Photoshop patternsYou can find patterns on many websites.
Designers often use them spice up their layouts.
In this tutorial I will show you how to make your own patterns for your websites in Photoshop.



Create a new transparent document in photoshop, the width and height varies from pattern to pattern. I specified the sizes for patterns below next to their names.

Next zoom in to the max("Alt" + "Scroll Wheel" or "Ctrl" + "=") and select the pencil tool).
Photoshop pencil tool
All that's left is to reproduce the pixels of your desired pattern.

Once you're done, go to Edit->Define Pattern...
Name your pattern and it's done.

To test the new pattern you can use the "Paint Bucket Tool"
paint bucket tool
Don't forget to select "Pattern" instead of "Foreground" in the tool options.
paint bucket tool options

Or right click on a layer, click "Blending Options".
Blending options
Then go to "Pattern Overlay" and select the pattern you want to try out.
Pattern overlay

Pictures to the left are the patterns zoomed in, while pictures to the right are the previews of the way the pattern actually look.

Diagonal lines A (3x3 pixels)
Diagonal line patternDiagonal line pattern preview
Diagonal lines B (3x3 pixels)
Diagonal line patternDiagonal line pattern preview
Thick diagonal lines (9x9 pixels)
Diagonal line patternDiagonal line pattern preview
Vertical lines (2x1 pixels)
Vertical line patternVertical line pattern preview
Horizontal lines "Scanlines" (1x2 pixels)
Horizontal line patternHorizontal line pattern preview
Holes (10x10 pixels)
These look nice on a colorfull background with the "soft light" blending mode.
Hole patternHole pattern preview
Cells (10x10 pixels)
Cell patternCell pattern preview
Carbon Fiber (4x4 pixels)
Carbon Fiber Photoshop patternCarbon Fiber Photoshop pattern preview

TIP: Try experimenting by using different blending modes and styles on your pattern to make them look even better.
Read more »

Thursday, March 19, 2009

Simple PHP website tutorial

If you ever tried making a simple website with only a handful of pages, you probably noticed that once you need to edit some menu element, you have to edit all of your pages, which can be very irritating.
The simplest way to solve this problem without resorting to coding is using frames. I encourage you not to do that. You can see for your self why.
Instead you can apply one of the following PHP techniques.

1) The content include method
In this method you put the unique content of your pages in different files like "news.html", "about.html" etc. While the HTML that is the same for all the pages, like the menu, stays in index.php.

To make this work you need to put the code that will load the contents of your pages into index.php. In PHP the include() function is just what we need to do the job. Alternatively you can use require(), it won't make a big difference.
Next, through our hyper links, we need to tell that function which file it should load into our main page. We need a variable for that, in this example I will call our variable "page" for the sake of simplicity. Which means that our links would look something like this:

<a href="index.php">Home</a><br />
<a href="index.php?page=page1">Page1</a><br />
<a href="index.php?page=page2">Page2</a><br />
<a href="index.php?page=page3">Page3</a><br />


Now we can work with the include() function.
As you probably noticed form our links above, the first link called "Home" doesn't assign any parameters to the "page" variable. To make include() work and protect our website form the Cross-site scripting vulnerability at the same time we will use a switch().

switch($_GET['page']) {
case
"page1": include('page1_content.html'); break;
case
"page2": include('page2_content.html'); break;
case
"page3": include('page3_content.html'); break;
default: include(
'home.html');
}

Since I chose to call the variable "page" the switch looks this way: "switch($_GET['page']) {" and the next four lines decide which file should be loaded depending on the value of the variable. So the line case "page1": include('page1_content.html'); break; means: if the variable was set to 'page1' then load page 'page1_content.html'.
But the last line: default: include('home.html'); means: if the variable "page" is set to anything else then home.html will be loaded.

One more thing: we have to make sure that the variable $_GET['page'] is set, else PHP will output an error. Therefore we will add this line before the switch():
if(!isset($_GET['page'])) $_GET['page']="";
This line will define the variable $_GET['page']
in case it hasnt already been defined.
(Thanks to Arthur for reminding me)


Now if we put it all together we will get something similar to this:
<html>
<head>
<title>My Website</title>
</head>
<body>

<a href="index.php">Home</a><br />
<a href="index.php?page=page1">Page1</a><br />
<a href="index.php?page=page1">Page2</a><br />
<a href="index.php?page=page1">Page3</a><br />
...


<?php

if(!isset($_GET['page'])) $_GET['page']="";
switch($_GET['page']) {
case
"page1": include('page1_content.html'); break;
case
"page2": include('page2_content.html'); break;
case
"page3": include('page3_content.html'); break;
default: include(
'home.html');
}
?>

</body>
</html>


One of the disadvantages of this method is that all of your pages will have the same title, unless you're willing to write a little bit more code.

2) The menu include method
In this method you have your menu in a separate file like 'menu.html', which you include on all of your html pages like "index.php", "about.php" etc. using this code:
<?php
include('menu.html');
?>


So our typical page would look like this:

<html>
<head>
<title>My Website</title>
</head>
<body>

<?php
include('menu.html');
?>

<h1> Hello and welcome to my website</h1>
The content of the page goes here.

</body>
</html>


This way you can easily have different titles on different pages and easily change your menu on all the pages by editing one file.

In case you have something on the bottom of the page like "All rights reserved" or "This website is a registered trademark..." which is the same on all the pages you can put it in separate file like "footer.html" and include it with the code:
<?php
include('footer.html');
?>


Read more »

Tuesday, March 17, 2009

include, require, include_once, require_once

When it comes to dividing and ruling your code, PHP has a confusing amount of standard functions to do the job. Take include() for example. It works fine so why make the other copycats? To figure that one out there's no better place to go to than the PHP.net. Once there search for the next big thing after include() - require(). And there you have it, the difference between include() and require() is the way the two handle their inability to load the specified file. Upon failing include() would only output a warning, whereas require() would result in a fatal error. 
Therefore, if it is crucial to execute a certain script - require() it, on the other hand if you can do without that script if PHP will fail to load it - include() it.

That being said we can move on to incude_once() and require_once() functions. The sole purpose of adding _once to require and include is to make sure they won't accidently repeat themselves. And in case the PHP interpreter will run in, let's say, require_once('myfile.php') two, three or more times it will simply ignore them, executing the script myfile.php only once. This can be very usefull when your code becomes too big and complex and you don't want PHP to go through the same scripts several times.

There's also the performance issue. When running _once() functions PHP has to check whether the file has already been included or not, but that only becomes an issue when you have hundreds of those.  So if you're interested you can find some controversial benchmark results by Googling something like php include require benchmark or include vs require vs include_once vs require once
Read more »

NeverEverPost #1

Hello world
Read more »