Cron timezone problem
I’ve just tried to understand what’s the problem with my crontab. I set it to a proper time but nothing happens. As i guessed the problem is in timezone.
I use Debian linux so here I’ll provide steps how I’ve fixed it:
Configure time zone with dpkg-reconfigure
dpkg-reconfigure tzdata
Link localtime to a corresponding zoneinfo file
ln -sf /usr/share/zoneinfo/Europe/Kiev /etc/localtime
In your case select your time zone.
Restart cron daemon
/etc/init.d/cron restart
In my case this was the fix for the problem. I edited my contab and cron started to work like a Swiss watch
New line to paragraph in PHP
Here’s an example of how to convert new line (LF – line feed, ‘\n’) or carriage return (CR, ‘\r’) followed by new line (CR+LF, ‘\r\n’) to <br> or <p>. In case of double or more breaks we’ll get a paragraph but in case of one break we’ll have <br>.
$text = 'Lorem ipsum\r\n\r\ndolor sit\r\namet.'; // double or more nl to <p> $text = preg_replace('/(\r?\n){2,}/', '</p><p>', $text); // nl to <br> $text = preg_replace('/(\r?\n)+/', '<br />', $text); echo '<p>' . $text . '</p>';
output: <p>Lorem ipsum</p><p>dolor sit<br />amet.</p>
One side shadow in CSS3

As You may suppose, there isn’t a standard way to set the box shadow for only one side of the box or leave one side of the element without a shadow. But You can reach it by using simple CSS tricks. Here You can analyze two examples.
In the first example, we will set box-shadow for only one side of the box.
In the second sample, only one side of the element will be without a shadow.
I hope everybody will understand this CSS so I won’t provide any other description. More code, less water)
Let’s start:
One side shadow
<div></div>div { margin: 30px; height: 100px; width: 100px; position: relative; overflow: hidden; padding: 0 7px 0 0; } div:before { position: absolute; content: ' '; top: 0px; right: 7px; bottom: 0; left: 0; background-color: transparent; box-shadow: 0 0 5px black; border: 1px solid red; }
One side without shadow
<div></div>div { margin: 30px; height: 100px; width: 100px; position:relative; overflow: hidden; padding: 7px 7px 0 7px; } div:before { position: absolute; content: ' '; top: 7px; right: 7px; bottom: -7px; left: 7px; background-color: transparent; box-shadow: 0 0 5px black; border: 1px solid red; }
Zend and “configure db-adapter” command problem
I use Win7 and Netbeans to work with Zend. When I tryed to configure db adapter for MySQL I got an error.
Run command:
configure db-adapter
"adapter=PDO_MYSQL&host=localhost&
username=root&dbname=test&password=555"
Error:
'host' is not recognized as an internal or external command, operable program or batch file. 'password' is not recognized as an internal or external command, operable program or batch file. 'database' is not recognized as an internal or external command, operable program or batch file.
Solution:
I’ve just read lots of forums until I found a solution. When I escaped quotation marks the command begin to run properly:
configure db-adapter
\"adapter=PDO_MYSQL&host=localhost&
username=root&dbname=test&password=555\"
How to return a value form Event in C#
public delegate bool MyEventHandler(object sender /* additional params */); public event MyEventHandler MyEvent; public void MyMethod() { if (MyEvent != null && MyEvent(this)) { /* TODO: do something */ } } public void MyBind() { MyEvent += new MyHandler(this); } private bool MyHandler(object sender) { return true; }
Absolute elements ignore z-index in IE6 and IE7

In this article I will show an example of how to fix the IE 6-7 bug when absolute elements ignore z-index CSS property. In the screenshot above you can see the problem. In the sample below you can see how these styles work in your browser:
HTML:
<div id="column1">1<div id="absoluteDiv"></div></div> <div id="column2">2</div>
CSS:
#column1, #column2 { display: block; position: relative; float: left; width: 100px; margin: 5px; padding: 5px; border: 1px solid red; } #absoluteDiv { display: block; position: absolute; top: 5px; left: 20px; width: 200px; height: 30px; background-color: yellow; border: 1px solid orange; z-index: 10000; }
To fix the bug you need to add z-index property to all the parents of your absolute element until you reach the siblings that overlap your absolute element. So, here’s a workaround:
FIX:
#column1 { z-index: 10000; }
Setting cellspacing and cellpadding in CSS
In this article you can find an example of how to set the cellspacing and cellpadding values with help of CSS styles.
First let’s declare a table with cellspacing and cellpadding attributes and see how it looks:
<table cellpadding="3" cellspacing="3" border="1"> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> </table>
In your browser this table has the following presentation:
| 1 | 2 |
| 3 | 4 |
Now, let’s override the values of cellspacing and cellpadding attributes with help of CSS style:
table { border-collapse: separate; border-spacing: 10px; } table td, table th { padding: 10px; }
If we apply these styles to our table the cellspacing and cellpadding values of the table will be changed:
| 1 | 2 |
| 3 | 4 |
These styles work in all the mordern browsers. If you want these attributes get working in IE 6 and IE 7 you still should use HTML attributes. By the way, cellpadding and cellspacing HTML attributes ARE NOT deprecated so you can fearlessly use them.
What if cellspacing is zero?
If you need to set cellspacing to zero with help of CSS you should use these styles:
table { border-collapse: collapse; } table td, table th { padding: 10px; }
So, applying these styles to the table above we will get:
| 1 | 2 |
| 3 | 4 |
These styles work OK in IE6+.
Browsers
I’ve just tested this example in different browsers:
| FireFox 4 | OK |
|---|---|
| Google Chrome | OK |
| Safari 5 | OK |
| Opera 11 | OK |
| Internet Explorer 8 | OK |
| Internet Explorer 7 | INCOMPLETELY |
| Internet Explorer 6 | INCOMPLETELY |
Need help on CSS properties? Check these links
Accessing a dimensional array in JavaScript
Let’s declare a two dimensional array and try to access the element. Here is the first example:
var array = [[1, 2, 3],[4, 5, 6]]; alert(array[1][1]); // Output: 5
Here is the same sample but with another sytnax:
var array = new Array(2); array[0] = new Array(3); array[0][0] = 1; array[0][1] = 2; array[0][2] = 3; array[1] = new Array(3); array[1][0] = 4; array[1][1] = 5; array[1][2] = 6; alert(array[1][1]); // Output: 5
Again, another syntax of this example to access a javascript array:
var array = new Array(new Array(1, 2, 3), new Array(4, 5, 6)); alert(array[1][1]); // Output: 5
Some developers make the following error when accessing a JavaScript array and wait that the 5 will be returned:
var array = [[1, 2, 3],[4, 5, 6]]; alert(array[1,1]); // Output: [4, 5, 6]
JavaScript interpretes 1,1 as a comma separated expression and this expression returnes 1. Each part of the comma separated expression is executed left to right. The final value of the comma separated expression is the value of the last comma part. So, when you try to evaluate the following script in the sample below you will get the last array item because the value of the comma separated expression 0,1,2 will be 2:
var array = [1, 2, 3]; alert(array[0,1,2]); // Output: 3
Apache redirect examples using mod_alias
Hi! here I will provide few samples of how to create redirect in Apache web server. You can test this examples locally in your localhost.
First example
In the first example let’s redirect to Google search when we trying to go to localhost.
1. Go to the root folder of your web server. In my case, it’s C:\xampp\htdocs\.htaccess and create .htaccess file if it doesn’t exist.
2. At the first line of .htaccess write:
Redirect / http://google.com4. Try to go to your localhost again. Apache will redirect you to Google search.
Second example
In this example le’ts redirect to Google search only when somebody trying to go to a web server folder “my”.
1. At the first line of .htaccess write:
Redirect /my/ http://google.com2. Now, when you go to your localhost you will get the right localhost page, but when you try to go to http://localhost/my/ it redirects you to Google search.
Third example
1. Let’s redirect to a subfolder when querying a subfolder. For instance, when the user entering http://localhost/my/ let’s redirect to http://localhost/site/ or when the user querying http://localhost/my/page.html let’s redirect to http://localhost/site/page.html
2. Edit your .htaccess:
Redirect /my/ /site/mod_alias
All these tricks are done with help of mod_alias so this module has to be turned on. You can read more abous this module at Apache:
Observer pattern example in C#
This article has a simple sample of using Observer pattern. The description of this pattern you can read in other resources or you can understand the basis of the pattern exploring this example. Also, you can download an example in C#. This pattern is also known as Dependents pattern or Publish-Subscribe pattern
class Subject { private List<Observer> observers = new List<Observer>(); public void Attach(Observer observer) { observers.Add(observer); } public void Detach(Observer observer) { observers.Remove(observer); } public void Notify() { foreach (var observer in observers) { observer.Update(); } } }
abstract class Observer { abstract public void Update(); }
class ConcreteSubject : Subject { private int value; public int Value { get { return value; } set { this.value = value; Notify(); } } }
class ConcreteObserver : Observer { private ConcreteSubject subject; public override void Update() { Console.WriteLine("Subject value is {0}.", subject.Value); } public ConcreteObserver(ConcreteSubject subject) { subject.Attach(this); this.subject = subject; } ~ConcreteObserver() { subject.Detach(this); } }
class Program { static void Main(string[] args) { var concreteSubject = new ConcreteSubject(); var concreteObserver = new ConcreteObserver(concreteSubject); concreteSubject.Value = 10; } }
As an output you will have: Subject value is 10.

