Monday, November 25, 2013

How to Install Zurb Foundation 5

Think most of the people having difficulties to install Zurb Foundation 5. Ruby Error messages, "compass watch" not working etc. etc. I had the same issue last night but solved it myself.

This is a small guide, how to Install Zurb Foundation 5 properly in Windows 7.

1. Install Git

As per Zurb Foundation docs, the 1st thing is you have to install Git.
https://msysgit.googlecode.com/files/Git-1.8.4-preview20130916.exe

When installing, choose the  2nd option. (Run Git from Windows command prompt)

Then, manually set configure the Windows Path as follows. (System->Advanced System Settings->Environment Variables)

C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

This will not harm anything in your system, so no need to worry.

2. Install Ruby

2nd thing as per the Zurb Foundation Docs.
http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-1.9.3-p484.exe?direct
Choose this version rather than the 2.00 or 2.00 64bit version. And if you installed any other Ruby version, uninstall it. (But remember the gems you have installed before)

Next Next Finish :)

3. NodeJs

Pretty straightforward.
http://nodejs.org/dist/v0.10.22/x64/node-v0.10.22-x64.msi


4. Restart PC

Path to npm will set when you install NodeJs.

5. Install Bower

Go to the command prompt and type "npm install -g bower"

6. Uninstall/ Install Foundation

If you uninstall ruby, the foundation gem also gone. But to make sure, try below.

gem uninstall foundation
gem uninstall zurb-foundation

If it said 0 gem uninstalled, then your foundation gem gone. What we have to do here is to install the new foundation as per the docs.

gem install foundation

7. Install Compass

Dont forget to Install Compass too. :)

gem install compass

8. Create Foundation 5 Project

YOUR_PATH> foundation new MY_PROJECT

9. Watch Sass Changes

YOUR_PATH> compass watch

10. Finish

Enjoy Foundation 5. :)

Sunday, November 10, 2013

How to submit a form using jQuery, AJAX and PHP

We can submit a form via jQuery, AJAX and PHP from two methods.
1. Data String
2. JSON

Here, Im using the 1st method and it is the easiest.

// link jquery main

$(function() {

// Your Button ID

$("#submit").click(function() {
 
      /* field names */
      var fld1 = $("#fld1").val();
      var fld2 = $("#fld2").val();
      var fld3 = $("#fld3").attr('checked');
      var fld4 = $("fld4 :selected").val(); 

      var dataString = 'fld1=' + fld1 + '&fld2=' + fld2 + '&fld3=' + fld3 + '&fld4=' + fld4 ;
      //alert (dataString);return false;
        
        $.ajax({
          type: "POST",
          url: "./form-submit.php",
          data: dataString,
          success: function(html) {
             var trimmed = trim(html); 
             if(trimmed == 'success') {
                /* Do what you want to do when its success */
            } else {
                /* Error Message */
            }
          }
        });
        return false; 
    });
});



Here I used a very simple method to post data into PHP. Now lets look at the "form-submit" file

$fld1 = $_REQUEST['fld1'];
$fld2 = $_REQUEST['fld2'];
$fld3 = $_REQUEST['fld3'];
$fld4 = $_REQUEST['fld4'];


/* MySQL Insert commands. At the end, echo "success"; */

echo "success";

Why echo Success?
That is the command we are giving for jQuery file saying that the operation did successfully. If form-submit returned a string different than 'success', then its an error.

PS : in jQuery file, i commented "alert (dataString);return false;". You can uncomment this and see whether your dataString is correctly passing or not. coz of return "false", it will not proceed to ajax call. :)

On a later day, lets see how to achieve this via JSON. :)

Thursday, November 7, 2013

How to read folder names/ file names in PHP

1. How to read folder name in PHP

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

/* Do your magic here */

echo $foldername;

}
Don't forget to add '/*' after your folder name
2. How to read file names in a folder in PHP

$folderpath = "./FOLDER-NAME/*.*";

foreach(glob($folderpath) as $filename){

/* Do your magic here */

