Friday, December 14, 2012

How to check CheckedListBox item with single click in Windows Forms Application?

If you want that when you check an item in CheckedListBox control in Windows Forms Application the item to be checked from first click there is a trick you need to do it.
As I developed more with Asp.Net, web applications, it was very awkward for me that when I checked the item in checkedListBox control it did not checked it but rather kind of selected it.
Well, in order to answer your question you have to make only one modification: select the control and then press Alt + Enter for Properties and then look for CheckOnClick property. Set it on True.

There you go :)
If this post helped you, leave a comment or share it :)

How to get rid of 'Saving Changes Is Not Permitted On SQL Server 2008 Management Studio'?

Well that is really annoying. Isn't it? This often happens when you want to alter a table: change data type on existing columns or change allow null on existing columns.
Good, so how do you get rid of this warning: Saving changes is not permitted ?

These are the steps:
1.Open Microsoft Sql Server Management Studio 2008 (I guess it is already opened)
2.Go to Tools(in menu) and click Options
3.Click Designers
4. and Uncheck 'Prevent saving changes that require table re-creation' option
5.Go OK and retry alter your table.

Here is a print screen.

There you go. Continue programming.

Monday, November 26, 2012

How to INSERT into a table records extracted from another table?

If you want to insert values from one table into another you can use this sql query.

select [USERNAME] ,[PASSWORD], 'I'

Don't use any extra 'VALUES' or parenthesis.

How to solve error 15128 in Microsoft Sql Server ?

If you ever meet this nice Sql Error, 15128 in Microsoft Sql Error you must do these next steps. At least they worked for me :)
First I want to explain which is the scenario. You are logged with Windows Authentication and you created a new sql login. Now you want to disable Enforce Password Policy. When you want to do that Sql tells you that you can not save the user, a new password must be set.

  • double click on new login created, leave the check boxes checked(enforce password policy and enforce password expiration) and change user's password temporally to what ever you want, click OK
  • then reopen and uncheck enforce password policy, enforce password expiration; Press OK
  • finally you reopen the user and specify the password you want
  • Test it ;)
Hope this will help you.

Wednesday, October 10, 2012

How to get total number of tables in a database in SQL?

It might happen that you will have to start working on a big database, someday. So, just out of curiosity if you ever want to find total number of tables that are in your table you can use this simple query:

SELECT COUNT(*) as TotalTables FROM sys.tables WHERE type in ('u') 

Of course, first you have to connect to your database. Hope it helps.

Thursday, October 4, 2012

How to get country, city, language for an ip address, in Asp.Net?

When you want to get location information about a client that visits your website according to its ip address you can use a third party service that offers this info in real time or you can use free services, which might not work 100% accurate. However, no matter which service you shall choose you can use the same workflow as I used in my project example.

I created a class that will be used to deserialize json response from api service from
 private struct GeoIPResponse
//this is the response I get
        public string IP;
        public string continentCode;
        public string continentName;
        public string countryCode2;
        public string COUNTRY;
        public string countryCode3;
        public string countryName;
        public string regionName;
        public string cityName;
        public string cityLatitude;
        public string cityLongitude;
        public string countryLatitude;
        public string countryLongitude;
        public string localTimeZone;
        public string localTime;
then I defined some needful methods: 

    /// Returns Client Ip Address
    static public string ClientIpAddress
            string _clientIPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (!string.IsNullOrEmpty(_clientIPAddress))
                string[] ipRange = _clientIPAddress.Split(',');
                _clientIPAddress = ipRange[ipRange.Length - 1];
                _clientIPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

            return _clientIPAddress;


    public string _WebRequest(string strURL)
        String strResult;
        WebResponse objResponse;
        WebRequest objRequest = HttpWebRequest.Create(strURL);
        objRequest.Method = "GET";

        objResponse = objRequest.GetResponse();
        using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            strResult = sr.ReadToEnd();
        return strResult;

and finally this is the way I used a service from :
protected void Page_Load(object sender, EventArgs e)
        txtMessage.Text = "";
        string Result = _WebRequest("" + ClientIpAddress + "&full=true");

        txtMessage.Text = Result;
        JavaScriptSerializer jss = new JavaScriptSerializer();
        var clientGeoLocation = jss.Deserialize < GeoIPResponse >(Result);

        lblMessage.Text = "
Your short details: " + "Country: " + clientGeoLocation.COUNTRY + ", CountryCode 2: " + clientGeoLocation.countryCode2 + ", CountryCode 3: " + clientGeoLocation.countryCode3 +
            ", TimeZone: " + clientGeoLocation.localTimeZone;

Wednesday, October 3, 2012

How do you test if a string is null or empty?

Today as I was studying something related to Asp.Net I got to an example where I had to test if a string variable is null or just an empty string. So, which are the possibilities and which is the most efficient?

  • if(myString == String.Empty)
  • if(myString == "")
  • if(myString.Length == 0) - this could throw an exception if myString is null
  • I also found this comparison: if( String.Equals(myString, String.Empty) )
  • and of course method IsNullOrEmpty introduced in .Net Framework 2:
    if(string.IsNullOrEmpty(myString)) which is said to be the most efficient.
Now, which methods do you use when comes to test if a string has a value or not? You are invited to write them as comments :) Of course that no matter which one of the methods above you choose won't slow down to much the performance of your application, but is good to build a good practice for future projects, isn't it?

Tuesday, September 18, 2012

How to format a number to x decimal places in C#?

If you have a decimal, double or int data type number and you want to show the number with a certain decimal places then you can use ToString() method from System namespace.
Have a look at these examples. I hope you will find what you need.

Friday, July 27, 2012

How to rename the /Umbraco directory?

When you want to rename the /Umbraco directory are two possibilities.

  1. You rename folder to 'admin', or whatever you want; change in web.config some lines - where is umbraco -> admin. Choosing this solution might not be that nice. When you will install a new package that will try to install on /Umbraco folder, so you will have to move files. Beside you still have to make some updates in Css files as it is hard-coded the paths.
  2. The second solution it is a very simple one :) Go to yoursite/Umbraco/UrlRewriting.config and add this  line in <rewrites> 

Good luck, ;)

Monday, July 23, 2012

How to create a sitemap/navigation for website in Umbraco with XSLT?

Working on a project, made in Umbraco CMS, I got to the point where I had to generate a navigation in footer. Just something like this

This is content Tree. Not all pages from footer image above appear in sitemap structure. I put the image just for you to realize what I had to do and what you might also want to achieve.

Now: according to my content, I wanted a list like this:

  •  About Patient Direct with childs bellow
  1.  Program Coverage (this page as you can see in image above has Hide in navigation = yes, so for me means they are childs of About....) 
  2.  Eligibility 
  •  Network 
  1.  About the Patient...
  2.  Dentist Search 
  •  Enroll Now 
  •  Wellness
Pretty nice, hm?
Good so how do you generate such a menu using Xslt?
Here is code I did and helped me.

< ? xml version="1.0" encoding="UTF-8" ? >
xsl:stylesheet [
    < ! ENTITY nbsp " ">
] >






  • bottom_border
  • bottom_border
If you need explanations about code please write it as a comment ;)

Monday, July 16, 2012

How to delete all tables from a Database?

If you want to delete all tables from a database you can help yourself by using this query:

DECLARE @TableName varchar(500)
      FOR SELECT [name] FROM sys.tables WHERE type in ('u') 

      OPEN cur

      FETCH NEXT FROM cur INTO @TableName
      WHILE @@fetch_status = 0
            EXEC('DROP TABLE ' + @TableName)
            --select @TableName
            FETCH NEXT FROM cur INTO @TableName
      CLOSE cur
      DEALLOCATE cur 

In case you have constraints take special care you delete tables one by one ;)

Thursday, June 7, 2012

How to delete procedures, user functions or views from a database in SQL?

In order to delete all functions, procedures or views from a database you can help yourself by using this query:

