Loading HTML Files from Resources to a UIWebView with URL in Xcode

NSString *htmlPath=[[NSBundle mainBundle] pathForResource:@”htmlFile” ofType:@”html”];  // Getting the path of the html file in the resources.

NSString *htmlContent=[[NSString alloc] initWithContentsOfFile:htmlPath]; // Loading the content of the html file.

NSURL *bundleURL=[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; // Creating the URL for the resources.

[webView loadHTMLString:html baseURL:bundleURL]; // Loading the html file to a UIWebView object webView using the baseURL.

Getting database from url

NSString *DB_NAME;

DB_NAME = @"/name.db";

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:DB_NAME];

const char* pathChar = [myPathDocs UTF8String];

int result = sqlite3_open(pathChar, &database);
if(result != SQLITE_OK)
{
sqlite3_close(database);
CCLOG(@"Failed to open Database");
return;
}

How to post a check-in via Facebook PHP SDK

Not sure why posting a check-in on Facebook is such a rare topic on Google – I would expect it to be one of the most written about and searched about topics.
Anyway after hours of Google-ing, trials using graph api and legacy REST api, this is the simplest code (my opinion) to post or do or make a check-in on Facebook.

Assuming that you have the latest Facebook PHP SDK (https://github.com/facebook/php-sdk/downloads) copy this code:
checkin.php

require("src/facebook.php");

// construct the object with your facebook app data
$facebook = new Facebook(array(
'appId'  => '[YOUR APP ID]',
'secret' => '[YOUR APP SECRET ID]',
'cookie' => true
));

try {
	// to get the id of the currently logged in user
	// if, you want you can manually set a user id here like this:
	//$uid = '[FB USER ID]';
	$uid = $facebook->getUser();
	
	// if you know know the access token before hand then you can set it here
	// or you can leave this line commented
	//$facebook->setAccessToken([ACCESS TOKEN FOR THIS USER - APP]);
	
	$api_call = array(
		'method' => 'users.hasAppPermission',
		'uid' => $uid,
		'ext_perm' => 'publish_checkins'
	);
	$can_post = $facebook->api($api_call);
	if ($can_post) {
		$facebook->api('/'.$uid.'/checkins', 'POST', array(
		'access_token' => $facebook->getAccessToken(),
		'place' => '[LOCATION ID]',
		'message' => 'I am place to check in',
		'picture' => 'http://test.com/someplace.png',
		'coordinates' => json_encode(array(
		   'latitude'  => '[LATITUDE]',
		   'longitude' => '[LONGITUDE]',
		   'tags' => '[A LIST OF TAGS TO USE FOR THIS CHECKIN]'))
		));
		echo 'You are checked in';
	} else {
		die('Permissions required!');
	}
} catch (Exception $e){
	// No user found - ask the person to login
	$login_url = $facebook->getLoginUrl();
	header("Location: ".$login_url);
}

Some points to note:

  • If, you are setting an access token manually, then ensure that the user has allowed publish_checkins permission.
  • You must use a valid Location ID that has a page on Facebook
  • The URL to this script must be in the app site Url. For example, if your Facebook app’s site URL is http://myworld.com/ then this script should be somewhere inside http:/myworld.com

Audio file handling in sencha

	
var mpanel = new Ext.Panel({
fullscreen: true,
items: [
{
xtype: 'audio',
url  : "my-music.mp3"
}
]
});

Params & functions:

url: Location of the audio to play.

preload: Will begin preloading the media immediately.

pause: Pauses media playback.

play: Starts or resumes media playback.

remove: Removes a component from this container.

removeAll: Removes all components from this container.

nextSibling: Returns the next sibling of this Component.

insert: Inserts a Component into this Container at a specified index.

hide: Hide the component.

isDisabled: Method to determine whether this Component is currently disabled.

 

Sencha Datastore connection to PHP

Create a Table “Employee” with following fields in Mysql:

ID, FirstName, LastName, Salary

After that you need to create a php file “data-file.php” with script for listing table contents.

Then we need to create a Datastore to connect our php file data_file.php:

EmployeeDataStore = new Ext.data.Store({
id: 'EmployeeDataStore',
proxy: new Ext.data.HttpProxy({
url: 'data_file.php',      // PHP file to connect to database or an array with data
method: 'POST'
}),
baseParams:{task: "LIST-ALL"}, // this parameter asks for listing
reader: new Ext.data.JsonReader({
// we tell the datastore where to get his data from
root: 'results',
totalProperty: 'total',
id: 'id'
},[
{name: 'ID', type: 'int', mapping: 'ID'},
{name: 'FirstName', type: 'string', mapping: 'firstname'},
{name: 'LastName', type: 'string', mapping: 'lastname'},
{name: 'Salary', type: 'float', mapping: 'salary'}
]),
sortInfo:{field: 'ID', direction: "ASC"}
});

 

How to set the keyboard type of input text field in Corona ?

For setting the keyboard type of input text field in Corona,

Use,
object.inputType = type

the possible type’s includes,

“default” – the default keyboard, supporting general text, numbers and punctuation
“number” – a numeric keypad
“phone” – a keypad for entering phone numbers
“url” – a keyboard for entering website URLs
“email” – a keyboard for entering email addresses

Example :
numericField = native.newTextField( 50, 150, 220, 36, handlerFunction )
numericField.inputType = “number”

Downloading an image from a remote url in corona

You can use network.download() to download an image from a url.

local function networkListener( event )
if ( event.isError ) then
print ( "Network error - download failed" );
else
myImage = display.newImage( "sch_logo.png", system.TemporaryDirectory, 256, 55 )
end
print ( "RESPONSE: " .. event.response );
end

network.download( “http://schogini.in/sites/all/themes/theme556/logo.png”, “GET”, networkListener, “sch_logo.png”, system.TemporaryDirectory );

Magento controller, action and what happens when you browse a URL

Assuming you know how to create a custom module, consider a case where you need to create a URL for your module. Follow these steps:

In your module’s config.xml file:

<modules>
.....
</modules>
<global>
....
</global>
<frontend>
	<routers>
		<schurl> --> name that will used in the URL
			<use>standard</use>  ---> standard means its a frontend url; admin will mean it is a backend url
			<args>
				<module>Mage_Schogini</module>  ---> which is the module to be used
				<frontName>schurl</frontName>   ---> name that will used in the URL
			</args>
		</schurl>
	</routers>
</frontend>
<default>
.....
</default>

Create a controller file TestController.php in your module’s controller folder like this (as you may have guessed, my modules name is Schogini):

class Mage_Schogini_TestController extends Mage_Core_Controller_Front_Action
{
	public function showmsgAction()
	{
		echo 'Here';
	}
}

This is what happens when you browse this URL
http://mymagentostore.com/schurl/test/showmsg/

  • schurl tells that the controller to check is Mage_Schogini (the name that is specified in the config file in the section: args > module)
  • test tells that controllers/TestController.php file must be checked
  • showmsg tells that showmsgAction() method must be called.

Hence, it will look for the method showmsg() inside the Mage_Schogini_TestController class

Page reloading using javascript

The following Javascript function will reload webpage. You can copy this function and paste it in your webpage and just call the function. That’s it.

<script type="text/javascript">

function reload_page(){

var cur_url = unescape(window.location.pathname);
window.location.href = cur_url;

}

</script>

Installing android OS on your PC

Step1: Download Android from the following url:
http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso

Step2: Download UNetbootin from the following url:
http://unetbootin.sourceforge.net/
UNetbootin allows you to create bootable live usb drives.

Step3: Reboot your computer with the USB drive, select “Live CD” which runs Android-x86 without installation.