It has been a busy week for me on updating this blog. Dealing with a 3rd party developer and letting me learn something new. I don't know everything and I seldom pretend knowing something I don't.
What I have learned from dealing with a 3rd party developer is this option of IIS to compress the content and giving it to the client browser. I sure wasn't aware of it. According to this source: http://www.codinghorror.com/blog/2004/08/http-compression-and-iis-6-0.html
IIS 6 is the server I am currently using for a website done by a 3rd party developer. So that article I linked above is a bit helpful in explaining it. And another link on how to enable it: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true
Here is a link for the IIS 7 configuration: http://www.iis.net/configreference/system.webserver/urlcompression
urlCompression replaces the settings of the IIS in .Net.
Which I found out was already set to send compressed files to browsers. And does not need to be set at all, it is only in IIS 6 and below where it is disabled, since some browsers then do not accept compressed files.
According to the first link, compression makes the plain text size by 75 percent. Not bad, but still if you have a small bandwidth, that will still affect your server and clients that are accessing it constantly.
Website Development & Programming related to front-end and back-end. Tech news: on gadgets, technology for the web and other things I think will be of use to people to be on the know.
Wednesday, October 30, 2013
Saturday, October 26, 2013
what is the value represented in clientCache cachControlMaxAge
I have been given a code by a 3rd developer to update the website they created in .Net.
He just mentioned I place the code, inside the <system.webServer> configuration.
After looking at it I was a bit apprehensive in implementing this setting in the web.config file:
<staticContent>
He just mentioned I place the code, inside the <system.webServer> configuration.
After looking at it I was a bit apprehensive in implementing this setting in the web.config file:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
</staticContent>
I have an idea, it could represent 10 days, but wasn't sure, since this is the first time I saw this code.
After an extensive search, which was hard since there isn't much result on the usage and value syntax for this settings. Also, the result always reflect as IIS, which makes me wonder when I see it if that is correct result.
It is confirmed it represents 10 days. Ten days cache on the client's browser cache, which I don't know how the microsoft technology can do it on client side level. But that was the explaination on this website: http://blog.janjonas.net/2011-08-21/microsoft-iis-7-enable-client-side-browser-caching-static-content-web-config
It says that the static contents such as image file, CSS and javascript files will not change based on the instruction given to the browser, on the page header.
The other source explained for this script can be found here: http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
Which is also based on the first link, to a IIS.net resource, which confuses me, since I thought this was a .Net settings.
If conditional statement in a single line using Operators (?:)
I often forget how to do the simplified condition using the (?:) symbol. And it is very hard to search on what you meant to search at times. It's called the ternary operator logic (?:).
I found a source where it shows just how to do it in different levels of complexity:
http://davidwalsh.name/php-shorthand-if-else-ternary-operators
In case the site goes offline. The Ternary Logic is the process of using the following syntax: "(condition) ? (true value return) : (false value return)". This will shorten the if/else statement to a single line.
But often this technique confuses others not familiar with it. But it is fun way to do it. I still prefer the long way, but will use it to shorten the code at times.
based on the website source link, here is a sample:
I found a source where it shows just how to do it in different levels of complexity:
http://davidwalsh.name/php-shorthand-if-else-ternary-operators
In case the site goes offline. The Ternary Logic is the process of using the following syntax: "(condition) ? (true value return) : (false value return)". This will shorten the if/else statement to a single line.
But often this technique confuses others not familiar with it. But it is fun way to do it. I still prefer the long way, but will use it to shorten the code at times.
based on the website source link, here is a sample:
$var = 6;
$var_result = ($var>3 ? true:false); // it will return true
Wednesday, October 2, 2013
GIT repository problem
We have a 3rd party developer try to give us the updates thru their repository...
Problem is the instruction isn't clear on how to do the update. They expect everyone to know this.
The development manager just placed the command (git pull origin master). I tried running the command in gitbash. Without any instruction of specific folder to be in. Did he expect me to know this, when I have no idea how GIT worked in the first place. Thanks to the internet, now I know why I get the error:
Fatal: Not a git repository (or any parent directories): .git
He should have instructed me to change my directory to the one I cloned before. Thanks to the internet I found the solution here: http://stackoverflow.com/questions/11961600/fatal-not-a-git-repository-or-any-of-the-parent-directories-from-git-status
Problem is the instruction isn't clear on how to do the update. They expect everyone to know this.
The development manager just placed the command (git pull origin master). I tried running the command in gitbash. Without any instruction of specific folder to be in. Did he expect me to know this, when I have no idea how GIT worked in the first place. Thanks to the internet, now I know why I get the error:
Fatal: Not a git repository (or any parent directories): .git
He should have instructed me to change my directory to the one I cloned before. Thanks to the internet I found the solution here: http://stackoverflow.com/questions/11961600/fatal-not-a-git-repository-or-any-of-the-parent-directories-from-git-status
You have to actually cd into the directory first:
$ git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Cloning into 'liggghts'...
remote: Counting objects: 3005, done.
remote: Compressing objects: 100% (2141/2141), done.
remote: Total 3005 (delta 1052), reused 2714 (delta 827)
Receiving objects: 100% (3005/3005), 23.80 MiB | 2.22 MiB/s, done.
Resolving deltas: 100% (1052/1052), done.
$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ cd liggghts/
$ git status
# On branch master
nothing to commit (working directory clean)
Wednesday, July 31, 2013
Email Validation on PHP
I have made email validation before, but have forgotten where I placed that code. I had to look for the RegEx (Regular Expression) around the net, there are some that work at a certain point, but does not if you had something like .com.ph or .com.us or .com.au.
There is also a question about the why the hyphen in his code does not work:
http://stackoverflow.com/questions/7939147/preg-match-email-validation-adding-hyphen-to-domain-spot
There is also this one that works, well almost (upper case letters not allowed on this one):
http://www.developphp.com/view_lesson.php?v=224
Explanations on how to add a hyphen to the Regular Expression:
http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
http://stackoverflow.com/questions/6744587/simple-regex-match-any-string-with-at-least-one-hyphen
So I tweak the code a bit to have the perfect email validation code I have seen so far, and here it is:
$email = "test@test-tester.com.ph" //<-- Works
$Syntax='/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/';
There is also a question about the why the hyphen in his code does not work:
http://stackoverflow.com/questions/7939147/preg-match-email-validation-adding-hyphen-to-domain-spot
There is also this one that works, well almost (upper case letters not allowed on this one):
http://www.developphp.com/view_lesson.php?v=224
Explanations on how to add a hyphen to the Regular Expression:
http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
http://stackoverflow.com/questions/6744587/simple-regex-match-any-string-with-at-least-one-hyphen
So I tweak the code a bit to have the perfect email validation code I have seen so far, and here it is:
$email = "test@test-tester.com.ph" //<-- Works
$Syntax='/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/';
if (preg_match($Syntax, $email)) {
echo $email . \" is a valid email. We can accept it.\";
} else {
echo $email . \" is an invalid email. Please try again.\";
}
Let me know if there is an improvement for this code.
Also a bit of caveat on the preg_match() function:
preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred
as mentioned in PHP documentation:
Tuesday, July 16, 2013
MySQL WorkBench problem cannot create user
'Unhandled exception: Error creating account' error message when creating an account in mySQL Workbench.
I'm using workbench 5.2.31 CE.
This problem have popped up, when I'm trying to create a user in mySQL.
There are two steps to work around this:
- edit the sql-mode configuration. It can be found under Advance tab, Edit the text of sql-mode. Remove the part "NO_AUTO_CREATE_USER," or cut it. Then paste it back after you have created your user.
- Run the grant all previleges script as instructed below.
The solution is very simple. You just have to run one of this statement in the Workbench Query window:
GRANT ALL PRIVILEGES ON *.* TO changetousername@localhost;
GRANT ALL PRIVILEGES ON *.* TO 'changetousername'@'%';
This will create an account without password. So better set the password and change the previleges.
I don't know if this is the best work around or the worst. But if you are desperate to add a user account. This is the way that worked for me.
Here is part of the source of the solution:
http://stackoverflow.com/questions/15673640/unhandled-exception-error-creating-account
I don't know if this is the best work around or the worst. But if you are desperate to add a user account. This is the way that worked for me.
Here is part of the source of the solution:
http://stackoverflow.com/questions/15673640/unhandled-exception-error-creating-account
Labels:
Creation,
Database,
Development,
MySQL,
Programming,
solution,
SQL,
User Account
Tuesday, July 9, 2013
Cookie Setting troubles in PHP
I was trying to determine why the value for a cookie is not reflecting on my page.
Here are some of other developers say you should now in implementing cookies:
There is a problem with the cookie when the mobile browser is never closed. I had my browser open in the background. Even when I set the cookie to expire in 30 mins. It does not happened, since the browser still reads the value even beyond expire date.
Here are some of other developers say you should now in implementing cookies:
- It has to be on top before any code is generated by the page
- Cookie will not reflect on the same page when you set it. It will reflect on the next loading of the page.
2nd one is true. The first one also seems to be true, since no value is placed when I placed the code in the middle and after html codes have been rendered.
Here are the links to those recommendations:
There is a problem with the cookie when the mobile browser is never closed. I had my browser open in the background. Even when I set the cookie to expire in 30 mins. It does not happened, since the browser still reads the value even beyond expire date.
Subscribe to:
Posts (Atom)