Coding for Good

Fantastic! That’s all I have to say!

Awesome Little Example on how to desaturate and saturate with CSS3 

Great Export Mysql data to CSV – PHP tutorial
Huge thanks to tracend for putting this together!!! Saved me soo many head aches!
 
I just did a few tweaks, timestamped filename and ability to pass in the tablename via a url. Now all I have to do is link to the file /exportcsv.inc.php?table=tablename (if you set target=”_blank” and have it open in a new tab it’ll download the file for the user and close the tab).
 


<?php

$table = “”; if (isset($_GET[“table”])){ $table = $_GET[“table”]; }

function exportMysqlToCsv($table) {

$datey = date(‘Y-m-d’); $filename = ‘subscribers’.’_’.$datey.’.csv’;
$csv_terminated = “\n”;

$csv_separator = “,”;

$csv_enclosed = ‘”’;

$csv_escaped = “\”;

$sql_query = “select * from $table”;

// Gets the data from the database

$result = mysql_query($sql_query);

$fields_cnt = mysql_num_fields($result);

 

$schema_insert = ”;

for ($i = 0; $i < $fields_cnt; $i++)

{

$l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,

stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;

$schema_insert .= $l;

$schema_insert .= $csv_separator;

} // end for

$out = trim(substr($schema_insert, 0, -1));

$out .= $csv_terminated;

// Format the data

while ($row = mysql_fetch_array($result))

{

$schema_insert = ”;

for ($j = 0; $j < $fields_cnt; $j++)

{

if ($row[$j] == ‘0’ || $row[$j] != ”)

{

if ($csv_enclosed == ”)

{

$schema_insert .= $row[$j];

} else

{

$schema_insert .= $csv_enclosed .

str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;

}

} else

{

$schema_insert .= ”;

}

if ($j < $fields_cnt - 1)

{

$schema_insert .= $csv_separator;

}

} // end for

$out .= $schema_insert;

$out .= $csv_terminated;

} // end while

header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);

header(“Content-Length: ” . strlen($out));

// Output to browser with appropriate mime type, you choose ;)

header(“Content-type: text/x-csv”);

//header(“Content-type: text/csv”);

//header(“Content-type: application/csv”);

header(“Content-Disposition: attachment; filename=$filename”);

echo $out;

exit;

}

 exportMysqlToCsv($table);

?>

Super Quick Format date from yyyy-mm-dd to Month Day, Year

var date = 2013-02-04; 
var d = date.split(“-“) ;

var month=new Array(13);
month[0]=”Nothing”;
month[1]=”January”;
month[2]=”Feburary”;
month[3]=”March”;
month[4]=”April”;
month[5]=”May”;
month[6]=”June”;
month[7]=”July”;
month[8]=”August”;
month[9]=”September”;
month[10]=”October”;
month[11]=”November”;
month[12]=”December”;

var m = parseInt(d[1]);
var nDate = month[m] + ’ ’ + d[2] +’, ‘+ d[0];

Get 60 day Facebook Access Token

Pulled from Original Post: http://appdevresources.blogspot.sg/2012/11/extend-facebook-access-token-make-it.html

Step01
The first step is create an app from developer.facebook.com and extend the permission by adding manage_pages and so on to fill your requirement.

Note : manage_pages field extension is required to access facebook fan pages.

Step02
Getting extended access token require the facebook ID and secret to pass in the http call. So make sure you can view your own’s app id and secret from the facebook developer page.

Step03
Now you can go to https://developers.facebook.com/tools/explorer to get the user’s access token for the app you just created. Retrieve the access token by choosing the right app on the top right corner and also make sure that you also need to give extended permission to your requirement such as manage_pages in extended permission session.

Step04
The access that you just get last for just a few hours or less and so you will need to exchange this access token to last up to 60 days instead of just minutes. Fill in your appID, secret and user accesstoken in respective fields and call it in your browser or using curl script. You will then be able to retrieve the exchange access token that last 60days and you can user this access token in your applications to access fan pages or anything that you want.
 
https://graph.facebook.com/oauth/access_token?client_id=&client_secret=&grant_type=fb_exchange_token&fb_exchange_token=
Using Facebook Connect with a jQueryMobile multipage site

This is a quick note based on extending the Hello World Facebook App Tutorial found here: 

Live demo: www.facebookmobileweb.com/hello/

Source code (Github): https://github.com/fbsamples

This is a great simple tutorial to get you up and running, but if you’re using a multipage site with jQueryMobile then be sure to put <div id=”fb-root”></div> just after the opening <body> tag before you start any of your pages. 

<body>
<div id=”fb-root”></div>
<div data-role=”page” id=”awesomeTown”>

I also moved all of the <script> stuff from that tutorial into a fbConnect.js file.

This is my first time really diving into OpenGraph, so far so good!!

Delay / Defer Javascript File Loading

I ran into an awesome issue, where just loading in all my JS files was delaying the loading of our apps in phonegap (especially some coming from outside servers). 

Turns out you can add in “defer” to your script tag and it will not load the script until the page / app is loaded and running.

<script src=”js/script.js defer></script> 

PhoneGap 2.2.0 Android - navigator.connection.type always returns 0

We have a pretty web service heavy app, so as I was working on letting the user know if they don’t have a connect to come back later I ran into this error on Android.

navigator.connection.type was always returning 0 instead of the network state (wifi, 3g, etc). (This was working perfectly for me in IOS).

After a little googlin’ it turns out that there is a bug in PhoneGap 2.2.0 when you try and return the network connection the way they state in the documentation. 

Instead of using: navigator.connection.type

Use: navigator.network.connection.type

Bada bing bada boom, you’re golden!!

Not that it’s a huge bug (we can still get the network connection and move on with our happy little coding lives), they say this will be resolved in 2.3.0.

I also have to shout out to Simon MacDonald and the PhoneGap crew not only for their hard work, but their incredible support. As I search around for bug fixes, creative uses and tutorials these guys are personally responding to issues and taking the time to help out novice users. They personally go above and beyond and I’ve got to say you guys ROCK!!

Creating PhoneGap Android Project Error - An error occurred. Deleting project… — Simple Fix

If your following along with the PhoneGap getting started guide for Android you might run into this error:

An error occurred. Deleting project…

And you’ll be like, look I followed your directions to a T! Here’s what we ended up doing to resolve the issue;

3A. Setup your PATH environment variable on Mac OS:

We put the skd inside a dev folder inside our user folder (/Users/MrHappy/dev/android-sdk-macosx), then used a “~” to help get us there.

export PATH=${PATH}:~/dev/android-sdk-macosx/platform-tools:~/dev/android-sdk-macosx/tools

4. Setup New Project 

We had to tweek the path used when creating a new project as well.  We used the full path instead of the “~” for this part. 

./create /Users/MrHappy/Documents/AndroidDev/poop/ com.picturehealing.poop Poop

 /Users/MrHappy/Documents/AndroidDev/poop/ is the path where I want my project created. Be SURE that you HAVEN’T already created that folder or you’ll still get the error. 

Hope that helps, it was a little headache our CTO helped me out with. 

Granted you can still manually create a phonegap project in eclipse (below is a great tutorial, if you want to understand everything that happening or if for some reason you can’t get this process working), but if you’re creating multiple PhoneGap apps it’s well worth the time to get this working, it’ll be a huge timesaver!

http://www.adobe.com/devnet/html5/articles/getting-started-with-phonegap-in-eclipse-for-android.html