DECLARE @procedureName varchar(500)
      FOR SELECT [name] FROM sys.procedures WHERE type in ('p', 'fn') and is_ms_shipped=0 and name not like 'sp[_]%diagram%'

      OPEN cur

      FETCH NEXT FROM cur INTO @procedureName
      WHILE @@fetch_status = 0
            EXEC('DROP PROCEDURE ' + @procedureName)
            --select @procedureName
            FETCH NEXT FROM cur INTO @procedureName
      CLOSE cur
      DEALLOCATE cur

How to get list with procedures, functions or views in Sql?

In order to obtain a list with procedures(P), functions(FN) or views(V) in Sql you can run this query:

SELECT [name], [type], create_date, modify_date
FROM sys.objects
WHERE [type] in ('P', 'FN', 'V')
order by [Type ] asc

Tuesday, May 15, 2012

How to convert string to string[] in C#?

It might happen that you receive from POST a variable name that is in fact an array. So in this case you should convert your object into string[]. How do you do that?
Well, as usually, it is simple:
string[] RoomOptions = new string[] { Request["room_options"] };
So there you are.
This was for solving asp error message saying:
Error message: Cannot convert type 'string' to 'string[]'

Friday, May 11, 2012

How to make an update query using join in SQL

Today it helped me a lot this page which instructed me how to make an update query using join. So you can go and check it out on

Here you can see how I wrote my update command:

                        UPDATE  O
set O.Payed = Payed - 1, O.PaymentDate = null , refPaymentMethodId = null
from [Orders] O
join PaymentMethod pm on pm.PaymentMethodID = O.refPaymentMethodID
where OrderID = @OrderID and pm.GenerateReceipt = 1;

Thursday, April 12, 2012

How to use conditional operator(?:) in c# in a string?

The conditional operator (?:) returns one of two values depending on the value of a Boolean expression.

The condition must evaluate to true or false. If condition is truefirst_expression is evaluated and becomes the result. If condition is falsesecond_expression is evaluated and becomes the result. Only one of the two expressions is evaluated.
Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other.
This is what MSDN says. :)
Now: it might help you to know how to use conditional operator when generate a string. I will give you a simple method which receives a input parameter and according to that will generate a link.

public string GenerateLink(string Option)
        string Response = "";
       Response = "<a href=\"YourPage.aspx?option=" + ((Option == "holiday") ? "goHoliday" : "goAndWork").ToString() + "\">Click</a>";
        return Response;

So, don't hesitate to use conditional operator whenever you are in need of it.
Have a nice day.

Friday, April 6, 2012

How to verify if two strings are equal in Sql?

This question might appear to you when you want to verify credentials for a user at login.
I found out that for SQL these two conditions will give the same result.
1. if(@Password = 'test')
2. if(@Password = 'test ')
(note the space)
So there is a problem.
I found out a simple solution for comparing these two strings. When you compare strings you have to hash them. So we are going to use Hashbytes function. Here you can find more details.
For our example we can verify like this:
if ( HASHBYTES('MD5', convert(nvarchar(50), @Password )) = HASHBYTES('MD5', 'test ' ))
will return expected result.
One think to note: it is important to keep in mind datatype. Datatypes must be the same otherwise you won't get the same hash. Md5 has in mind even data types when converting ;)

Hope will help you.

Friday, March 9, 2012

How To Allow Blocked Content on Internet Explorer

I thought that will be great if I will post here on this blog for anytime when I found an article on the internet that helped me. So based on this idea I am going to give you a short description of problem(found in title, maybe) and the link to the solution.
So one of my question of today was: How To Allow Blocked Content on Internet Explorer?
Instructions found you can get at

Friday, March 2, 2012

How to validate if an email address is syntax valid in C#?

As a simple question: how do you validate if an email address is correct? (by syntax point of view)
If you need this function, to validate an email address you should use this method which is using regular experssions:
public bool IsEmailSyntaxValid(string emailToValidate)
            return System.Text.RegularExpressions.Regex.IsMatch(emailToValidate,

Thursday, March 1, 2012

How to disable textarea resizing with Css?

Today I had to make `something` so my textarea field could not be resized. There might be different reasons why a user should not resize a textarea(which is a default setting in most browsers).
So if you want your textarea to be fixed, no rezise just use this in your css style:

.your_div textarea {
    resize: none;

There you go :)

Wednesday, February 29, 2012

Goodle Doodle: Gioachino Rossini's 220th birthday / Leap Year

Google doodle celebrates leap year

Google's latest doodle celebrates the leap year and Italian composer Gioachino Antonio Rossini's 220th birthday. The doodle showcases four frogs, each closely associated to one of Rossini's best-known comic-opera "The Barber of Seville'. 

Gioachino Rossini, in full Gioachino Antonio Rossini   (born Feb. 29, 1792, Pesaro, Papal States [Italy]—died Nov. 13, 1868, Passy, near Paris, France), Italian composer noted for his operas, particularly his comic operas, of which The Barber of Seville (1816), Cinderella (1817), and Semiramide (1823) are among the best known. Of his later, larger scale dramatic operas, the most widely heard is William Tell (1829).

Google doodles are the decorative changes that are made to the Google logo to celebrate holidays, anniversaries, and the lives of famous artists and scientists. The first doodle was created by Larry Page and Sergy Brin in the year 1998 to mark the celebrations of the Burning Man Festival. Google currently has over 1000 doodles. Google recently revamped its doodle site, which features largely all doodles created by the company. The website also gives a peek into the creative process that goes into creating these doodles. 

Tuesday, February 28, 2012

How to use transactions in MySql?

Today I struggled a few hours just making transactions work.
But first: why should we use transactions? I will give you a short example.
Let's suppose we want to transfer points, money, credit from one user to another.
So we would have two queries:

update user set credits='100' where userId = 1;
update user set credits='0' where userId = 2;

So, in case when first query throws an error all queries run must be `reversed`. So in this case transactions are very useful.
Here is an example I use, it is a very basic one:

SET autocommit=0;

select * from product where deleted=0 and name='Juice Coke';

insert into product(name, fk_category, fk_packaging, fk_stock, active, decimals, price, has_special_price, special_price_description, added_date, deleted)
values ('aJuice Coke','2','4','1','1','2','100.244','1','DESC SPECIAL PRICE','2012-02-28 08:26:47', 0 );

select * from product where deleted=0 and name='Juice Pepsi';

I have some select queries and an insert. Case when insert throws error it should be roll backed all transaction queries. However in these query lines i don't catch errors or just for you to see the idea how it works.
Now, after you catch the idea there might be a problem :) You will not be able to run transactions if your table's engine is MyIsam ! Must be InnoDB !!!
As I found a helpful post I will write here the basics about those two engines and give you the url of the source where you can find more.


Let's start with MyISAM since it is the default engine with MySQL. MyISAM is based on the older but proven ISAM code but has been extended to be fully-featured while retaining the reliability. Data in MyISAM tables is split between three different files on the disk. One for the table format, another for the data, and lastly a third for the indexes.
The maximum number of rows supported amounts to somewhere around ~4.295E+09 and can have up to 64 indexed fields per table. Both of these limits can be greatly increased by compiling a special version of MySQL.
Text/Blob fields are able to be fully-indexed which is of great importance to search functions.
Much more technical information can be found on MySQL's MyISAM Manual Page.


InnoDB is relatively newer so the scene than MyISAM is so people are still weary about its use in environments than run fine under MyISAM. InnoDB is transaction-safe meaning data-integrity is maintained throughout the entire query process. InnoDB also provides row-locking, as opposed to table-locking, meaning while one query is busy updating or inserting a row, another query can update a different row at the same time. These features increase multi-user concurrency and performance.
Another great feature InnoDB boasts is the ability to use foreign-key constraints. FK constraints allows developers to ensure that inserted data referencing another table remains valid. For example, if you had an authors table and a books table and you wanted to insert a new book while referencing the author. The author would have to exist in the authors table before inserting them in the books table because a foreign key was specified in the books table. At the same time you would not be able to delete an author from the authors table if they had any entries associated with them in the books table. More on this in a later article...
Because of its row-locking feature InnoDB is said to thrive in high load environments. Its CPU efficiency is probably not matched by any other disk-based relational database engine.
Here is the link source:
I will give you more details about transactions only if you request :)

How to display current thread in mysql?

This is going to be a very short post. :) If you would like to know how many transactions remained uncommitted(opened) in mysql server then all you have to do is just run this query on your mysql server.


Short, isn't it? 

Monday, February 27, 2012

How to get an array with properties of an object in Php?

If you ever need to get an array of properties for an object in php this is the method that I created and might help you with that. The key is to use get_object_vars() method, parse each key and memorize in an array.
//Returns an array with properties of an object
 function GetAnArrayOfPropertiesForAnObject($Object)
  $arrayProperties = get_object_vars( $Object);
  foreach($arrayProperties as $key=>$value)
   $returnArray[] = strtolower($key);
  return $returnArray;

Wednesday, February 22, 2012

Goodle Doodle: Heinrich Rudolf Hertz's birthday marked with Google doodle wave

Heinrich Rudolf Hertz has been honored with a Google doodle marking the 155th anniversary of his birth.

Heinrich Rudolf Hertz (February 22, 1857 – January 1, 1894) was a German physicist who clarified and expanded the electromagnetic theory of light that had been put forth by Maxwell. He was the first to conclusively prove the existence of electromagnetic waves by engineering instruments to transmit and receive radio pulses using experimental procedures that ruled out all other known wireless phenomena.

Hertz was born in Hamburg, then a sovereign state of the German Confederation, into a prosperous and cultured Hanseatic family. His father, Gustav Ferdinand Hertz, was a writer and later a senator. His mother was the former Anna Elisabeth Pfefferkorn. His paternal grandfather David Wolff Hertz (1757–1822), fourth son of Benjamin Wolff Hertz, moved to Hamburg in 1793 where he made his living as a jeweller. He and his wife Schöne Hertz (1760–1834) were buried in the former Jewish cemetery in Ottensen. Their first son Wolff Hertz (1790–1859), was chairman of the Jewish community. His brother Hertz Hertz (1797–1862) was a respected businessman. He was married to Betty Oppenheim, the daughter of the banker Salomon Oppenheim, from Cologne. Hertz converted from Judaism to Christianity and took the name Heinrich David Hertz.

While studying at the Gelehrtenschule des Johanneums in Hamburg, he showed an aptitude for sciences as well as languages, learning Arabic and Sanskrit. He studied sciences and engineering in the German cities of Dresden, Munich and Berlin, where he studied under Gustav R. Kirchhoff and Hermann von Helmholtz.
Part of the source: Wikipidia

Monday, February 20, 2012

How to verify if checkbox was checked in PHP after submit?

Often when you have a form in a html file(might be even php file as you might know) and submit to a php file you want to see if checkbox from your form was checked so you will save in your database accordingly some value.
I have a form like this:

<form name="AddUser" method="post" action="createUser.php">

<legend>Add a user </legend>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" />

<label for="newsletter">Subscribe to newsletter:</label>
<input type="checkbox" name="newsletter" id=" newsletter " value="" />

<input type="submit" name="add_user_btn" value="Create" />

As usually the solution is simple, using isset() method:
 $newsletter= 1;
 $newsletter= 0;

Monday, January 30, 2012

How to iterate through a DataTable in C#?

It often happens when you have a datatable in c# but you don't know how many columns has and its names. So, please take a look at this simple example to loop over a datatable rows. If you have any question don't hesitate in comments section.
DataTable dtCompanies = GetCompanies();
        string Message = "";
        int rowCount = 0;
        foreach (DataRow dRow in dtCompanies.Rows)
            Message += "Row:" + rowCount + ", Columns: ";

            foreach (DataColumn dCol in dtCompanies.Columns)
                Message += dCol.ColumnName + "( " + dtCompanies.Rows[rowCount][dCol].ToString() + " ) ";