echo $filename;

}
Don't forget to add '/*.*' after your folder name

Might you will complain that it is reading the whole path, not the folder/ filename you want to get at the end. So follow this trick. :)

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

$newFolderName = str_replace("./FOLDER-NAME/", '', $foldername);

echo $newFolderName;

}
TaDa !!!!

Tuesday, November 5, 2013

How to use the same MySQL query again and again

Actually, what we going to do is to move the internal row pointer to re-query. For this, Im going to use the mysql function mysql_data_seek().


The internal row pointer is the current row position in a result returned by the mysql_query() function.

$sql    = "SELECT * FROM tbl_data";
$result = mysql_query($sql,$con);

while ($row = mysql_fetch_array($result)) {
   /* Show your data here*/
}

/* Call the result info again*/

mysql_data_seek($result,0); 

//  you can change the 0 into any number. From this, it will control from which row number you want to start the query again.

while ($row = mysql_fetch_array($result)) {
   /* Show your data for the 2nd time */
}

Monday, May 13, 2013

Getting the first letters of text using PHP [SafGetFirstLetters]

It is always better to make small small functions and keep a library, I was collecting all my experimental functions since I am in to PHP.

I wanted to take first letters from a line of text and realized that I have to use this for many places. Yesterday I have made a new one "SafGetFirstLetters"?

What does it do?
Example Text: This Is A Example Text Line
Output: TTIAETL

SafGetFirstLetters("Lagoon Water Villa with Private Pool", 5)
will return: "LWVwP"
5 is the limit of the text I have asked from function to return.

function SafGetFirstLetters($Text,$MaxChr){
 $TextArray = explode(" ",$Text);
 $WordCount = count($TextArray);
 if ($WordCount) {
  $MakeText='';
  for ($i_a = 0; $i_a < $WordCount; $i_a++) {
   $MakeText = $MakeText . substr($TextArray[$i_a],0,1);
  }
 }
 if ($MaxChr) {
  return substr($MakeText,0,$MaxChr);
 }else{
  return $MakeText;
 }
}
If you like it please comment.
Thanks.
Safras Ahamed

Wednesday, April 3, 2013

How to create a unique string in PHP (Simple Way)

$string = md5(time()); 


Instead of md5, you can use SHA1 or any other encryption method in PHP OR a mix of them.

Eg :

$string = sha1(md5(time())); 

Tuesday, March 26, 2013

How Get Number of Days in a Month in PHP

Extracted from PHP.net

