Quantcast
Channel: Developer Feed - Snippet
Browsing latest articles
Browse All 178 View Live

How to remove all files of a particular type from a directory in iOS?

Lets say you want to remove(delete) all the files of a particular extension say PNG from the Documents folder of the app. We can use the following code snippet.NSString*fileExt =@"png";</p>read more

View Article


How do you hide an ImageButton in Android?

In order to hide the button, call the setVisible method with either one of two argumentsimageButton.setVisible(View.INVISIBLE)OR imageButton.setVisible(View.GONE);read more

View Article


How to build simple Hashmap cache in Android?

The following snippet shows how to build a simple Bitmap Cache in Android:import java.util.HashMap;import android.graphics.Bitmap;// TODO: Auto-generated Javadoc/** * The Class ImageMemoryCache....

View Article

How to check if a file is an Image in Android using FileFilters?

In order to check if file is an Image, one can check for the file extension (jpg, png, etc.) using FileFilter as shown below:packagecom.livrona.apps.sikh.wallpapers;...

View Article

How do you center an Image to display in a Splash Page in Android?

Generally the splash page displays an image of the App on launch of the app. Most of time its just an single image that is intended to be displayed.Depending of the size of image and device it runs, it...

View Article


Email Validator in Android

The snippet shows an Email Validator using RegEx.read more

View Article

How to download and store file contents from Remote location on the SD Card?

The following functions fetches the file contents from a remote location, stores it in a given directory with a given file name on the SDCard of the deviceread more

View Article

How to create nosiy captcha using RMagick?

</p>read more

View Article


How to generate a random number in CSharp?

In order to generate a random number between two numbers, use the Next Function of the Random class as shown below:Example :read more

View Article


How to create 2D Canvas in HTML5 using Javascript?

SnippetThe following snippet shows how to create a div called as canvas (can be any name) and then in javascript we get the handle to canvas by calling document.getElementById method. Finally we get...

View Article

How to send Email via Intent in Android?

SnippetThe following snippet shows how to send Email via an Email Intent in an Android Activity.packagecom.livrona.apps.radio.activity;...

View Article

How to parse ShoutCast/IceCast Stream Metadata in Java?

Snippet StreamScraper is a java library that can be used to harvest streaming metadata (current song title, genre, current listener count, etc.) from SHOUTcast/IceCast servers. Usage...

View Article

How to animated text like marquee on iPad?

Snippet In order to create a rotating banner marquee on screen we can use a label along with help of core animation to achieve the effect as follows. The location of the text and duration can be...

View Article


How to create vertical menu in Cocos2D?

Snippet In order to create a Menu in Cocos2D, simply create MenuItems and then add create the Menu with those items and finally align the items vertical for a vertical menuCCMenu *endMenu =nil;...

View Article

How do you post and recieve notifications via Notification Center in iOS

Snippet Notification Center allows to send internal asynchronous notification with the application. Ex. you can define these methods as below to send notification when required in your app.-(void)...

View Article


How to check if network is Reachable in iOS?

Snippet Any good mobile application would keep a track or aleast check whether the network is reachable or not as the iPhone may have a bad reception, the wifi may not be connected etc. This is also a...

View Article

How to use a LED like font in iOS?

