Posts

Showing posts from 2013

[Android] Show AlertDialog with EditText.

public void showDialogWithEditText() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Server Message"); alert.setMessage("Set Server Message"); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); } This method will show alertdialog with EditText.You can use "value" variable as required.

Unable to resolve target 'android-16'

In Eclipse, try changing the build target. Here how it done, Right click on your project -> Properties -> Android -> Project Build Target. Change the build target and click 'apply' button.

Basic windows command lines for ethical hacking.

To open command line. Go to start menu and type "cmd" without quotations. And it will start command prompt. To go to C:\> drive type cd\ To create a directory type mkdir directory_name. C:\>mkdir Isuru To insert some text into notepad. C:\>echo Leann will come again. > leann.txt To list tasks. C:\>tasklist To find specific task. C:\>tasklist | findstr firefox To kill a task. C:\>taskkill /PID 6880 /F 6880 is the process id. And /F will kill the task forcefully. To write all tasks into a file. C:\>tasklist > qwe.txt To change color of command prompt. C:\>color a To view all the files in your drive in tree view. C:\>tree To view ip information. C:\>ipconfig To ping any web address. C:\>ping www.google.com To trace route. C:\>tracert 209.85.175.103 Netstat This is to display the TCP/IP network protocol statistics and information. C:\>netstat To list the users. C:\>net user To delete the user. C:\&

Migrate all blogger(blogspot) posts to wordpress.

This video shows how to migrate from blogger to wordpress. There are lots of plugins that can be used for greater blogging experience using wordpress.

Oracle/PLSQL: Execute an SQL script file in SQLPlus

Question: How do I execute an SQL script file in SQLPlus? Answer: To execute a script file in SQLPlus, type @ and then the file name. SQL > @{file} For example, if your file was called script.sql, you'd type the following command at the SQL prompt: SQL > @script.sql The above command assumes that the file is in the current directory. (ie: the current directory is usually the directory that you were located in before you launched SQLPlus.) If you need to execute a script file that is not in the current directory, you would type: SQL > @{path}{file} For example: SQL > @/oracle/scripts/script.sql This command would run a script file called script.sql that was located in the /oracle/scripts directory.

Change Oracle password after installation.

To change a password after installation: Start SQL*Plus: C:\> sqlplus /NOLOG Connect as SYSDBA : SQL> CONNECT / AS SYSDBA   Action SQL Statement Unlock a password ALTER USER username ACCOUNT UNLOCK; Lock a password ALTER USER username ACCOUNT LOCK; Change password of an unlocked account ALTER USER username IDENTIFIED BY password ; Change password of a locked account ALTER USER username IDENTIFIED BY password ACCOUNT UNLOCK;  

Resolving ORACLE ERROR:ORA-20000: the account is locked

From your command prompt, type sqlplus "/ as sysdba" Once logged in as SYSDBA, you need to unlock the hr account SQL> alter user hr account unlock; SQL> grant connect, resource to hr;

Check remote file size in php using PHP5 and cUrl.

To check file size you need PHP5 and Curl. It first try checking headers. But if file size is not specified in headers, it use cUrl to download the file and checks the size. File is saved in memory temporarily. <?php echo get_remote_size("http://www.google.com/"); function get_remote_size($url) {     $headers = get_headers($url, 1);     if (isset($headers['Content-Length'])) return $headers['Content-Length'];     if (isset($headers['Content-length'])) return $headers['Content-length'];     $c = curl_init();     curl_setopt_array($c, array(         CURLOPT_URL => $url,         CURLOPT_RETURNTRANSFER => true,         CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'),         ));     curl_exec($c);     return curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD); } ?>

Check whether url is valid with php

Use Filter Validator  to validate url. filter_var($url, FILTER_VALIDATE_URL); Example using that, if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {     die('Not a valid URL'); }

How to add custom javascript to backend(admin) and frontend of wordpress cms?

Image
Here I'm going to show how to add custom javascript to your backend(admin panel) and frontend of your wordpress website inside <head> tag. I am not talking about wordpress.com(pre hosted) blogging system. Here I'm demonstrating how to do it in self-hosted blog/website. First you need to go to Theme Editor(Appearance -> Editor). And find functions.php file from right panel. To find it easily click Ctrl + F (In Windows machine) and type functions.php. After you found it click on it and it will open up online editor. You will see something like following. Coding may differ in your system. And add following code to the end of functions.php file. function custom_js() { echo '<script type="text/javascript"> YOUR CODE HERE </script>'; } // Add hook for admin <head></head> add_action('admin_head', 'custom_js'); // Add hook for front-end <head></head> add_action('wp_head', 'cust

Principles of Mobile Interface Design

Image
Mobile app design for touchscreen devices has more in common with classic industrial design principles than the software interface development patterns of the desktop computing era. In this hands-on webcast presented by Jonathan Stark, author of 'Building Android Apps with HTML, CSS, and JavaScript' and 'Building iPhone Apps with HTML, CSS, and JavaScript', learn how to take your mobile app from concept to completed design by exploring practical principles and visual examples. What will be covered? User centered design Defining the mobile context Pragmatic UI guidelines Editorial considerations for small screen Best practices for touch interfaces Designing cross-platform controls Who is this webcast for? This webcast is for web designers and developers who are interested in creating mobile apps. A basic familiarity with standard HTML, CSS, and JavaScript would be very helpful but is not required. NOTE: Jonathan Stark is presenting a series of webcasts that ar

Sizes of Android background images.

I always had hard times finding out sizes of background images for hdpi, mdpi and ldpi. Here sizes in pixel for each one. hdpi => 800×480 pixels mdpi => 320×480 pixels ldpi => 320×420 pixels.

iOS 6 vs. Android Jelly Bean

Image

Shortcut Keys for android emulator/avd

There are few shortcut codes/keys which will help you when you are debugging with android emulator. Main Keyboard Shortcuts 1. Home            -   Home Button Of Keyboard 2. F2                 -   Left Softkey / Menu / Settings button (or Page up) 3. Shift + F2      -   Right Softkey / Star button (or Page down) 4. Esc                -   Back Button 5. F3                 -   Call/ dial Button 6. F4                 -   Hang up / end call button 7. F5                 -  Search Button Other Device Keys 1. Ctrl+F5         -  Volume up (or + on numeric keyboard with Num Lock off) 2. Ctrl+F6        -   Volume down (or + on numeric keyboard with Num Lock off) 3. F7                -   Power Button 4. Ctrl+F3        -   Camera Button 5. Ctrl+F11      -   Switch layout orientation portrait/landscape backwards 6. Ctrl+F12      -   Switch layout orientation portrait/landscape forwards 7. F8                -   Toggle cell network 8. F9                -   Toggle cod

How to kill an Android activity?

 How to kill an Android activity when leaving it so that it cannot be accessed from the back button? All you need to do is call finish() method in Activity class like following code snippets. Intent intent = new Intent ( this , NextActivity . class ); startActivity ( intent ); finish ();

Basic structure of AsyncTask Class

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {     protected Long doInBackground(URL... urls) {         while (true) {             // Do some work             publishProgress((int) ((i / (float) count) * 100));         }        return result;     }     protected void onProgressUpdate(Integer... progress) {         setProgressPercent(progress[0]);     }     protected void onPostExecute(Long result) {         showDialog(“Result is “ + result);     } } To execute, new DownloadFilesTask (). execute ( url1 , url2 , url3 ); To read more about async task refer android developer guide.

Check whether an app on debug mode.

Here is a simple method to check whether an app is on debug mode or not. This will be useful to check to enable Strict Mode or to disable Strict Mode. public static boolean isDebugMode(Context context) {               PackageManager pm = context.getPackageManager(); try {              ApplicationInfo info = pm.getApplicationInfo p (context.getPackageName(), 0);               return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; } catch (NameNotFoundException e) { }              return true; } And to enable Strict Mode, StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .penaltyDialog() .build()); The above code will detect all types of network and disk I/O. Very helpful for debugging.

How can I make wordpress to show images in articles on homepage?

By default post images not shown on home page by some themes. Showing images on articles in home page can be achieved by two ways. 1. You need to edit index.php of your theme. Remember you must edit currently activated theme. It is currently configured to only show a post excerpt. If you don’t supply an optional custom excerpt, WordPress will create one automatically by stripping out all formatting, markup and images from the first 55 words of your post. Replace the_excerpt() with the_content(). You can easily find the_excerpt() by clicking CTRL + F and typing the_excerpt() , find it replace. And save by clicking the update button. 2. Write a custom excerpt in the Excerpt field, under the post edit box. It can be as short, or as long, as you wish and can include images.

There was a problem saving your changes. Please try again later.

There was a problem saving your changes. Please try again later. When I try to save settings of my facebook app. I got the above error. It occurred when I try to save Secure Canvas URL field. And then I used port number of 443 with my url. For example if my Secure Canvas URL is  https://dl.dropbox.com/u/38102629/index.html?  I added port number and my canvas url is  https://dl.dropbox.com :443 /u/38102629/index.html? And error went away.

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'

I tried to install proftpd in webmin and I broke ftp in zpanel. I got following error message when I run proftpd command. root@Ubuntu12:~# proftpd Ubuntu12 proftpd[1400]: Fatal: LoadModule: error loading module 'mod_sql_mysql.c': Operation not permitted on line 38 of '/etc/zpanel/configs/proftpd/proftpd-mysql.conf' And I searched everywhere but I couldn't find anything. But following command make my error vanish .  apt-get install proftpd-mod-mysql If it asked what mode, choose 'stand-alone'. root@Ubuntu12:~# proftpd And it must be running.

Check whether model is loaded or not.

Following function will check whether model is loaded in codeigniter. Pass the model name as argument to the following function. function is_model_loaded ( $model ) { $ci =& get_instance (); $load_arr = ( array ) $ci -> load ; $mod_arr = array (); foreach ( $load_arr as $key => $value ) { if ( substr ( trim ( $key ), 2 , 50 ) == "_ci_models" ) $mod_arr = $value ; } //print_r($mod_arr);die; if ( in_array ( $model , $mod_arr )) return TRUE ; return FALSE ; }

Android - Detect whether there is an Internet connection available?

Following method return true if there is any internet connection available and can connect to internet, and it will return if app cannot connect to internet. You must import following classes. import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.content.Context; And here is the method, public boolean checkInternet() { ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni == null) { // There are no active networks. return false; } else{ return true; } }

How to find your server's IP address

You can run the following command to reveal your server’s IP address. ifconfig eth0 | grep inet | awk '{ print $2 }'

CakePHP url rewrite not working or css cake.generic.css not working.

If CakePHP is not finding your image and css files and you tried everything else like activating mod rewrite, .htacess, try editing app/Config/Core.php file. Find following line and uncomment it. Configure::write(&#8216;App.baseUrl&#8217;, env(&#8216;SCRIPT_NAME&#8217;));

[MYSQL][SOLVED] The used table type doesn't support FULLTEXT indexes

The problem occurred because of wrong table type. To solve the problem we need to change the type of the table. Mysql supports a few different types of tables, but the most commonly used are MyISAM and InnoDB. MyISAM is the only type of table that Mysql supports for Full-text indexes. To correct this error run following sql. ALTER TABLE <table name> ENGINE = MYISAM

[PHP] Get the Page Name.

The following code will get the name of the page in php. It is sometimes useful to get name of the page. $uri = $_SERVER['REQUEST_URI']; $pieces = explode("/", $uri); if ($pieces[3] == "upload.php") { echo "Page name is upload.php"; } My Uri was "/tubesite/admin/upload.php". So when I run explode method, it returned array with three strings. First string $pieces[0] was an empty string. Second string was tubesite. And so on. You can check out explode method. It uses to form substrings by splitting it on boundaries formed by the string delimiter http://php.net/manual/en/function.explode.php