How to generate random password in PHP?
Snippet# Random Password function random_password($maxlen){$chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i=0; $pass='';...
View ArticleHow to convert newline entered in TextArea to HTML line breaks in PHP?
SnippetThe data entered into the textarea in a html form contains lines break as \n , however when we have to save and display the same data back as html and maintain the formatting, these line feed \n...
View ArticleHow to copy text into Clipboard in Android?
Snippet // get the char sequence CharSequence displayContents = resultHandler.getDisplayContents(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);// set the...
View ArticleHow to create menu list in Android?
Snippet The following snippet shows how to create a menu option list. publicboolean onCreateOptionsMenu(Menu menu){ super.onCreateOptionsMenu(menu); menu.add(0, SHARE_ID, 0, R.string.menu_share)...
View ArticleHow to convert a String as Quoted String in Java?
Snippet /** * Encloses the incoming string inside double quotes, if it isn't already quoted. * @param string: the input string * @return a quoted string, of the form "input". If the input string...
View ArticleHow to check if WEP Key is valid in Java?
Snippet privatestaticfinal Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+"); /** * Check if wepKey is a valid hexadecimal string. * @param wepKey the input to be checked * @return true if...
View ArticleHow to embed Youtube Video using from flashvars using HDFlvPlayer?
SnippetThe following snippet shows the HDFlashPlayer embeding a YouTube video into HTML using the FlashVars. It assumes the the flash player is located in hdflvplayer/hdplayer.swf relative to the page...
View ArticleHow to download Image from URL and save it in Java?
Snippet importjavax.imageio.ImageIO;importjava.awt.image.BufferedImage;importjava.io.File;importjava.io.IOException;importjava.net.URL; publicclass ImageDownloader { publicstaticvoid...
View ArticleHow do you convert Image to Base64 String in C#?
Code Snippet publicstring ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format){ using(MemoryStream ms =new MemoryStream()) { // Convert Image to byte[] image.Save(ms,...
View ArticleHow do you convert Image in Base64 String to actual Image in C#?
Code Snippet public Image Base64ToImage(string base64String){ // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms =new...
View ArticleHow do you serve a image file using PHP?
Code SnippetLets say you have to build and image server using PHP. The image filename to be severed is specified with the file GET parameter and this script is called as get-image.php which is located...
View ArticleHow to resolve Hostname to IP or viceversa in PHP?
PHP language provides two convenient functions to achieve this.- gethostbyaddr() -gethostbyname()The gethostbyaddr() and gethostbyname() functions will return the hostname or IP address of a given...
View ArticleAndroid MediaPlayer Source Code
publicclass AudioStreamer extends Activity { @Override publicvoid onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); String url ="http://www.yoursite:port/stream";...
View ArticleHow do you define gradient color in Android?
Answer In order to define a gradient that can be used in your app, define it an a resource file.e.g. the resource file can be named as gradient.xml in the res/drawables directory of your project...
View ArticleHow do you define colors to be used in layouts in an Android App?
Answer In order to define a colors that can be used in your app, define it an a resource file.e.g. the resource file can be named as color.xml in the res/values directory of your project...
View ArticleHow do you define styles in Android?
Answer In order to define a styles that can be used as theme for your app widget or layout, define the styles as a resource in the file. The resource file can have any name but ends with .xmle.g. the...
View ArticleHow do you encode url in Android?
SnippetEncoding URL is very straightforward, simply call the encode method of the URLEncoder class on the String data that you want to encode.try{ String url ="http://www.yoursite.com/blah"; String...
View ArticleHow to implement Button OnClickListener in Android?
SnippetThe following snippet shows how to implement OnClickListner for a ImageButton in an Android Activity.packagecom.livrona.apps.radio.activity;...
View ArticleHow 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 ArticleHow 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