function days_in_month($month, $year)  { 
return $month == 2 ? 
($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : 
(($month - 1) % 7 % 2 ? 30 : 31); 
}

echo days_in_month(YOUR_MONTH,YOUR_YEAR);


More Simple way by a SafFunction

function days_in_month($month,$year) {
return date('t',mktime(0,0,0,$month,1,$year));
}

echo days_in_month(YOUR_MONTH,YOUR_YEAR);

Sunday, March 24, 2013

SafSendMailV2: A function to send mail using php

I started to make and collect my own function since 2001 and SafSendMail I made it in 2002 for a project where there was lots of mail sending option. If I want to send a mail I have to write whole lot and I didn't like it. Created SafSendMail so that I can send mail as I want using a single line.

Later I made SafSendMailV2 supporting HTML and other stuff as you can see, if any mail sent using V2 it will also record From-IP & From-File. Using this you can Identify different things.




function SafSendMailV2(
 $MYRECIPIENTE_EMAIL,
 $MYRECIPIENTE_NAME,
 $MYFROM_NAME,
 $MYFROM_EMAIL,
 $MYSUBJECT,
 $MYBODY,
 $MYHTML,
 $REMOTE_ADDR,
 $PHP_SELF){
 $MYRECIPIENTE_EMAIL  = "$MYRECIPIENTE_EMAIL";
 if ($MYHTML==true) {
  $MYHEADERS = "From: $MYFROM_NAME <$MYFROM_EMAIL>\r\n";
  $MYHEADERS .= "MIME-Version: 1.0\r\n";
  $MYHEADERS .= "Content-Type: text/html; charset=windows-1256\r\n";
  $MYHEADERS .= "Content-Transfer-Encoding: base64\r\n";
  $MYHEADERS .= "From-IP: $REMOTE_ADDR\r\n";
  $MYHEADERS .= "From-File: $PHP_SELF\r\n";
  $MYHEADERS .= chunk_split(base64_encode("$MYBODY"));
  mail("$MYRECIPIENTE_EMAIL", "$MYSUBJECT", "", $MYHEADERS);
 }else{
  $MYHEADERS = "From: $MYFROM_NAME <$MYFROM_EMAIL>\r\n";
  $MYHEADERS .= "From-IP: $REMOTE_ADDR\r\n";
  $MYHEADERS .= "From-File: $PHP_SELF";
  mail("$MYRECIPIENTE_EMAIL", "$MYSUBJECT", "$MYBODY", $MYHEADERS);
 }
}

How to use?
SafSendMailV2("Recipiente@domain.com","Recipiente Name","Your Name","Your Email","Subject",$MYBODY,true,$REMOTE_ADDR,$PHP_SELF)

How to Integrate Twitter into your Website



With jTweetsAnywhere, its very simple. Its powered by jQuery.

Step 1
Download the Zip package from here and extract them.

Step 2
Link these to your web page header.

<script src="javascripts/jquery.js" type="text/javascript"></script>
<script src="javascripts/jquery.jtweetsanywhere.js" type="text/javascript"></script>
<script src="javascripts/jtweetsanywhere-de-min.js" type="text/javascript"></script>
<link href="stylesheets/jquery.jtweetsanywhere.css" rel="stylesheet"></link>

Step 3
Set this to document.ready function

$(document).ready(function(){
    $('#your-twitter-div-id').jTweetsAnywhere({
        username: 'your-twitter-username',
        count: 5, //how many tweets you wants to show
        showTweetFeed: {
            /*showProfileImages: true,
            showUserScreenNames: true,
            showUserFullNames: true,*/
            showActionReply: true,
            showActionRetweet: true,
            showActionFavorite: true
  },
 });
});
You can customize the CSS file as you like. Simple, isn't it? :)

Saturday, March 23, 2013

JQuery Auto Refresh

Its small code but powerful and helpful.
 
<script>
 var auto_refresh = setInterval(
 function(){
  $('#autorefresh').fadeOut('slow').load('refresh.php').fadeIn("slow");
 }, 20000);
</script>

<div id="autorefresh">Hello</div>

ColdFusion like UUID in PHP



Originally extracted from php.net with minor changes

The main function of an UUID is being unique. UUIDs are commonly use in databases to store a unique string, but not limited to. This function will help you to create a Coldfusion like Universally Unique Identifier (UUID) in PHP. This was customized for ColdFusion UUID format (8-4-4-16) .

UUID is a mix of 0-9 A-F Hex value.


function GenerateUUID() {
return sprintf('%04x%04x-%04x-%04x-%04x%04x%04x%04x',
  // 32 bits for "time_low"
 mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  // 16 bits for "time_mid"
 mt_rand(0, 0xffff),
  // 16 bits for "time_hi_and_version",
  // four most significant bits holds version number 4
  mt_rand(0, 0x0fff) | 0x4000,
  // 16 bits, 8 bits for "clk_seq_hi_res",
  // 8 bits for "clk_seq_low",
  // two most significant bits holds zero and 
         // one for variant DCE1.1
  mt_rand(0, 0x3fff) | 0x8000,
  // 48 bits for "node"
  mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
 );
}


Friday, March 22, 2013

PHP Date Functions with SafDate Functions

This is a set of small functions I use, this will make my life easy, no need to remember all the variables at date() function and you can make some predefined functions that you use always.













saf.date.functions.php
<?php
//Pass 2007-01-22 as date and output  as January 22, 2007
function SafDate1V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("F d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
//Pass 2007-01-22 as date and output  as Jan 22, 2007
function SafDate2V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;

}
//Pass 2007-01-22 as date and output  as Jan 22, 07
function SafDate3V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("M d, y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
//Pass 2007-01-22 as date and output as Sunday Jan 22, 2007
function SafDate4V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("l M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
?>
<?php
//Pass 2007-01-22 as date and output as Sun, Jan 22, 2007
function SafDate5V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = @date("D, M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
?>

Wednesday, March 20, 2013

Beginning - MyCodeGenius

MyCodeGenius is a blog space of our day-to-day code snippets which we use in our programming works that we would like to share with others.

Feel free to ask anything and we'll try our best to help as long as the time permits.

Happy Coding.

Let's start with a meme. :D


Source : www.memecenter.com