Translate

Friday, May 15, 2015

Convert a date into Timestamp in Javscript



To convert a date into timestamp milisecond  in JavaScript we are going to use the function new Date() that JavaScript provide  to deal with dates.

Basically, this is code:


//convert date into a timestamp milisecond
var oDate = new Date('2015','05','12','07','30','00');

//printing the timestamp   
console.log(oDate.getTime());


Explanation:

The function  Date() , receives the following parameters:
new Date(year, month, day, hours, minutes, seconds, milliseconds)

so,the Object oDate(Variable) has a method called getTime, that you can access to convert the date into a timeStamp.


Output:

1434115800000


NOTE: In javascript, the conversion to timestamp is in timestamp millisecond and not timestamp epoch. 


Wednesday, May 13, 2015

Regular Expressions You Should Know(REGEX)


In this section, I will be writing some REGEX that could be helpful  to your  projects.



REGEX #1: Numbers Separated by comma or blank spaces.Example(1,2 ,3  ,4)



   //Numbers Separated by comma or blank spaces
   ^[\d]{1,}(\s*,\s*[\d]{1,})+$
 
 

REGEX #2:  Only number


   //Only Number
   ^(\d)+$
 
 
REGEX #3: Alphanumeric


   //Only Alphanumeric 
   ^(\w)+$
 
 
REGEX #4: Validate URL (either http, https or IP number)

   //Validate URL (either htpp,https or IP number)
   ^(http|https):\/\/([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?$
 
 
REGEX #5: Validate Emails. Example : myUser.test01@gmail.com

   //Validate emails
   ^[\w_.+-]+@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$
 
 

REGEX #6: Validate Hours format

//Validate Hours Format
^[\d]{1,2}:[\d]{1,2}:[\d]{1,2}$



REGEX #7: Validate date format

//Validate date Format
^[\d]{2}\/[\d]{2}\/[\d]{4}$



REGEX #8: Validate IP number format (IPV4)

//Validate IP number format (IPV4)
^[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.[\d]{1,3}$



REGEX #9: Regular expression to limit number of characters to 10

//Limit number of characters to 10
^[a-zA-Z]{1,10}$



REGEX #10: Regular expression: Match Not equal to the string "login"

//Match Not Equal to the string "login"
^(?!login$).+$


Monday, May 11, 2015

How to Delete an element from an array?





In this post, we will answer the question : How to Delete an element from an array?

First of all , we  will create our own array called :$aFruits


  
   $aFruits = array('apple','lemon','grapes','pineapple');
 

Secondly,  if we want to delete the lemon element, we have to use the function called unset and we need to access to  that element by  its  position number.


  
  unset($aFruits[1]);
 

Ouput:
 Array ( [0] => apple [2] => grapes [3] => pineapple )

Wednesday, April 29, 2015

Mysql SQL Error 1093 You can't specify target table



In this post, we will learn how to resolve this "Mysql Error 1093 You can't specify target table"



I was trying to delete some data using  this query:



DELETE  FROM articles
where art_id  in (select a.art_id
                          from articles a
                         where a.art_date <= '2015-05-19'

                        );
 

When I executed this query an error suddenly appeared that was: Mysql Error 1093 you can't specify target table.


What was the problem?
 Basically, the delete statement doesn’t allow to perform a sub-query using the same table.

How can I overcome this?

The solution, that I found was quite easy, is as simple as this: you have to wrap the
sub-query in one more select .

Solution:





DELETE FROM articles
 WHERE art_id in (
     SELECT aid FROM(
      SELECT a.art_id FROM articles a WHERE a.art_date <= '2015-05-19'
  ) as a
 );
 







Friday, November 7, 2014

How to remove the letter of an alphanumeric string


How to remove the letter of an alphanumeric string



In this post, I'll  try to explain how to remove the letter of an alphanumerics string.Maybe this tutorial could be helpful for you :

we have the following code:



  $sMystring = 'Tra789asdf'; //1
  $pMypattern = '/[a-zA-z]/'; //2
  $sMyreplacement = ''; //3
  echo preg_replace($pMypattern, $sMyreplacement, $sMystring);//4
 

Code explanation:

First Line: We have our alphanumeric string ,I mean a combination between numbers and letters.

Second Line: We have out REGEX pattern, which identify the letter in our string $pMypattern.

Third  Line: We have a variable that will use to replace the letter, by that I mean instead of letter we  will have in the string blank spaces.

Fourth Line:  We will have our output and it is important to note the preg_replace
 which  identified in the string the pattern and remove the matches and replace with the new value in our case is: $Myreplacement.


Output : 789

If want the opposite output, I mean remove the number the code will be:
   

    $sMystring = 'Tra789asdf';//1
    $pMypattern = '/[0-9]/';//2
    $sMyreplacement = ''; //3
    echo preg_replace($pMypattern, $sMyreplacement, $sMystring); //4
 

Output :: Traasdf


La Gloria de Dios

La Gloria de Dios




LA GLORIA DE DIOS: La iglesia existe para exaltar la Gloria de Dios.
Dios es glorioso! y nosotros conocemos su Gloria por medio de la cruz, la naturaleza nos enseña acerca del ingenio de Dios, de su bondad, de su creatividad, hermosura,
Pero es la muerte de Jesús en la cruz y su resurrección la que nos enseña que Dios es Airado, pero a la vez Misericordioso, Justo pero a la vez Dios de Gracia, que es Santo pero a la vez Amor.... Por tanto, esta custodia de su gloria ante el mundo que Cristo nos dejó, ha quedado en manos de la iglesia... somos mayordomos de la gloria de Dios por medio de el evangelio, pero es necesario que nos mostremos fieles.

REGEX  :Identify Comma outside  Double Quotes







If  you want to identify each comma outside double quotes this is the regex:

(?!\B"[^"]*),(?![^"]*"\B)

Result:


but if you are using PHP the regex above  will not going to work ,so you can use this regex: 

Regex: (,)(?=(?:[^"]|"[^"]*")*$)

Result: