

Archive for the 'Programming' Category
I began to use Zend Framework
Author: DeVoid
At work develop a project with the use of Zend Framework. To it with wramework’s i did not work, but enough quickly studied basis and beginnings actively to use him. Today I want talk about feelings and considering which arose up in latter days.
First that it should be noted - Zend Framework lays on serious rules on the structure of catalogues. It is good, as a clear structure of project gives to understand at once, where for you Comptrollers, Models and files of templates which are responsible for a kind.
read comments (0)Enums in C# - use sbyte
Author: DeVoid
C# Code Specification:
The following example declares an enum type named Alignment with an underlying type of sbyte.
enum Alignment: sbyte
{
Left = -1,
Center = 0,
Right = 1
}
When you use enumerations in C# - you easy can declare new values as sbyte. Standart type of variable is int, but you can use and sbyte type.
C# - start only one copy of the program
Author: DeVoid
If you need that the program was started an only to one copy - can take advantage of such simple and useful class:
public class SingleInstance
{
private bool firstInstance = false;
public bool FirstInstance
{
get { return firstInstance; }
}
public SingleInstance()
{
Mutex mutex=null;
try
{
mutex = Mutex.OpenExisting("ProgramName");
}
catch (WaitHandleCannotBeOpenedException e)
{
firstInstance = true;
}
if (mutex == null)
{
mutex = new Mutex(false, "ProgramName");
GC.KeepAlive(mutex);
}
}
}
Now, we need edit Program.cs like here:
[STAThread]
static void Main()
{
SingleInstance single = new SingleInstance();
if (single.FirstInstance)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
Now the program will be started only in one copy. A code works on the different versions of Windows - including Vista.
PHP - array_map and callback functions
Author: DeVoid
callback functions of arrays are a very powerful instrument, using which, a programmer can obtain flexibility and simplicity of work with arrays. The callback functions of arrays are created for modification of content of arrays a method “value after a value”.
We will consider the function of array_map(), which in a general view looks so:
array array_map ( mixed $callback , array $array1 [, array $array2... ] )
the first parameter is a function of treatment of array, must work exactly with the that amount of parameters, which you will pass to it. For an example it is possible to consider simple example which will simply illustrate work of this function:
<?php
function format_values($value)
{
return '<b>'.$value.'</b>+';
}
$myarray = array('first', 'second', 'third');
$formatted_array = array_map("format_values", $myarray);
echo('<pre>');
print_r($formatted_array);
echo('</pre>');
?>
As a result of implementation of this code, we will get the values of our array in a bold style. As the first parameter of function of array_map we passed the name of function which will process every value of array $myarray. It should be noted that function of array_map return an array $formatted_array, every value of which is treated the function of format_values.
Resize Jpeg image using PHP
Author: DeVoid
If you created galleries once - you know how important create the small preview images. In PHP we easy can do it. Now we write small function which will change the size of image. If you need show the image preview do it:
<img ALT="preview" SRC="resize.php?url=image.jpg" />
Here file resize.php:
<?
function resize($img_src)
{
header('Content-type: image/jpeg'); list($width, $height) = getimagesize($img_src);
$source_img = imagecreatefromjpeg($img_src);
$dest_img = imagecreatetruecolor(64, 64);
imagecopyresampled($dest_img, $source_img, 0, 0, 0, 0, 64, 64, $width, $height);
imagejpeg($dest_img);
}
if(isset($_GET["url"]))
{
resize($_GET["url"]);
}
?>
Function simple and to explain as it works it is not needed. But if you need change size of many images
- it is needed to understand that this function will strongly slow work of site.
How to do redirect by web.config in ASP.NET
Author: DeVoid
If you want create the mod_rewrite analogue and use links as mysite/user/DeVoid or send an user on other page - use web.config option urlMappings in ASP.NET:
<configuration> <system.web> <urlMappings enabled="true"> <add url="~/Article28.aspx" mappedUrl="~/MyNewBestArtile.aspx"/ > <urlMappings> </system.web> </configuration>
Using urlMappings you will be able to do your site on ASP.NET more attractive for an user
phpDoc in Eclipse - when the comments become more clear
Author: DeVoid
About importance of commenting of a code was spoken already many times. About importance of commenting of a code was spoken already many times.
If you would want that each class written by you was clear to you and your colleagues - can use the simple standard of record of the comments:
/ **
* Short description - used in indexlists
*
* Multiple line detailed description.
* The handling of line breaks and HTML is up to the renderer.
* Order: short description - detailed description - doc tags.
*
* @param string Target directory for the generated HTML Files
*/
If before the announcement of a class or method to write such comment - IDE will process it and will deduce to you the help at their further use. It is very convenient by collective development and large volumes of a code.
The purpose of methods becomes more clear, the transmitted parameters are deduced, the returned meanings are specified.
It is necessary to note that Eclipse automatically generates preparation under such style of the comment after introduction / ** and pressing Enter before the announcement of a method / class. And to receive the help it is possible on pressing Ctrl+Space after input $myClassName- >.
How-to: Comments in ASP.NET
Author: K_Den
When you create pages in ASP.NET - you must understand what you write. Comments help you write clean and clear code. Comments are the very important instrument of programmer. At the correct use of comments - his code is always clear a programmer and he can change him not reflecting.
Distinguish comments on the server-side and comments which are added to the outgoing HTML file.
If you want to write a comment which will be represented only inwardly aspx pages, and will not be visible an end user, use such syntax:
Read the rest of this entry »
How-to: create page “Site offline” in ASP.NET
Author: K_Den
Today I want to write about the some tricks of ASP.NET, which are very useful.
Sometimes, when you load new files into server or site temporary not work - you must notify users about it. If you use ASP.NET - you can do it easy! Create static html page with message about it and save as “app_offline.htm” (not *.html !!) into root directory of site. Now if users come in to your site they will see beautiful page. When a site will begin to work normally - delete file app_offline.htm.