Saturday, January 21, 2012

How to shut down an application in Asp.Net?

Often when you are updating your website you would not be able to overwrite files, operate in database. That is why you can do the following. Create a file called app_offline.html. In this file you can insert content to show as long time as your application is down for maintenance. You can look here form my application offline page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="">
    <title>Application Offline</title>
            background-color: #ffffcc;
            padding-top: 10px;
            padding-bottom: 10px;
            padding-left: 10px;
            padding-right: 10px;
            border-style: solid;
            border-color: Black;
            border-width: 1px;
    <h1 class="error">
        Website is updating
    <p style="font-size: 15px;">
        This site is currently updating. Please wait for a while.
        <br />

The way app_offline.htm works is that you place this file in the root of your application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online or rename to _app_offline(for example) and you will have the file there for use next time you need it.

Also have in mind that by adding the app_offline.htm the application sends the Application_End and after this function return the rest of the threads of the program are killed. The maximum time of wait for theApplication_End to return is set on the pool settings.

If you stop the full pool then all the sites that under this pool follow the same procedure. If you only open the app_offline.htm then only this site is affected.

To avoid your threads to kill by this shutdown, set a wait state on the Application_End
void Application_End(object sender, EventArgs e) 
    // This is a custom function that you must make and
    //   check your threads in the program

    // after this function exit the rest of the threads are killed.

If you use the app_offline.htm feature, you should make sure you have at least 512 bytes of content within it to make sure that your HTML (instead of IE's friendly status message) shows up to your users.  If you don't want to have a lot of text show-up on the page, one trick you can use is to just add an html client-side comment with some extra content to push it over 512 bytes. You can insert html comments just to make your file bigger.

Thursday, January 19, 2012

Html web color codes and chart, how to get hexadecimal values

It happens very often when you need to get hexadecimal values for colors so you can set them as background color or color of a certain text in CSS style without opening Photoshop or other software. So I think that a useful link is this one I wrote this link because it was useful to me. It is not because of advertising reasons. :)

Tuesday, January 17, 2012

How to detect browser name and version in JavaScript?

In case that you wonder how to detect version of current browser in javascript you can use the next code. If you have any question please leave a comment.
var navigatorVersion = navigator.appVersion;
var navigatorAgent = navigator.userAgent;
var browserName = navigator.appName;
var fullVersionName = '' + parseFloat(navigator.appVersion);
var majorVersionName = parseInt(navigator.appVersion, 10);
var nameOffset, verOffset, ix;