Snippet LED like font is available on the iOS platform. The following snippet shows how to set the font to LED like for a label.    UILabel *remainLabel  =[UILabel alloc] init];    [remainLabel...

View Article


How to display a Dialog using UIAlertView in iOS?

SnippetThe following utility method shows how to display a Dialog using UIAlertView.+(void) displayAlertOk:(NSString*) title andMessage:(NSString*) message {[self displayAlert: title andMessage:...

View Article

How to progamatically Java version?

Snippet The key here is to use the system property java.version and get minor and point version. publicclass CheckVersion {  publicstaticvoid main(String[] args){    String version...

View Article

How to programatically download mp3 file from Web using PHP?

Code Using PHP built in function fopen we can read a remote stream, read the contents in the buffer and flush it to the file.// Copy remote file locally $remote_file='http://www.example.com/music.mp3';...

View Article

How to check if file exists in PHP?

Snippet Using the file_exists function it is very easy to check whether a file exists in a given directory or not. Say we want to check if file name audio.mp3 exists or not in /tmp...

View Article


How to get button text on click in Android?

The following code shows how to associated the OnClickListener with the button and later on when its clicked and that handler is invoked how to get the title to the button.Button buttonAdvert =...

View Article


How do you convert CharSequence to String in Android?

AnswerThe CharacterSequence is an interface as defined below// Compiled from CharSequence.java (version 1.5 : 49.0, no super bit)public abstract interface java.lang.CharSequence {    // Method...

View Article

How to Resize UIView using Core Animation in iOS?

Core Animation based on Quartz provides very simple ways to create special effects in your game or application.The following shows how to create a Resize Effect of any UIView (e.g. UIButtonView,...

View Article

How to Move UIViews using Core Animation in iOS?

Core Animation based on Quartz provides very simple ways to create special effects in your game or application.The following shows how to create a Move Effect of any UIView (e.g. UIButtonView,...

View Article


How to create a Pulse Effect on UIViews using Core Animation in iOS?

Core Animation based on Quartz provides very simple ways to create special effects in your game or application.The following shows how to create a Pulse Effect of any UIView (e.g. UIButtonView,...

View Article

When you transition scene in cocos2d what methods do get called?

The following three callback methods are called when one Scene is transitioned into another in Cocos2D. -(void) onEnter{// Called right after a node's init method is called.// If using a...

View Article

How do you add a colored background in Cocos2d?

Adding colored background to a layer is very easy, just create a CCLayer from the subclass CCLayerColor and in the constructor define the name of the color as show below.// Set background color to...

View Article

Understanding Cocos2D CCNode?

/** CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode. The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.  The main features of a CCNode...

View Article



How to check if UIImage the is loaded?

AnswerSometimes when we load the UIImage and try to use it, it does not display or given an exception. The very simple way is to check whether the image handle is null or not as shown below.UIImage...

View Article

How to make UIWebView background transparent?

AnswerAt times the UIWebView background needs to be made transparent so that the html content is displayed flushed against the screen background.For this set the following properties on the...

View Article

Can you have the same development and distribution certificates for your iOS...

AnswerYou can, but then both your development and distribution certificates will be tied to the same public/private key pair (which is generated when you create the certificate request). This may work...

View Article

How to rename file in PHP?

If you want to rename a file in PHP you can use the rename function. The syntax of the rename function is same as that of the UNIX mv(move) command. The general syntax is:rename('/pathA/old_file_name',...

View Article


How to list files in a directory in PHP?

<?phpif($handle=opendir('/path/to/directory')){    echo"Directory handle: $handle\n";    echo"Entries:\n";    /* This is the correct way to loop over the directory. */...

View Article

How to save an NSArray into Plist with a Key?

Saving an NSArray with a Key into PList is easy. You can start with a NSMutableDictionary and add each array as an entry with a key. Finally save into file.+(void) saveArrayIntoPlist:(NSArray*)aArray...

View Article

How to compute SHA1 digest for NSString?

Computing SHA1 (Message Digest). The following is implemented as extension to NSString.////  NSString+Hashing.h #import <Foundation/Foundation.h> @interfaceNSString(Hashing)-(NSString*)sha1;@end...

View Article


Some useful Box 2D macros

BOX2D has uses meters as a unit for length and width. However the objects need to be draw on screen in pixel sizes. The following macros helps with those conversions.#define PTM_RATIO 40.0f#define...

View Article


How to hide UITextView Keyboard in OS?

Basically UITextView is for Multi line Text. However if you want to hid the keyboard when the user presses the Return Key using the following snippet:-(BOOL)textView:(UITextView *)textView...

View Article

How do you hide the back button in UINavigationController?

Whenever a child view is pushed into the Navigation Controller, a back button on the top left of the page is displayed. Using this button the user can go back to the parent view. In some case we like...

View Article

How can you cache CCAnimation in Cocos2D?

Cocos2D provides a simple way to cache you Animations using CCAnimationCache class. The CCAnimationCache is implemented as a singleton which can be accessed using the [CCAnimationCache...

View Article

How to list all the fonts available in the iOS platform?

A variety of fonts are available in iOS platform. The following code snippet shows how to list all such fonts and add the font names into an array. // arrayNSMutableArray*fontNames =[[NSMutableArray...

View Article


Image may be NSFW.
Clik here to view.

How to display PHP setup and environment variables?

In order to display PHP setup, configuration and environmental variables simply create a php page and execute the phpinfo command. It will display all the relevant information about PHP as output in...

View Article

How to load image from PhotoGallery into a CCSprite?

SinppetThe Asset Library is used here, so add import.#import "AssetsLibrary/AssetsLibrary.h"   CCSprite *playPhoto;  CCLOG(@"Photo %@",dataManager.playerPhoto);// check if the URL is an asset URL from...

View Article


How to change font to bold and color of a UILabel?

SnippetThe following snippet provides a utiity method to change the label font from bold to regular along with that it changes the color to red or black respectively-(void) updateLabel :(UILabel*)...

View Article

What are the various Enums used by the Facebook iOS SDK?

The following are the various Enumeration defined and used by the Facebook iOS SDK. Please review these for full understanding of how the SDK behaves for various operations./* * Constants used by...

View Article


How to load an remote image as a Drawable in Android?

Loading an remote image from a online server accessible via a URL as Drawable is very straightforward.// Utililty Methodpublic static Drawable loadImageAsDrawable(String url) {    try {        // open...

View Article

How to allow multiple line text in EditText view in Android?

The EditText widget by default is single line. In order to allow mutiple lines modify and customize the widget definition in the layout file as below:<EditText    android:singleLine="false"<!--...

View Article

How to show Alert Dialog in Java Swing?

Displaying a simple message box or an alert dialog with an Ok button can be done with just one line of code as show below:A) Without a JFrameJOptionPane.showMessageDialog(null, "Message goes...

View Article

How do you create a simple Swing based Window with Frame?

importjava.awt.EventQueue; importjavax.swing.JFrame;  publicclass MainWindow {      privateJFrame frame;      /**     * Launch the application.     */     publicstaticvoid main(String[] args){...

View Article


How to check the version of MySQL database using Python?

#!/usr/bin/python# -*- coding: utf-8 -*- import MySQLdb as mdbimport sys con = None try:     con = mdb.connect('localhost','username',        'password','dbname');     cur = con.cursor()...

View Article

Browsing latest articles
Browse All 178 View Live