// In Firefox, the true version is after "Firefox" 
if ((verOffset = navigatorAgent.indexOf("Firefox")) != -1) {
    browserName = "Firefox";
    fullVersionName = navigatorAgent.substring(verOffset + 8);
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset = navigatorAgent.indexOf("MSIE")) != -1) {
    browserName = "Microsoft Internet Explorer";
    fullVersionName = navigatorAgent.substring(verOffset + 5);

// In Chrome, the true version is after "Chrome" 
else if ((verOffset = navigatorAgent.indexOf("Chrome")) != -1) {
    browserName = "Chrome";
    fullVersionName = navigatorAgent.substring(verOffset + 7);

// In Opera, the true version is after "Opera" or after "Version"
else if ((verOffset = navigatorAgent.indexOf("Opera")) != -1) {
    browserName = "Opera";
    fullVersionName = navigatorAgent.substring(verOffset + 6);
    if ((verOffset = navigatorAgent.indexOf("Version")) != -1)
        fullVersionName = navigatorAgent.substring(verOffset + 8);

// In Safari, the true version is after "Safari" or after "Version" 
else if ((verOffset = navigatorAgent.indexOf("Safari")) != -1) {
    browserName = "Safari";
    fullVersionName = navigatorAgent.substring(verOffset + 7);
    if ((verOffset = navigatorAgent.indexOf("Version")) != -1)
        fullVersionName = navigatorAgent.substring(verOffset + 8);

// In most other browsers, "name/version" is at the end of userAgent 
else if ((nameOffset = navigatorAgent.lastIndexOf(' ') + 1) <
          (verOffset = navigatorAgent.lastIndexOf('/'))) {
    browserName = navigatorAgent.substring(nameOffset, verOffset);
    fullVersionName = navigatorAgent.substring(verOffset + 1);
    if (browserName.toLowerCase() == browserName.toUpperCase()) {
        browserName = navigator.appName;
// trim the fullVersionName string at semicolon/space if present
if ((ix = fullVersionName.indexOf(";")) != -1)
    fullVersionName = fullVersionName.substring(0, ix);
if ((ix = fullVersionName.indexOf(" ")) != -1)
    fullVersionName = fullVersionName.substring(0, ix);

majorVersionName = parseInt('' + fullVersionName, 10);
if (isNaN(majorVersionName)) {
    fullVersionName = '' + parseFloat(navigator.appVersion);
    majorVersionName = parseInt(navigator.appVersion, 10);

// + 'Browser name  = ' + browserName + '
// + 'Full version  = ' + fullVersionName + '
// + 'Major version = ' + majorVersionName + '
// + 'navigator.appName = ' + navigator.appName + '
// + 'navigator.userAgent = ' + navigator.userAgent + '

My most popular images for sale at Shutterstock:

Find my story and how you can get into stock photography, too.

Monday, January 16, 2012

How to fix permissions for files on a server?

Often after you upload files on a server you will get to the point when you won't be able to edit/delete add other files. It happened to me when I unzipped an archive directly on server with a php file.
So how do we change attributes?

set_time_limit ( 0 );


function file_fix_directory($dir, $nomask = array('.', '..', 'CVS')) {
  if (is_dir($dir)) {
     // Try to make each directory world writable.
     if (@chmod($dir, 0777)) {
       echo "

Made writable: " . $dir . "

"; } } if (is_dir($dir) && $handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (!in_array($file, $nomask) && $file[0] != '.') { if (is_dir("$dir/$file")) { // Recurse into subdirectories file_fix_directory("$dir/$file", $nomask); } else { $filename = "$dir/$file"; // Try to make each file world writable. if (@chmod($filename, 0777)) { echo "

Made writable: " . $filename . "

"; } } } } closedir($handle); } }

Monday, January 9, 2012

How to substract 2 ArrayLists in C#?

Well the answer might be really easy for some of you but for newbies is not.
So considering that we have 2 arraylists.
ArrayList FirstArray = new ArrayList(new[] { "23", "25", "27" });
ArrayList SecondArray = new ArrayList(new[] { "25", "28", "29" });

and we want the difference.For that this is what you have to do. Call a method that I implemented.
ArrayList Difference = Substract2ArrayLists(FirstArray, SecondArray, true);
    /// Substracts 2 array lists/a difference

First ArrayList

Second ArrayList

True if compare string, False for long values
    static public ArrayList Substract2ArrayLists(ArrayList First, ArrayList Second, bool IsString)
        if (IsString)
            foreach (string secondValue in Second)
            foreach (long secondValue in Second)
        return First;

Monday, January 2, 2012

How to insert embedded code into a post on Blogger?

As I have just started to write in this blog 3 days ago I came to an issue: how to insert highlighted code, snippets of code: csharp, javascript, css, sql, cpp, python, ruby, xml or perl. I googled a little and found this solution: Go to Dashboard page of your blog and go to Template -> Edit HTML -> Proceed. Then just before closing of head tag, insert next lines.

As you can see source of codes come from so you can find last updates right on that blog. Of course, if you are not going to insert let's say Python code than it won't be necessary no insert that line () Save your template and go to a new post. There are two possibilities to insert snippets code.

  1. Using script tag
    Result is:
  3. Using the pre tag
  4. // Comment
    public class Test2 {
    public Test2() {
    public void AMethod() {
    /* Another comment */
    string  var = "Message";
    Result is:
    // Comment
    public class Test2 {
    public Test2() {
    public void AMethod() {
    /* Another comment */
    string  var = "Message";